过滤换柱清管器

4sup72z8  于 2021-06-25  发布在  Pig
关注(0)|答案(1)|浏览(453)

假设我的数据

row1 cats val12 val13
row2 dogs val22 val23
row3 cats val32 val33
...

data = load 'file' AS (row:chararry, pets:charray, val2:charray, val3:charray);

筛选数据以仅保存“cats”行

felines = filter data by (pets matches 'cats');

现在把“猫”改成“狮子”

lions = foreach felines generate replace (pets, 'cats', 'lions');
dump lions;

(lions)
(lions)
...

我的目标是创建新行以添加到表中

newFelines = foreach lions generate rows, lions, val1, val2;
                                    Error ^^^^^
"Error during parsing. Scalars can be only used with projections"

如何获得具有以下新行的集合?

row1 lions val11 val12
row3 lions val31 val32

蒂亚,

2w2cym1i

2w2cym1i1#

逐行:
没有“chararry”或“charray”数据类型:

data = load 'file' USING  PigStorage(' ')  AS 
    (row:chararray, pets:chararray, val2:chararray, val3:chararray);

提取“猫”:

felines = filter data by (pets matches 'cats');

用“狮子”代替“猫”可以这样做:

lions = foreach felines generate row, REPLACE(pets, 'cats', 'lions'), val2, val3;

或者像这样:

lions = foreach felines generate row, 'lions', val2, val3;

相关问题