You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pig.apache.org by Margus Roo <ma...@roo.ee> on 2014/12/16 08:10:13 UTC
How to add new column into row
Hi
I have rows contains different timestamp columns in format YYYYMMDDhhmmss.
And I'd like to create a new timestamp using another field called type.
So if type = 1 then I use one timestamp field and if type=2 then I use
another timestamp field.
And there is more. The new timestamp fields format should be YYYYMMDD.
So I can save them using MultiStore into separate directories.
I played with CASE WHEN THEN. But if I included all fields and tried to
add something after THEN I got that there are similar fields error.
So I have to create a new one.
And the second issue how to substring? Is it possible? I tried with
STREAM and awk but this is not so clean I hoped :)
--
Margus (margusja) Roo
http://margus.roo.ee
skype: margusja
+372 51 480
Re: How to add new column into row
Posted by Margus Roo <ma...@roo.ee>.
Found solution
substring comes from:
DEFINE SUBSTRING org.apache.pig.piggybank.evaluation.string.SUBSTRING();
And new field is possible like this:
X = FOREACH A GENERATE (
CASE
WHEN type==1 THEN SUBSTRING((chararray)charging_start_time_str, 0, 8)
...
ELSE '20000101'
END
), *;
Margus (margusja) Roo
http://margus.roo.ee
skype: margusja
+372 51 480
On 16/12/14 09:10, Margus Roo wrote:
> Hi
>
> I have rows contains different timestamp columns in format
> YYYYMMDDhhmmss.
> And I'd like to create a new timestamp using another field called type.
> So if type = 1 then I use one timestamp field and if type=2 then I use
> another timestamp field.
> And there is more. The new timestamp fields format should be YYYYMMDD.
> So I can save them using MultiStore into separate directories.
>
> I played with CASE WHEN THEN. But if I included all fields and tried
> to add something after THEN I got that there are similar fields error.
> So I have to create a new one.
> And the second issue how to substring? Is it possible? I tried with
> STREAM and awk but this is not so clean I hoped :)
>