animal
animal

Reputation: 1004

Concat after checking condition in Pig

I am trying to CONCAT a column in my pig if a certain condition is getting matched for that i am using below code but it is throwing error.

CODE:

STOCK_A = LOAD '/user/cloudera/pati1.hl7' USING PigStorage('|');
data = FILTER STOCK_A BY ($0 matches '.*OBR.*' or $0  matches '.*OBX.*');
MSH_DATA = FOREACH data GENERATE ($0=='OBR' ? CONCAT('OBR',CurrentTime(),$1) : ($0=='OBX' ? CONCAT('OBR',CurrentTime(),$1))) AS Uid; , $1 AS id, $5 AS result, $3 AS resultname;
Dump MSH_DATA;

ERROR:

ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1200: <line 13, column 122>  mismatched input ')' expecting COLON

Upvotes: 0

Views: 179

Answers (1)

nobody
nobody

Reputation: 11080

Source:CONCAT : The data type of the two elements must be the same, either chararray or bytearray.

First,You are trying to CONCAT fields of different datatype.Cast the fields to chararray.Second, your bincond syntax is incorrect.Since you have already filtered the records for values OBR and OBX,you need not check for $0 == 'OBX'.Third, when the value of $0 == 'OBX' you are again concatenating OBR with the current time which is same as the if part.Fourth, there is a ';' after Uid which is incorrect.

MSH_DATA = FOREACH data GENERATE ($0 == 'OBR' ? CONCAT('OBR',ToString(CurrentTime(), 'yyyy-MM-dd\'T\'HH:mm:ssz'),(chararray)$1) : CONCAT('OBX',ToString(CurrentTime(), 'yyyy-MM-dd\'T\'HH:mm:ssz'),(chararray)$1)) AS Uid, $1 AS id, $5 AS result, $3 AS resultname;

Upvotes: 1

Related Questions