在apache pig中获得每年的最大值

58wvjzkj  于 2021-06-24  发布在  Pig
关注(0)|答案(1)|浏览(246)

我一直试图用下面的数据得到每年的最高温度。实际数据看起来像这样,但我只感兴趣的第一列是年,第四列是温度。。

2016-11-03 12:00:00.000 +0100,Mostly Cloudy,rain,10.594444444444443,10.594444444444443,0.73,13.2664,174.0,10.1913,0.0,1019.74,Partly cloudy throughout the day.
2016-11-03 13:00:00.000 +0100,Mostly Cloudy,rain,11.072222222222223,11.072222222222223,0.72,13.1698,176.0,12.4131,0.0,1019.45,Partly cloudy throughout the day.
2016-11-03 14:00:00.000 +0100,Mostly Cloudy,rain,11.172222222222222,11.172222222222222,0.71,12.654600000000002,175.0,10.835300000000002,0.0,1019.16,Partly cloudy throughout the day.
2016-11-03 15:00:00.000 +0100,Mostly Cloudy,rain,10.911111111111111,10.911111111111111,0.72,11.753,170.0,10.867500000000001,0.0,1018.94,Partly cloudy throughout the day.
2016-11-03 16:00:00.000 +0100,Mostly Cloudy,rain,10.350000000000001,10.350000000000001,0.72,10.6582,161.0,11.592,0.0,1018.81,Partly cloudy throughout the day.
DUMP B is like below
(2014,12.038889)
(2014,21.055555) 
(2016,29.905556)
(2016,30.605556)
(2016,29.95)
(2016,29.972221)

我写的代码如下..但是,它在d处抛出了一个错误。我也用过todate函数,但似乎不太管用。。

A = load 'file.csv' using PigStorage(',')......
B = foreach A GENERATE SUBSTRING(year,0,4) as year1, Atemp
C = group B by year1;  
D = foreach C GENERATE group,MAX(Atemp);

我得到的错误:

Invalid field projection. Projected field [year1] does not exist in schema: group:chararray,B:bag{:tuple(year1:chararray,Atemp:float)}.
czq61nw1

czq61nw11#

我在stackoverflow发布问题后发现自己:)我想知道为什么!代替d=foreach c generate group,max(atemp);我使用d=foreach c generate group,max(b.atemp)作为max;而且有效!
如果有人想让我删除这个帖子,我很乐意这么做。请告诉我

相关问题