Is there any Conditional IF like operator in Apache PIG?

后端 未结 5 1022
灰色年华
灰色年华 2020-12-18 20:35

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

相关标签:
5条回答
  • 2020-12-18 21:19

    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.

    0 讨论(0)
  • 2020-12-18 21:24

    There is a CASE Statement available from version 0.12 onwards.

    0 讨论(0)
  • 2020-12-18 21:28

    You can create a Python wrapper around your Pig script. See Embedded Pig in the docs.

    0 讨论(0)
  • 2020-12-18 21:30

    Create a UDF (say, in Java) and then embed that into your PIG script. You will need to 'register' the jar file that you generate after writing the UDF.

    //(something like this), say your Java UDF class is UDFCondition & the generated jar file is PigUDFCondition.jar, then in your PIG Code

    register PigUDFCondition.jar

    X = foreach A generate UDFCondition(..flag...)
    
    0 讨论(0)
  • 2020-12-18 21:32

    Pig is data flow language not control flow. Only construct which comes close is PIG split, but it is very limited.

    You can use oozie and its decision construct with two pig scripts.

    0 讨论(0)
提交回复
热议问题