How to get a substring from a given string in Pig?

This is for Hadoop eco system like HDFS, Map reduce, Hive, Hbase, Pig, sqoop,sqoop2, Avro, solr, hcatalog, impala, Oozie, Zoo Keeper and Hadoop distribution like Cloudera, Hortonwork etc.
dharama123
Posts: 125
Joined: Wed Aug 27, 2014 1:10 am
Contact:

How to get a substring from a given string in Pig?

Postby dharama123 » Wed Sep 17, 2014 3:26 am

How i can get a substring from a given String using Pig Script?


Guest

Re: How to get a substring from a given string in Pig?

Postby Guest » Wed Sep 17, 2014 3:28 am

Use the SUBSTRING function to return a substring from a given string.

Given a field named alpha whose value is ABCDEF, to return substring BCD use this statement: SUBSTRING(alpha,1,4). Note that 1 is the index of B (the first character of the substring) and 4 is the index of E (the character following the last character of the substring).

SUBSTRING(string, startIndex, stopIndex)

A = LOAD '/user/Ram/file.txt' USING PigStorage;
B = FOREACH A GENERATE SUBSTRING($0, 16, 19);
DUMP B;

Result
(Jan)


Return to “Hadoop and Big Data”

Who is online

Users browsing this forum: No registered users and 1 guest