如何生成元组?猪的经营者

时间:2013-11-09 15:12:50

标签: hadoop mapreduce hdfs apache-pig

我的代码如下

temp = foreach requiredData generate (recordType == 3 ? controllingCalledNum : callingPtyNum)as ServiceNumber, (recordType == 3 ? callingPtyNum : controllingCalledNum)as DestinationNumber;

这里我的代码是reduntant ..

我可以在'?'中生成元组吗?操作员并做这样的事情,我可以进一步FLATTERN

  temp = foreach requiredData generate (recordType == 3 ? (controllingCalledNum,callingPtyNum) : (callingPtyNum,controllingCalledNum))as (ServiceNumber,DestinationNumber);

如果我尝试这样做,我会收到错误 请帮帮我。

1 个答案:

答案 0 :(得分:0)

使用内置的TOTUPLE UDF:

temp = foreach requiredData generate FLATTEN(recordType == 3 ? TOTUPLE(controllingCalledNum,callingPtyNum) : TOTUPLE(callingPtyNum,controllingCalledNum))as (ServiceNumber,DestinationNumber);