regex - How to get the last element in Pig Script -


i want last element of line using pig script. cant use $ index of last element not fixed. tried using regular expression not working. tried using $-1 didn't work. posting sample actual file contains more of pid's.

sample:

msh|�~\&|lab|lab|heath|hea-heal|20247||ou�r01|m1738000000001|p|2.3|||er|er| pid|1|yxq120185751001|yxq120185751001||eljkdp@#pdub||19790615|f||| h lggh vw��zhvw fkhvwhu�sd�19380|||||||4002c340778a|000009561|eljkdp@#pdub19790615f 

i want ot last value of pid i;e eljkdp@#pdub19790615f have tried below code's not working.

code 1:

stock_a = load '/user/rt/parsed' using pigstorage('|');  data = filter stock_a ($0 matches '.*pid.*');  msh_data = foreach data generate $2 id, $5 ame , $7 dob, $8 gender, $-1 rk; 

code 2:

stock_a = load '/user/rt/parsed' using pigstorage('|');  data = filter stock_a ($0 matches '.*pid.*');  msh_data = foreach data generate $2 id, $5 ame , $7 dob, $8 gender, regex_extract(data,'\\s*(\\w+)$',1) rk; 

error code 2:

error org.apache.pig.tools.grunt.grunt - error 1200: pig script failed parse: invalid scalar projection: data : column needs projected relation used scalar

please help

this should work

regex_extract(data,'([^|]+$)',1) rk 

[^|]+$ matches right of last pipe character.

output


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -