Home | About | Sematext search-lucene.com search-hadoop.com
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB
 Search Hadoop and all its subprojects:

Switch to Plain View
Pig >> mail # user >> Replace at position in string


+
Shin Chan 2012-04-13, 12:17
Copy link to this message
-
Re: Replace at position in string
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 ,
>
+
Kris Coward 2012-04-13, 13:34
+
Jonathan Coveney 2012-04-13, 16:07
+
jagatsingh@... 2012-04-13, 16:03
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB