0
$\begingroup$

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!

$\endgroup$

1 Answer 1

0
$\begingroup$

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.