You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pig.apache.org by Mark <st...@gmail.com> on 2011/08/10 07:25:40 UTC

Replacing values

I have some tuples and I would like to be able to transform the first 
row using the REGEX_EXTRACT method but leave all the other rows 
untouched. Now I can easily do this with known and/or named fields but I 
do not know the exact number of values in each tuple so something like 
the following will not work:

foo = foreach views generate REGEX_EXTRACT($0, '.*\\b(\\d+)$', 1), $1, 
$2, $3

I've tried the following but this duplicates the first value un-extracted:

foo = foreach views generate REGEX_EXTRACT($0, '.*\\b(\\d+)$', 1), *

Is there anyway I can accomplish modifying just the first value in each 
tuple with an unknown number of values in each tuple?

Thanks






Re: Replacing values

Posted by Thejas Nair <th...@hortonworks.com>.
We released the range projection feature in pig 0.9 because we knew you 
were going to ask this question ;)

See - 
http://www.hortonworks.com/new-apache-pig-0-9-features-part-3-additional-features/
and http://pig.apache.org/docs/r0.9.0/basic.html#expressions

That would be -

foo = foreach views generate REGEX_EXTRACT($0, '.*\\b(\\d+)$', 1), $1 .. ;

Thanks,
Thejas




On 8/9/11 10:25 PM, Mark wrote:
> I have some tuples and I would like to be able to transform the first
> row using the REGEX_EXTRACT method but leave all the other rows
> untouched. Now I can easily do this with known and/or named fields but I
> do not know the exact number of values in each tuple so something like
> the following will not work:
>
> foo = foreach views generate REGEX_EXTRACT($0, '.*\\b(\\d+)$', 1), $1,
> $2, $3
>
> I've tried the following but this duplicates the first value un-extracted:
>
> foo = foreach views generate REGEX_EXTRACT($0, '.*\\b(\\d+)$', 1), *
>
> Is there anyway I can accomplish modifying just the first value in each
> tuple with an unknown number of values in each tuple?
>
> Thanks
>
>
>
>
>