问题描述
实际上我正在编写 PIG 脚本,并且希望在满足其中一个条件时执行一些语句集.
我设置了一个变量并检查该变量的某个值.假设
if flag==0 thenA = LOAD 'file' using PigStorage() as (f1:int, ....);B = ...;C = ....;别的又是一些 Pig Latin 语句
我可以在 PIG Script 中执行此操作吗?如果是,那我该怎么做?
谢谢.
是的,Pig 确实提供了 if-then-else 结构,但它没有按照您要求的方式使用.
Pig 的 if-then-else 是一个算术运算符 使用简写condition ? true_value : false_value"作为表达式的一部分调用,例如:
X = FOREACH A GENERATE f2, (f2==1?1:COUNT(B));
您必须已经加载了表 A 才能执行此操作.要围绕整个 Pig 语句执行控制流,您需要像 Fakrudeen 建议的 oozie 之类的东西.>
Actually I am writing PIG Script and want to execute some set of statements if one of the condition is satisfied.
I have set one variable and checking for some value of that variable. Suppose
if flag==0 then
A = LOAD 'file' using PigStorage() as (f1:int, ....);
B = ...;
C = ....;
else
again some Pig Latin statements
Can I do this in PIG Script? If yes, then how can I do this?
Thanks.
Yes, Pig does offer an if-then-else construction, but it is not used in the way you're asking.
Pig's if-then-else is an arithmetic operator invoked with the shorthand "condition ? true_value : false_value" as part of an expression, such as:
X = FOREACH A GENERATE f2, (f2==1?1:COUNT(B));
You have to already have loaded the table A to do this. To execute control flow around entire Pig statements you'll need something like oozie, as suggested by Fakrudeen.
这篇关于Apache PIG 中是否有条件 IF 之类的运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!