Convert date into number - Apache PIG

Imagine that I've a field called date in this format: "yyyy-mm-dd" and I want to convert to number like "yyymmdd". For that I'm trying to use this:

Data_ID = FOREACH File GENERATE CONCAT((chararray)SUBSTRING(Date,0,4),(chararray)SUBSTRING(Date,6,2),(chararray)SUBSTRING(Date,9,2));

But I'm getting a list of nulls...

Anyone knows what I'm doing wrong?

Thnaks!

Topic etl apache-pig

Category Data Science


I don't use PIG, but from looking online I think you should be able to use the Replace function built into PIG.

Assuming your Date field is already a string:

Data_ID = FOREACH File GENERATE(int) REPLACE(Date,'-','');

Here's the reference if it's helpful: https://pig.apache.org/docs/r0.9.1/func.html#replace

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.