我是Apache Pig的新手。是否可以用动态柱创建袋子? 以下是脚本,例如。
A = LOAD 'student' USING PigStorage() AS (col1:chararray, col2:chararray, col3:chararray ....... );
B = FOREACH A GENERATE col1, col3; OR
B = FOREACH A GENERATE col2, col3, col4;
简而言之,获取列列表并创建包。有可能吗?怎么样? 我需要的是获得动态列的方法。所以例如有人定义我的脚本在params ='col1,col2,col4'上运行,然后我的脚本应该能够解析这个字符串并使用它获得所需的列。
答案 0 :(得分:0)
A = LOAD 'student' using PigStorage(',');
by this relation A contains all columns which has student file.You can access these columns by using sequence number like $0,$1,$2
$0 --> First column
$1 --> Second column
$2 --> third column and so on
答案 1 :(得分:0)
我可以建议在脚本中使用MACRO或PARAMETER变量,这里的MACRO是示例
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');