how to use logical operators in OOZIE workflow

不打扰是莪最后的温柔 提交于 2019-12-09 18:34:14

问题


i have a oozie workflow im using decision control node in the predicate i want to "&&" two different conditions and i need to use "&&" in between them for the final TRUE/FALSE result

i dont find the predicate syntax for such conditions

im using this

 <decision name="comboDecision">
        <switch>
            <case to="alpha">
              ---------
            </case>
        </switch>
  </decision>

i want to do this =

<decision name="comboDecision">
        <switch>
            <case to="alpha">
             condition1 && condition2
            </case>
        </switch>
  </decision>

can anyone help me with the syntax ?


回答1:


I will explain this with an example.

Let's assume that we have a Java action (we will call this action as getAgeInfo), which outputs age of a person:

'person.age': Age of the person

The action:

<action name='getAgeInfo'> 
    <!--Outputs 1 property: person.age: returns age of the person--> 
    <java> 
        ..........
    </java> 
    <ok to="makeClassification" /> 
    <error to="fail" /> 
</action>

The next action is makeClassification. In makeClassification action, we classify a person into "child", "teenager", "mid-aged" or "senior-citizen", based on the person's age.

For e.g. if a person's age is greater than or equal to (ge) 12 (and) less than (lt) 20, we classify that person as a teenager and the workflow transitions to teenager action.

Following is the switch statement, which illustrates use of "and":

<decision name="makeClassification"> 
    <switch> 
        <case to="child"> 
            ${wf:actionData('getAgeInfo')['person.age'] gt 0 &&
              wf:actionData('getAgeInfo')['person.age'] lt 12} 
        </case> 
        <case to="teenager"> 
            ${wf:actionData('getAgeInfo')['person.age'] ge 12 && 
              wf:actionData('getAgeInfo')['person.age'] lt 20} 
        </case> 
        <case to="mid-aged"> 
            ${wf:actionData('getAgeInfo')['person.age'] ge 20 && 
              wf:actionData('getAgeInfo')['person.age'] lt 50} 
        </case> 
        <case to="senior-citizen"> 
            ${wf:actionData('getAgeInfo')['person.age'] ge 50} 
        </case> 
        <default to="error"/> 
    </switch> 
</decision>

You can see another example here: Oozie by Example, which illustrates the use of gt (greater than), lt (less than), logical or (||), logical and (&&).




回答2:


oozie EL functions/expression are using JSP Expression Language syntax. from oozie's doc

You can check the JSP 2.0 specification to get the syntax.

Specifically for your question, the answer is:

<decision name="comboDecision">
    <switch>
        <case to="alpha">${(condition1) and (condition2)}</case>
        <default to="end"/>
    </switch>
</decision>


来源:https://stackoverflow.com/questions/33957236/how-to-use-logical-operators-in-oozie-workflow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!