我正在通过alan gates编写的pig编程,在引入宏功能的脚本中出现了一个错误:http://ofps.oreilly.com/titles/9781449302641/advanced_pig_latin.html#macros
--macro.pig
-- Given daily input and a particular year, analyze how
-- stock prices changed on days dividends were paid out.
define dividend_analysis (daily, year, daily_symbol, daily_open, daily_close)
returns analyzed {
divs = load 'NYSE_dividends' as (exchange:chararray,
symbol:chararray, date:chararray, dividends:float);
divsthisyear = filter divs by date matches '$year-.*';
dailythisyear = filter $daily by date matches '$year-.*';
jnd = join divsthisyear by symbol, dailythisyear by $daily_symbol;
$analyzed = foreach jnd generate dailythisyear::$daily_symbol,
$daily_close - $daily_open;
};
daily = load 'NYSE_daily' as (exchange:chararray, symbol:chararray,
date:chararray, open:float, high:float, low:float, close:float,
volume:int, adj_close:float);
results = dividend_analysis(daily, '2009', 'symbol', 'open', 'close');
错误是意外的 $
在中的双冒号后签名 dailythisyear::$daily_symbol
.
您如何解决这一问题,而不将行替换为:
$analyzed = foreach jnd generate divsthisyear::symbol, $daily_close - $daily_open;
1条答案
按热度按时间42fyovps1#
不能在宏内部使用参数替换。参数应该显式传递给宏,参数替换只能在顶层使用。
您可以使用-dryrun命令行参数来查看宏是如何在线展开的。
所以无论如何,你不能用这种方式在宏中使用参数。