【问题标题】:Pig: Create new column based off of two other columnsPig:基于其他两列创建新列
【发布时间】:2014-10-09 19:48:21
【问题描述】:

我想知道是否有可能在猪身上做这样的事情:

共有三列:

一个"type1","type2","type3"

B 101 , 159 , 74

我想这样定义列 C:

如果 A == "type1" 那么 C = B;否则 C = 0

这可能在猪身上吗?

【问题讨论】:

    标签: hadoop apache-pig bigdata


    【解决方案1】:

    是的,这是可能的。你可以这样写:

    data = LOAD '$dataSource' using AvroStorage();
    -- data = {A, B}
    
    data2 = FOREACH data
               GENERATE
                   A,
                   B,
                   (A == 'type1' ? B : 0) AS C;
    
    dump data2;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-30
      • 1970-01-01
      • 1970-01-01
      • 2017-08-03
      • 1970-01-01
      • 1970-01-01
      • 2021-09-17
      • 2021-12-27
      相关资源
      最近更新 更多