su-
su-

Reputation: 3166

Pig - date string to long conversion

I have some date values in the source text file, like column 3 below

123|text|2000-02-05 01:00:00-0500|true

how can I convert them to corresponding long value in Pig latin? Thanks.

a = load 'test.txt';
b = <what should be here>(a);
dump b; --output contains long value for column 3

Upvotes: 2

Views: 5779

Answers (1)

Frederic
Frederic

Reputation: 3284

You can use the UDFs from Piggybank to convert you date string to ISO format using the CustomFormatToISO UDF and then convert your ISO formatted date to Unix milliseconds using the ISOToUnix UDF.

Starting with pig 0.11 you can use the DateTime type and call the ToUnixTime builtin UDF.

You can also write your own UDF for that problem, it's really simple.

Upvotes: 3

Related Questions