pig中distinct用法

Distinct  

只能处理关系中的整个记录,不能是表达式,或者部分域。

--distinct.pig

daily  = load 'NYSE_daily' as (exchange:chararray, symbol:chararray);

uniq   = distinct daily;

uniq是一个关系relation(类似表,是流对象)。不是表达式

 

“distinct forces a reduce phase. It does make use of the combiner toremove,any duplicate records it can delete in the map phase.”其会强制执行一个reduce阶段(很多语句只用map就能完成,不需要reduce),此外还有order,join,group,limit,cogroup,cross等等。

而之所以distinct很快,是因为其在map阶段执行了combiner,提高效率。

其parallel只能控制reduce端,所以在设计程序时指定parallel的个数,实际上是指定了reduce的个数,而在reduce过程中,是自动hashing到对应的reduce中。

 

 

--distinct_symbols.pig

daily   = load 'NYSE_daily' as (exchange, symbol); -- not interested in otherfields

grpd    = group daily by exchange;

uniqcnt = foreach grpd {

          sym      = daily.symbol;

          uniq_sym = distinct sym;

          generate group, COUNT(uniq_sym);

};

另外,distinct只能处理relation,不能处理expression。

这里,daily.symbol是expression,不能被distinct。必须提取到sym后成为关系,才能被distinct。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值