Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Threaded View
Pig, mail # user - Replace at position in string


Copy link to this message
-
Re: Replace at position in string
Gianmarco De Francisci Mo... 2012-04-13, 13:23
Hi,
I think you can accomplish what you want with Substring and Concat in a
generate statement.

Something along these lines:

a = load 'strings' as (line:chararray);
b = foreach a generate CONCAT(REPLACE(SUBSTRING(line, 0, 2), 'ab', 'mn',),
SUBSTRING(line, 2, SIZE(line)));

Of course you can use constant strings instead of replace if needed.

Disclaimer: I haven't tested the code, it is right off the top of my head.

Cheers,
--
Gianmarco

On Fri, Apr 13, 2012 at 14:17, Shin Chan <[EMAIL PROTECTED]> wrote:

> Hi all,
>
>  How to replace some value in string at particular location
>
>  For example
>
>  abcd
>
>  Replace values from index 0-1 with mn
>
>  mncd as output
>
>  Any built in UDF or i should write own UDF?.
>
>  I checked existing Replace method , it replaces value to some another
> value.
>
> Thanks and Regards ,
>