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

Popular posts from this blog

javascript - Feed FileReader from server side files -

python - Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] error -

oracle - pls-00402 alias required in select list of cursor to avoid duplicate column names -