可以将三元运算符与store in pig一起使用吗

vvppvyoh  于 2021-06-21  发布在  Pig
关注(0)|答案(1)|浏览(528)

在apache pig中,如果我想有条件地存储一些数据,并尝试这样做:

data1 = ....;
data2 = ....;
STORE (condition ? data1 : data2) INTO '$output' USING PigStorage(",");
--assuming pig is smart enough not to run the query for data1 or data2 depending on the condition

然后我得到一个语法错误:

SEVERE: exception during parsing: Error during parsing. <file test.pig, line 38, column 6>  Syntax error, unexpected symbol at or near '('
Failed to parse: <file test.pig, line 38, column 6>  Syntax error, unexpected symbol at or near '('

我是否在pig中错误地使用了三元运算符,如果这不可能,有没有其他方法可以在pig中实现条件存储,最好不用编写udf。

5q4ezhmt

5q4ezhmt1#

不能在store语句中使用三元运算,因为您正试图在问题中这样做。您可以将条件列添加到data1和data2,然后获取联合,然后根据条件值筛选联合的数据。

data1 = ....
data1a = CROSS data1, condition;

data2 = ....
data2a = CROSS data2, condition;

data12 = UNION data1a, data2a;
final = FILTER data12 BY condition == true;

STORE final INTO '$output' USING PigStorage(",");

希望这有帮助。

相关问题