如何在PIG中使用某些硬编码值连接变量

时间:2015-03-04 07:45:57

标签: hadoop apache-pig

如何在PIG中使用某些硬编码值连接变量

A = LOAD'data'为(f1:chararray,f2:chararray,f3:chararray);

X =对于一个生成的CONCAT(“BIG”,f3);

预期产出:

(apache的,开放的,BIGsource)

(hadoop的,地图,BIGreduce)

(猪,猪,BIGlatin)

1 个答案:

答案 0 :(得分:1)

Pig不支持双引号,因此您需要将硬编码值从双引号更改为单引号。

X = FOREACH A GENERATE f1,f2,CONCAT('BIG',f3);

<强>更新
您可以使用REPLACE函数从输入中删除双引号 示例如下

数据

"apache","open","source"
"hadoop","map","reduce"
"pig","pig","latin"

<强> PigScript:

A = LOAD 'data' USING PigStorage(',') AS (f1:chararray, f2:chararray, f3:chararray);
B = FOREACH A GENERATE REPLACE(f1,'"',''),REPLACE(f2,'"',''),CONCAT('BIG',REPLACE(f3,'"',''));
DUMP B

<强>输出:

(apache,open,BIGsource)
(hadoop,map,BIGreduce)
(pig,pig,BIGlatin)