hadoop - How Replace function in Pig works? -
my input file name words.txt below . there no space in each record of below file .
hi hi how
i loading file pig
words = load '/user/inputs/words.txt' using pigstorage() (line:chararray); words_each = foreach words generate replace(line,'','|') ; dump words_each;
i getting output
|h|i| |h|i| |h|o|w|
but know how replace functions treats '' second argument in replace function .
there no empty space in file, how come getting | in output .
well, per statement, replace function called on ''
. doesn't contain whitespace.
if want replace space, need give ' '
. +
both different conditions given below:
words_each = foreach words generate replace(line,'','|') ; // without space words_each = foreach words generate replace(line,' ','|') ; // space
first condition add pipe symbol(|) after each character, while 2nd condition won't make impact because there no space in file content.
Comments
Post a Comment