在Apache Pig(版本0.16.x)中,有哪些最有效的方法可以通过其中一个数据集字段的现有值列表来过滤数据集?
例如, (根据@inquisitive_mind的提示更新)
输入:行分隔文件,每行一个值 my_codes.txt
'110'
'100'
'000'
sample_data.txt
'110', 2
'110', 3
'001', 3
'000', 1
期望输出
'110', 2
'110', 3
'000', 1
示例脚本
%default my_codes_file 'my_codes.txt'
%default sample_data_file 'sample_data.txt'
my_codes = LOAD '$my_codes_file' as (code:chararray)
sample_data = LOAD '$sample_data_file' as (code: chararray, point: float)
desired_data = FILTER sample_data BY code IN (my_codes.code);
错误:
Scalar has more than one row in the output. 1st : ('110'), 2nd :('100')
(common cause: "JOIN" then "FOREACH ... GENERATE foo.bar" should be "foo::bar" )
我也试过FILTER sample_data BY code IN my_codes;
但是“IN”子句似乎需要括号。
我也试过了FILTER sample_data BY code IN (my_codes);
但得到了错误:
需要从关系中投射一个列,以便将其用作标量
答案 0 :(得分:1)
my_codes.txt文件的代码为行而不是列。由于您将其加载到单个字段中,因此代码应如下所示
'110'
'100'
'000'
或者,您可以使用JOIN
joined_data = JOIN sample_date BY code,my_codes BY code;
desired_data = FOREACH joined_data GENERATE $0,$1;