PIG中是否有条件IF运算符

PIG中是否有条件IF运算符

本文介绍了Apache PIG中是否有条件IF运算符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上,我正在编写PIG脚本,并希望在条件满足时执行一些语句集。



我设置了一个变量并检查某个值的变量。假设

  if flag == 0 then 
A = LOAD'file'使用PigStorage()as(f1:int ,...);
B = ...;
C = ....;
else
再一些Pig拉丁语句

我可以在PIG Script中执行此操作吗?如果是的话,那么我该如何做到这一点?



谢谢。

解决方案

是的,Pig确实提供了一个if-then-else的结构,但它没有以你问的方式使用

猪的if-then-else ,用简写condition?true_value:false_value作为表达式的一部分进行调用,例如:

  X = FOREACH A GENERATE f2,(f2 == 1?1:COUNT(B)); 

您必须已经加载了表A才能执行此操作。要执行整个Pig语句的控制流程,您需要按照Fakrudeen的建议。 p>

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运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 21:06