问题
I have been trying to get the max temperature per year using the data below. Actual data looks like this but I am interested in only first column that is year and 4th column that is temperature..
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)
The code I have write is like below..But, it throws me the error at D. I have also used ToDate function but seems it doesn't work too..
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);
Error I get :
Invalid field projection. Projected field [year1] does not exist in schema: group:chararray,B:bag{:tuple(year1:chararray,Atemp:float)}.
回答1:
I figure out myself after posting question at stackoverflow :) I wonder why! Instead of D = foreach C GENERATE group,MAX(Atemp); I have used D= foreach C GENERATE group, MAX(B.Atemp) as max; and it works!
If anyone wants me to delete the post I'm happy to do so. Kindly let me know
来源:https://stackoverflow.com/questions/62314415/get-max-value-per-year-in-apache-pig