我自己在学猪,我遇到了一个错误。
这是用宏脚本编写的,用于理解Pig中的模块化编程。问题是我试图通过引用关系名称::使用$来使用字符串参数,然后立即使用$替换参数字符串。错误是:
意外字符$
如何继续这个?
define dividend_analysis (daily, year, daily_symbol, daily_open, daily_close)
returns analyzed {
divs = load '/PigData1/NYSE_dividends.txt'as (exchange:chararray, symbol:chararray, date:chararray, dividends:float);
divisthisyear = filter divs by date matches '$year-.*';
dailythisyear = filter $daily by date matches '$year-.*';
jnd = join divisthisyear by symbol, dailythisyear by $daily_symbol;
$analyzed = foreach jnd generate dailythisyear.$daily_symbol,$daily_close - $daily_open;
};
daily = load '/PigData1/NYSE_daily.txt'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');
错误信息来自猪......
<line 7, column 53> Unexpected character '$'
2016-12-09 16:14:04,283 [main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1200: <line 7, column 53> Unexpected character '$'
Details at logfile: /home/hadoop/pig_1481278051535.log
grunt> exec macro1.pig
<line 7, column 53> Unexpected character '$'
2016-12-09 17:00:37,723 [main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1200: <line 7, column 53> Unexpected character '$'
Details at logfile: /home/hadoop/pig_1481278051535.log
答案 0 :(得分:0)
以下是针对您的脚本所做的更改,请尝试使用此脚本
define dividend_analysis (daily, year, daily_symbol, daily_open, daily_close)
returns analyzed {
divs = load '/user/data/NYSE_dividends'as (exchange:chararray, symbol:chararray, date:chararray, dividends:float);
divisthisyear = filter divs by date matches '.*$year.*';
dailythisyear = filter $daily by date matches '.*$year.*';
jnd = join divisthisyear by symbol, dailythisyear by $daily_symbol;
$analyzed = foreach jnd generate $1 ,$daily_close - $daily_open; };
daily = load '/user/data/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');