Support Questions
Find answers, ask questions, and share your expertise

ToDate java.lang.illegalargumentexception invalid format is malformed at Z

Highlighted

ToDate java.lang.illegalargumentexception invalid format is malformed at Z

Explorer

ToDate(ToString(CURRENT_DATE), 'yyyy-MM-dd\'T\'HH:mm:ss.SSSZ' , 'UTC' ) as CURRENT_DATE

throws a java.lang.IllegalArgumentException: Invalid format: "2017-10-25T04:30:00.000Z" is malformed at "Z". I tried using the suggestion mentioned in https://community.hortonworks.com/questions/10322/todate-javalangillegalargumentexception-invalid-fo... , but even that does not seem to work. Is there a particular way in which the ToDate method is to be specified in Pig Script to avoid this Exception

3 REPLIES 3
Highlighted

Re: ToDate java.lang.illegalargumentexception invalid format is malformed at Z

Super Guru

@Omkar Nalawade, Can you add more details to question like what would trying to do and your expected output please..!

Highlighted

Re: ToDate java.lang.illegalargumentexception invalid format is malformed at Z

Explorer
FOREACH a GENERATE ToDate(ToString(CURRENT_DATE), 'yyyy-MM-dd\'T\'HH:mm:ss.SSSZ' , 'UTC' ) as CURRENT_DATE; 
This is the statement I was executing using the Pig script which is giving the above mentioned error.I wanted to store the current date in Date format
Reference: https://pig.apache.org/docs/r0.11.1/api/org/apache/pig/builtin/ToDate.html
Highlighted

Re: ToDate java.lang.illegalargumentexception invalid format is malformed at Z

Super Guru
@Omkar Nalawade

simple way to get CURRENT_DATE variable in date format in pig is

grunt> %declare DATE `date -u +%Y-%m-%d`; //set CURRENT_DATE in UTC format
grunt> sh echo $CURRENT_DATE; //check CURRENT_DATE variable value
2017-10-29