以下是详细信息:
date2.txt
B02617,2/27/2015,1551,14677
B02598,2/27/2015,1114,10755
B02512,2/27/2015,272,2056
B02764,2/27/2015,4253,38780
猪脚本:
A = Load '/files/date2.txt' using PigStorage(',') as (base:chararray, tripdate:chararray, cars:int, tripkms:int);
B = FOREACH A GENERATE tripdate;
C = FOREACH B GENERATE ToDate(tripdate,'yyyy-MM-dd') as mytripdate;
这是我得到的错误:
main]错误org.apache.pig.tools.grunt.Grunt-错误1070:使用导入无法解析ToDate:[,org.apache.pig.builtin。,org.apache.pig.impl.builtin。]
答案 0 :(得分:1)
输入日期格式为MM/dd/yyyy
。
C = FOREACH B GENERATE ToDate(tripdate,'MM/dd/yyyy') as mytripdate;
如果您希望日期采用'yyyy-MM-dd'格式,请使用ToString()
C = FOREACH B GENERATE ToString(ToDate(tripdate,'MM/dd/yyyy'),'yyyy-MM-dd') as mytripdate;