Marcelo Penteado
Marcelo Penteado

Reputation: 23

How to split a tuple in character '\' in PIG

I'm beginning learn PIG and I want to split a tuple in character '\'. My original tuple is

(192.168.2.227\al0000)

and I need to split it in '\'

(192.168.2.227, al0000)

I tryed to use

B =  FOREACH original GENERATE FLATTEN (STRSPLIT(tuple, '\\u034B'));

but it dont work. What is the proper solution ?

Upvotes: 1

Views: 574

Answers (2)

Murali Rao
Murali Rao

Reputation: 2287

Input :

192.168.2.227\al0000

Pig Script :

A = LOAD 'input.csv' as line;  
B = FOREACH A GENERATE FLATTEN (STRSPLIT(line, '([\\\\])'));
dump B; 

Second argument used is a regex to identify '\'

Output :

(192.168.2.227,al0000)

Ref :

  1. http://pig.apache.org/docs/r0.14.0/func.html#strsplit
  2. Can't escape the backslash with regex?

Upvotes: 2

Did you try '\\\\' in place of the strange unicode code point u034B?

Upvotes: 0

Related Questions