Search code examples
apache-pig

ERROR 1070: Could not resolve ToDate using imports


Following are the details:

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

pig-script:

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;

This the error I am getting:

main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1070: Could not resolve ToDate using imports: [, org.apache.pig.builtin., org.apache.pig.impl.builtin.]


Solution

  • The input date format is MM/dd/yyyy.

    C = FOREACH B GENERATE ToDate(tripdate,'MM/dd/yyyy') as mytripdate;
    

    If you want the date to be in 'yyyy-MM-dd' format use ToString()

    C = FOREACH B GENERATE ToString(ToDate(tripdate,'MM/dd/yyyy'),'yyyy-MM-dd') as mytripdate;