Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache pig 清管器-选择组中的多个顶部记录_Apache Pig - Fatal编程技术网

Apache pig 清管器-选择组中的多个顶部记录

Apache pig 清管器-选择组中的多个顶部记录,apache-pig,Apache Pig,我试图从一个组中选择共享同一密钥的多个记录,但不确定如何筛选 例如,使用以下数据: D120130701,M1,V1 D120130701,M2,V2 D120130702,M1,V3 D120130703,M1,V4 D120130703,平方米,V5 D220130701,M1,V1 D220130702,M1,V3 D220130703,M1,V4 和load语句: A = load '/home/hduser/t.csv' using PigStorage(',')

我试图从一个组中选择共享同一密钥的多个记录,但不确定如何筛选

例如,使用以下数据:

D120130701,M1,V1

D120130701,M2,V2

D120130702,M1,V3

D120130703,M1,V4

D120130703,平方米,V5

D220130701,M1,V1

D220130702,M1,V3

D220130703,M1,V4

和load语句:

A = load '/home/hduser/t.csv' 
        using PigStorage(',') 
        as (
            device:chararray, 
            dt:chararray, 
            metric:chararray, 
            value:chararray
        );

C = group A by (device, dt);
产生:

((D120130701),{(D120130701,M1,V1),(D120130701,M2,V2)})

((D120130702),{(D120130702,M1,V3)})

((D120130703),{(D120130703,M1,V4),(D120130703,M2,V5)})

((D220130701),{(D220130701,M1,V1)})

((D220130702),{(D220130702,M1,V3)})

((D220130703),{(D220130703,M1,V4)})

问题是,我应该做些什么来过滤掉这些行,这样我只会得到粗体的行,逻辑是针对每个设备(D1/D2…),给我一行最短的日期

如果我仅按设备分组:

B = group A by device;
我得到以下两行:

(D1,{(D120130701,M1,V1)、(D120130701,M2,V2)、(D120130702,M1,V3)、(D120130703,M1,V4)、(D120130703,M2,V5)})

(D2,{(D220130701,M1,V1)、(D220130702,M1,V3)、(D220130703,M1,V4)})

但我不能在foreach中使用limit,因为每个设备的记录数是可变的

有什么想法吗?对猪来说是相当新鲜的

非常感谢。

一种方法是

 records = LOAD '/user/nubes/ncdc/micro-tab/top.txt' AS (
        device:chararray, 
        dt:int, 
        metric:chararray, 
        value:chararray);


 records_group = group records by (device);

 with_min = FOREACH records_group 
       GENERATE
       FLATTEN(records), MIN(records.dt) ;

 filterRecords = filter with_min by ( $1 == $4 );
i/p是

D1 20130701 M1 V1 D1 20130701平方米V2

D1 20130702 M1 V3

D1 20130703 M1 V4

D1 20130703平方米V5

D2 20130702 M1 V3

D2 20130703 M1 V4

输出为

(D120130701、M1、V120130701)

(D120130701,M2,V220130701)


(D220130702,M1,V320130702)

非常感谢您!这正是我想要的。