Files
doc-exports/docs/dataartsstudio/umn/dataartsstudio_01_0583.html
chenxiaoxiong f9e2808b7c DataArts UMN 20250810 version
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com>
Co-authored-by: chenxiaoxiong <chenxiaoxiong@huawei.com>
Co-committed-by: chenxiaoxiong <chenxiaoxiong@huawei.com>
2025-09-02 10:44:13 +00:00

99 lines
36 KiB
HTML

<a name="dataartsstudio_01_0583"></a><a name="dataartsstudio_01_0583"></a>
<h1 class="topictitle1">IF Statements</h1>
<div id="body8662426"><p id="dataartsstudio_01_0583__en-us_topic_0000001162343901_en-us_topic_0000001073100734_p2567186349">When developing and orchestrating jobs in DataArts Factory, you can use IF statements to determine the branch to execute.</p>
<p id="dataartsstudio_01_0583__en-us_topic_0000001162343901_p757235514393">This section describes how to use IF statements in the following scenarios:</p>
<ul id="dataartsstudio_01_0583__en-us_topic_0000001162343901_ul955219434010"><li id="dataartsstudio_01_0583__en-us_topic_0000001162343901_li1255254154015"><a href="#dataartsstudio_01_0583__en-us_topic_0000001162343901_en-us_topic_0000001073100734_section14991730115912">Determining the IF Statement Branch to Be Executed Based on the Execution Status of the Previous Node</a></li><li id="dataartsstudio_01_0583__en-us_topic_0000001162343901_li355219424012"><a href="#dataartsstudio_01_0583__en-us_topic_0000001162343901_section191402715452">Determining the IF Statement Branch to Be Executed Based on the Execution Result of the Previous Node</a></li><li id="dataartsstudio_01_0583__li121141929152718"><a href="#dataartsstudio_01_0583__section1626375417376">Configuring the Policy for Executing a Node with Multiple IF Statements</a></li></ul>
<p id="dataartsstudio_01_0583__en-us_topic_0000001162343901_p163576216509">IF statements use EL expressions. You can select EL expressions and follow the instruction in this section to develop jobs.</p>
<div class="section" id="dataartsstudio_01_0583__en-us_topic_0000001162343901_en-us_topic_0000001073100734_section14991730115912"><a name="dataartsstudio_01_0583__en-us_topic_0000001162343901_en-us_topic_0000001073100734_section14991730115912"></a><a name="en-us_topic_0000001162343901_en-us_topic_0000001073100734_section14991730115912"></a><h4 class="sectiontitle">Determining the IF Statement Branch to Be Executed Based on the Execution Status of the Previous Node</h4><p id="dataartsstudio_01_0583__en-us_topic_0000001162343901_p1035798173616"><strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b416218461135">Scenario</strong></p>
<p id="dataartsstudio_01_0583__en-us_topic_0000001162343901_en-us_topic_0000001073100734_p1980655818414">Generally, you can determine the IF statement branch to be executed based on whether the previous CDM node is successfully executed. For details on how to set IF statements, see <a href="#dataartsstudio_01_0583__en-us_topic_0000001162343901_en-us_topic_0000001073100734_fig1727424664320">Figure 1</a>.</p>
<div class="fignone" id="dataartsstudio_01_0583__en-us_topic_0000001162343901_en-us_topic_0000001073100734_fig1727424664320"><a name="dataartsstudio_01_0583__en-us_topic_0000001162343901_en-us_topic_0000001073100734_fig1727424664320"></a><a name="en-us_topic_0000001162343901_en-us_topic_0000001073100734_fig1727424664320"></a><span class="figcap"><b>Figure 1 </b>Example job</span><br><span><img id="dataartsstudio_01_0583__en-us_topic_0000001162343901_image15922423155011" src="en-us_image_0000002269116645.png" title="Click to enlarge" class="imgResize"></span></div>
<p id="dataartsstudio_01_0583__en-us_topic_0000001162343901_p116234214367"><strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b416455781417">Configuration Method</strong></p>
<ol id="dataartsstudio_01_0583__en-us_topic_0000001162343901_ol385085735213"><li id="dataartsstudio_01_0583__en-us_topic_0000001162343901_li7850057145212"><span>Log in to the <span id="dataartsstudio_01_0583__text78071439114517">DataArts Studio</span> console, locate the target <span id="dataartsstudio_01_0583__text198094393454">DataArts Studio</span> instance, and click <strong id="dataartsstudio_01_0583__b1810039154516">Access</strong> on the instance card.</span></li><li id="dataartsstudio_01_0583__en-us_topic_0000001162343901_li1585025716526"><span>Click the <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b52891559171510">Workspaces</strong> tab. In the workspace list, locate the target workspace and click <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b2153103182213">DataArts Factory</strong>. The DataArts Factory console is displayed.</span></li><li id="dataartsstudio_01_0583__li5143918161"><span>On the <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b19438115411234">Develop Job</strong> page, create a job, drag a CDM node and two Dummy nodes and drop them on the canvas in the right pane. Click and hold <span><img id="dataartsstudio_01_0583__en-us_topic_0000001162343901_image459381712591" src="en-us_image_0000002269116637.png"></span> to connect the CDM node to the Dummy nodes, as shown in <a href="#dataartsstudio_01_0583__en-us_topic_0000001162343901_en-us_topic_0000001073100734_fig1727424664320">Figure 1</a>.</span><p><p id="dataartsstudio_01_0583__p7895171811613">Set the <strong id="dataartsstudio_01_0583__b1948322493919">Failure Policy</strong> for the CDM node to <strong id="dataartsstudio_01_0583__b12483142433914">Go to the next node</strong>.</p>
<div class="fignone" id="dataartsstudio_01_0583__fig1177617229616"><span class="figcap"><b>Figure 2 </b>Configuring the failure policy for the CDM node</span><br><span><img id="dataartsstudio_01_0583__image47611833476" src="en-us_image_0000002269196749.png" title="Click to enlarge" class="imgResize"></span></div>
<p id="dataartsstudio_01_0583__p275016331810"></p>
<p id="dataartsstudio_01_0583__p118521219865"></p>
</p></li><li id="dataartsstudio_01_0583__en-us_topic_0000001162343901_li585111357612"><span>Right-click the connection line and select <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b195224019397">Set Condition</strong>. In the <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b17231112153919">Edit EL Expression</strong> dialog box, enter the IF statement in the text box.</span><p><p id="dataartsstudio_01_0583__en-us_topic_0000001162343901_p96563362061">Each statement branch requires an IF statement. The IF statement is a ternary expression based on the EL expression syntax. If the result of the ternary expression is <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b1039171310436">true</strong>, subsequent nodes will be connected. Otherwise, subsequent nodes will be skipped.</p>
<p id="dataartsstudio_01_0583__en-us_topic_0000001162343901_p16837174095918">In this demo, the <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b40142811434">#{Job.getNodeStatus("node_name")}</strong> EL expression is used to obtain the execution status of a specified node. If the execution is successful, <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b19127183116447">success</strong> is returned; otherwise, <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b9521747104416">fail</strong> is returned. In this example, the IF statement expressions are as follows:</p>
<ul id="dataartsstudio_01_0583__en-us_topic_0000001162343901_ul54111213313"><li id="dataartsstudio_01_0583__en-us_topic_0000001162343901_li040122319">The IF statement expression for branch A is <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b393241414610">#{(Job.getNodeStatus("CDM")) == "success" ?</strong>. "true" : "false"}</li><li id="dataartsstudio_01_0583__en-us_topic_0000001162343901_li17420121230">The IF statement expression for branch B is <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b16925626114614">#{(Job.getNodeStatus("CDM")) == "fail" ?</strong>. "true" : "false"}</li></ul>
<div class="p" id="dataartsstudio_01_0583__en-us_topic_0000001162343901_p4363174316337">After entering the IF statement expression, you can select either <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b192671411114818">Skip all subsequent nodes</strong> or <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b8379182219481">Skip the next node</strong> for <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b17426493482">Failure Policy</strong>. After the configuration is complete, click <strong id="dataartsstudio_01_0583__b1026585312102">OK</strong> to save the job.<div class="fignone" id="dataartsstudio_01_0583__en-us_topic_0000001162343901_en-us_topic_0000001073100734_fig831416114181"><span class="figcap"><b>Figure 3 </b>Configuring a failure policy</span><br><span><img id="dataartsstudio_01_0583__en-us_topic_0000001162343901_image469419511121" src="en-us_image_0000002234077448.png" title="Click to enlarge" class="imgResize"></span></div>
</div>
</p></li><li id="dataartsstudio_01_0583__en-us_topic_0000001162343901_li15791751154515"><span>Click <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b37568147499">Test</strong> to test the job and view the execution result on the <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b199081841134918">Monitor Instance</strong> page.</span></li><li id="dataartsstudio_01_0583__en-us_topic_0000001162343901_li104762315513"><span>After the job is executed, view the job instance running result on the <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b19457124405020">Monitor Instance</strong> page. The execution result meets the expectation. If the execution result is <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b2955839105111">fail</strong>, branch A is skipped and branch B is executed.</span><p><div class="fignone" id="dataartsstudio_01_0583__en-us_topic_0000001162343901_fig159981523165117"><span class="figcap"><b>Figure 4 </b>Job execution result</span><br><span><img id="dataartsstudio_01_0583__en-us_topic_0000001162343901_image1216919151276" src="en-us_image_0000002269196757.png" title="Click to enlarge" class="imgResize"></span></div>
</p></li></ol>
</div>
<div class="section" id="dataartsstudio_01_0583__en-us_topic_0000001162343901_section191402715452"><a name="dataartsstudio_01_0583__en-us_topic_0000001162343901_section191402715452"></a><a name="en-us_topic_0000001162343901_section191402715452"></a><h4 class="sectiontitle">Determining the IF Statement Branch to Be Executed Based on the Execution Result of the Previous Node</h4><p id="dataartsstudio_01_0583__en-us_topic_0000001162343901_p48551004391"><strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b122601825512">Scenario Description</strong></p>
<p id="dataartsstudio_01_0583__en-us_topic_0000001162343901_p1836117710377">Scenario: Use the Hive SQLnode to collect statistics on the number of people whose score is higher than 85, transfer the execution result as a parameter to the next node, compare the result with the number of people who have passed the test, and determine the IF condition branch to be executed.</p>
<p id="dataartsstudio_01_0583__p1538603804617">Analysis: The execution result of the select statement on the Hive SQL node is a two-dimensional array which contains a single field. Therefore, EL expression <strong id="dataartsstudio_01_0583__b63869387464">#{Loop.dataArray[][]}</strong> or <strong id="dataartsstudio_01_0583__b193861038154618">#{Loop.current[]}</strong> can be used to obtain the value in the two-dimensional array. Currently, only the For Each node supports loop expressions, so the Hive SQL node needs to be connected to a For Each node.</p>
<div class="note" id="dataartsstudio_01_0583__note2029924415466"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="dataartsstudio_01_0583__p91581629134710">In this scenario, the loop expression cannot be replaced by the StringUtil expression <strong id="dataartsstudio_01_0583__b1632111217018">#{StringUtil.split(StringUtil.split(StringUtil.split(Job.getNodeOutput("<em id="dataartsstudio_01_0583__i1659736102">Name of the previous node</em>"),"]")[0],"[")[0],"\\"")[0]}</strong> because the StringUtil expression returns a string which cannot be compared with the standard data of the int type.</p>
</div></div>
<p id="dataartsstudio_01_0583__en-us_topic_0000001162343901_p1363671014617"><a href="#dataartsstudio_01_0583__en-us_topic_0000001162343901_fig1639792911135">Figure 5</a> shows the job orchestration.</p>
<div class="fignone" id="dataartsstudio_01_0583__en-us_topic_0000001162343901_fig1639792911135"><a name="dataartsstudio_01_0583__en-us_topic_0000001162343901_fig1639792911135"></a><a name="en-us_topic_0000001162343901_fig1639792911135"></a><span class="figcap"><b>Figure 5 </b>Example job</span><br><span><img id="dataartsstudio_01_0583__en-us_topic_0000001162343901_image73661915113318" src="en-us_image_0000002234237324.png" title="Click to enlarge" class="imgResize"></span></div>
<p id="dataartsstudio_01_0583__en-us_topic_0000001162343901_p1438172518337">Key configurations of the For Each node are as follows:</p>
<ul id="dataartsstudio_01_0583__en-us_topic_0000001162343901_ul13874125811393"><li id="dataartsstudio_01_0583__en-us_topic_0000001162343901_li487418587394"><strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b3798173119320">Dataset</strong>: Enter the execution result of the select statement on the Hive SQL node. Use the <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b169465144413">#{Job.getNodeOutput('HIVE')}</strong> expression, where <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b129741819642">HIVE</strong> is the name of the previous node.</li><li id="dataartsstudio_01_0583__en-us_topic_0000001162343901_li2508102204013"><strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b1120213522417">Subjob Parameter Name</strong>: Enter the parameter defined in the subjob. Transfer the output of the previous node of the main job to the sub-job for use. The variable name is <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b9561154785512">result</strong>, and its value is a column in the dataset. The EL expression <strong id="dataartsstudio_01_0583__b1527112262425">#</strong><strong id="dataartsstudio_01_0583__b549213254424">{Loop.dataArray[0][0]}</strong> or <strong id="dataartsstudio_01_0583__b18274633204211">#{Loop.current[]}</strong> is used. This example uses <strong id="dataartsstudio_01_0583__b281284318421">{Loop.dataArray[0][0]}</strong> as an example.</li></ul>
<p id="dataartsstudio_01_0583__en-us_topic_0000001162343901_p1039742920134">The sub-job selected on the For Each node determines the IF statement branch to be executed based on the subjob parameter transferred from the For Each node. <a href="#dataartsstudio_01_0583__en-us_topic_0000001162343901_fig517111111225">Figure 6</a> shows the job orchestration.</p>
<div class="fignone" id="dataartsstudio_01_0583__en-us_topic_0000001162343901_fig517111111225"><a name="dataartsstudio_01_0583__en-us_topic_0000001162343901_fig517111111225"></a><a name="en-us_topic_0000001162343901_fig517111111225"></a><span class="figcap"><b>Figure 6 </b>Example sub-job</span><br><span><img id="dataartsstudio_01_0583__en-us_topic_0000001162343901_image1829683717241" src="en-us_image_0000002234077436.png" title="Click to enlarge" class="imgResize"></span></div>
<p id="dataartsstudio_01_0583__en-us_topic_0000001162343901_p105633513714">The IF statement is the key configuration of the subjob. This example uses the expression <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b7432184981011">${result}</strong> to obtain the value of the job parameter.</p>
<div class="note" id="dataartsstudio_01_0583__en-us_topic_0000001162343901_note1546120419520"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="dataartsstudio_01_0583__en-us_topic_0000001162343901_p16691216153">Do not use the <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b1137342111119">#{Job.getParam("job_param_name")}</strong> EL expression because this expression can only obtain the values of the parameters configured in the current job, but cannot obtain the parameter values transferred from the parent job or the global variables configured in the workspace. The expression only works for the current job.</p>
<p id="dataartsstudio_01_0583__en-us_topic_0000001162343901_p85351447162819">To obtain the parameter values passed from the parent job and the global variables configured for the workspace, you are advised to use the <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b7413133218157">${job_param_name}</strong> expression.</p>
</div></div>
<p id="dataartsstudio_01_0583__en-us_topic_0000001162343901_p86132236281"><strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b927311445219">Configuration Method</strong></p>
<p id="dataartsstudio_01_0583__en-us_topic_0000001162343901_p937792514371">Developing a Subjob</p>
<ol id="dataartsstudio_01_0583__en-us_topic_0000001162343901_ol12198621103719"><li id="dataartsstudio_01_0583__en-us_topic_0000001162343901_li193978297137"><span>Log in to the <span id="dataartsstudio_01_0583__text12944114854512">DataArts Studio</span> console, locate the target <span id="dataartsstudio_01_0583__text9945148204520">DataArts Studio</span> instance, and click <strong id="dataartsstudio_01_0583__b13947134854513">Access</strong> on the instance card.</span></li><li id="dataartsstudio_01_0583__en-us_topic_0000001162343901_li7198421163711"><span>Click the <strong id="dataartsstudio_01_0583__b995275815371">Workspaces</strong> tab. In the workspace list, locate the target workspace and click <strong id="dataartsstudio_01_0583__b2953155819371">DataArts Factory</strong>. The DataArts Factory console is displayed.</span></li><li id="dataartsstudio_01_0583__en-us_topic_0000001162343901_li8198202114373"><span>On the <strong id="dataartsstudio_01_0583__b10199521734">Develop Job</strong> page, create a data development subjob For Each. Drag four Dummy nodes and drop them on the canvas, click and hold <span><img id="dataartsstudio_01_0583__en-us_topic_0000001162343901_image193971129121313" src="en-us_image_0000002234237300.png"></span> to connect them, as shown in <a href="#dataartsstudio_01_0583__en-us_topic_0000001162343901_fig517111111225">Figure 6</a>.</span></li><li id="dataartsstudio_01_0583__en-us_topic_0000001162343901_li101987211377"><span>Right-click the connection line and select <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b0195131213199">Set Condition</strong>. In the <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b4200141241914">Edit EL Expression</strong> dialog box, enter the IF statement in the text box.</span><p><p id="dataartsstudio_01_0583__en-us_topic_0000001162343901_p19615124210309">Each statement branch requires an IF statement. The IF statement is a ternary expression based on the EL expression syntax. If the result of the ternary expression is <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b19673112211920">true</strong>, subsequent nodes will be connected. Otherwise, subsequent nodes will be skipped.</p>
<ul id="dataartsstudio_01_0583__en-us_topic_0000001162343901_ul26161742153012"><li id="dataartsstudio_01_0583__en-us_topic_0000001162343901_li66161742193018">For the <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b168934819197">&gt;5</strong> branch, the IF statement expression is <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b166602509242">#{${result} &gt; 5 ? "true" : "false"}</strong>.</li><li id="dataartsstudio_01_0583__en-us_topic_0000001162343901_li461614273017">For the <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b17767657192419">=5</strong> branch, the IF statement expression is <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b1357697258">#{${result} == 5 ? "true" : "false"}</strong>.</li><li id="dataartsstudio_01_0583__en-us_topic_0000001162343901_li15616174253011">For the <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b6796141518252">&lt;5</strong> branch, the IF statement expression is <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b1780121582518">#{${result} &lt; 5 ? "true" : "false"}</strong>.</li></ul>
<p id="dataartsstudio_01_0583__en-us_topic_0000001162343901_p31127379337">After entering the IF statement expression, you can select either <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b182273280256">Skip all subsequent nodes</strong> or <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b122281528142518">Skip the next node</strong> for <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b7228122832515">Failure Policy</strong>.</p>
<div class="note" id="dataartsstudio_01_0583__note138666243580"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="dataartsstudio_01_0583__p19392195745918">If an expression contains multiple conditions, you can use || to combine them conditions. The following is an example:</p>
<p id="dataartsstudio_01_0583__p198364095812">#{(${result} &gt;= 19 || ${result} &lt;=9) ? "true" : "false"}</p>
</div></div>
</p></li><li id="dataartsstudio_01_0583__en-us_topic_0000001162343901_li1117515214366"><span>Configure job parameters. Set the parameter name to <strong id="dataartsstudio_01_0583__b747571564519">result</strong>. This parameter is only used by the For Each node in the main job <strong id="dataartsstudio_01_0583__b154761749457">testif</strong> to identify subjob parameters. You do not need to set the parameter value.</span><p><div class="fignone" id="dataartsstudio_01_0583__en-us_topic_0000001162343901_fig6711113444014"><span class="figcap"><b>Figure 7 </b>Configuring job parameters</span><br><span><img id="dataartsstudio_01_0583__image42881554290" src="en-us_image_0000002269196765.png" title="Click to enlarge" class="imgResize"></span></div>
<p id="dataartsstudio_01_0583__p271385712713"></p>
</p></li><li id="dataartsstudio_01_0583__en-us_topic_0000001162343901_li12781624154514"><span>Save the job.</span></li></ol>
</div>
<p id="dataartsstudio_01_0583__p3666131316226">Developing a Job</p>
<ol id="dataartsstudio_01_0583__en-us_topic_0000001162343901_ol091619185382"><li id="dataartsstudio_01_0583__en-us_topic_0000001162343901_li19198102193716"><span>On the <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b125120564299">Develop Job</strong> page, create a data development job named <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b19569564293">testif</strong>. Drag a HIVE SQL node and a For Each node and drop them on the canvas. Click and hold <span><img id="dataartsstudio_01_0583__en-us_topic_0000001162343901_image549216431659" src="en-us_image_0000002269196709.png"></span> to connect the nodes, as shown in <a href="#dataartsstudio_01_0583__en-us_topic_0000001162343901_fig1639792911135">Figure 5</a>.</span></li><li id="dataartsstudio_01_0583__en-us_topic_0000001162343901_li112793693716"><span>Configure properties for the HIVE SQL node. Reference the following SQL script (there is no special requirement for other properties):</span><p><pre class="screen" id="dataartsstudio_01_0583__en-us_topic_0000001162343901_screen18291142634013">--Obtain the number of people whose scores are higher than 85 from the student_score table.
SELECT count(*) FROM student_score WHERE score&gt; "85" ;</pre>
<div class="fignone" id="dataartsstudio_01_0583__en-us_topic_0000001162343901_fig176309306309"><span class="figcap"><b>Figure 8 </b>HIVE SQL script execution result</span><br><span><img id="dataartsstudio_01_0583__image1462164710455" src="en-us_image_0000002234077496.png" title="Click to enlarge" class="imgResize"></span></div>
<p id="dataartsstudio_01_0583__p349651720461"></p>
</p></li><li id="dataartsstudio_01_0583__en-us_topic_0000001162343901_li18850173864018"><span>Configure properties for the For Each node.</span><p><ul id="dataartsstudio_01_0583__en-us_topic_0000001162343901_ul473126194116"><li id="dataartsstudio_01_0583__en-us_topic_0000001162343901_li1728281115419"><strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b16156112213714">Subjob in a Loop</strong>: Select <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b8737154617374">foreach</strong>, the subjob that has been developed.</li><li id="dataartsstudio_01_0583__en-us_topic_0000001162343901_li67311361414"><strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b5347155716370">Dataset</strong>: Enter the execution result of the select statement on the Hive SQL node. Use the <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b1253717598376">#{Job.getNodeOutput('HIVE')}</strong> expression, where <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b195371659163714">HIVE</strong> is the name of the previous node.</li><li id="dataartsstudio_01_0583__en-us_topic_0000001162343901_li1273119674118"><strong id="dataartsstudio_01_0583__b197561473213">Subjob Parameter Name</strong>: Enter the parameter defined in the subjob. Transfer the output of the previous node of the main job to the sub-job for use. The variable name is <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b192394133817">result</strong> (parameter name of the subjob), and its value is a column in the dataset. The EL expression <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b149281473813"> #{Loop.dataArray[0][0]}</strong> is used.</li></ul>
<div class="fignone" id="dataartsstudio_01_0583__en-us_topic_0000001162343901_fig176439478428"><span class="figcap"><b>Figure 9 </b>Properties of the For Each node</span><br><span><img id="dataartsstudio_01_0583__image418953143114" src="en-us_image_0000002269196781.png" title="Click to enlarge" class="imgResize"></span></div>
</p></li><li id="dataartsstudio_01_0583__en-us_topic_0000001162343901_li15453913457"><span>Save the job.</span></li></ol>
<p id="dataartsstudio_01_0583__en-us_topic_0000001162343901_p116422040164216">Testing the Main Job</p>
<ol id="dataartsstudio_01_0583__en-us_topic_0000001162343901_ol33632059124213"><li id="dataartsstudio_01_0583__en-us_topic_0000001162343901_li55861024114310"><span>Click <strong id="dataartsstudio_01_0583__b22381957171014">Test</strong> above the canvas to test the main job. After the main job is executed, the subjob is automatically invoked through the For Each node and executed.</span></li><li id="dataartsstudio_01_0583__en-us_topic_0000001162343901_li036495914429"><span>In the navigation pane on the left, choose <strong id="dataartsstudio_01_0583__b925019349115">Monitor Instance</strong> to view the job execution result.</span></li><li id="dataartsstudio_01_0583__en-us_topic_0000001162343901_li2364659144211"><span>After the job is executed, view the execution result of the subjob <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b42771129124111">foreach</strong> on the <strong id="dataartsstudio_01_0583__en-us_topic_0000001162343901_b13901753164014">Monitor Instance</strong> page. The execution result meets the expectation. Currently, the execution result of the Hive SQL statement is <strong id="dataartsstudio_01_0583__b1793613814317">4</strong>. Therefore, the <strong id="dataartsstudio_01_0583__b189369811320">&gt;5</strong> and <strong id="dataartsstudio_01_0583__b493778536">=5</strong> branches are skipped, and the <strong id="dataartsstudio_01_0583__b1593715819315">&lt;5</strong> branch is successfully executed.</span><p><div class="fignone" id="dataartsstudio_01_0583__en-us_topic_0000001162343901_fig330818168499"><span class="figcap"><b>Figure 10 </b>Execution result of the subjob</span><br><span><img id="dataartsstudio_01_0583__en-us_topic_0000001162343901_image1888912134428" src="en-us_image_0000002269196741.png" title="Click to enlarge" class="imgResize"></span></div>
</p></li></ol>
<div class="section" id="dataartsstudio_01_0583__section1626375417376"><a name="dataartsstudio_01_0583__section1626375417376"></a><a name="section1626375417376"></a><h4 class="sectiontitle">Configuring the Policy for Executing a Node with Multiple IF Statements</h4><p id="dataartsstudio_01_0583__p118215218387">If the execution of a node depends on multiple IF statements, the policy for executing the node can be <strong id="dataartsstudio_01_0583__b135102589493">AND</strong> or <strong id="dataartsstudio_01_0583__b11222105654917">OR</strong>.</p>
<p id="dataartsstudio_01_0583__p786471444811">If you choose the <strong id="dataartsstudio_01_0583__b66715262517">OR</strong> policy, the node will be executed if any one of the IF statements is met.</p>
<p id="dataartsstudio_01_0583__p7321145317503">If you choose the <strong id="dataartsstudio_01_0583__b1213064819511">AND</strong> policy, the node will be executed only if all of the IF statements are met.</p>
<p id="dataartsstudio_01_0583__p1641514289412">If you choose neither, the <strong id="dataartsstudio_01_0583__b19117337532">OR</strong> policy will be used.</p>
<div class="fignone" id="dataartsstudio_01_0583__fig1727474115310"><a name="dataartsstudio_01_0583__fig1727474115310"></a><a name="fig1727474115310"></a><span class="figcap"><b>Figure 11 </b>A job with multiple IF statements</span><br><span><img id="dataartsstudio_01_0583__image1789145810271" src="en-us_image_0000002234237348.png"></span></div>
<p id="dataartsstudio_01_0583__p16935156185715"><strong id="dataartsstudio_01_0583__b858398034">Configuration Method</strong></p>
<p id="dataartsstudio_01_0583__p1672193355814">Configure the execution policy.</p>
<ol id="dataartsstudio_01_0583__ol1615118173318"><li id="dataartsstudio_01_0583__li164064611192"><span>Log in to the <span id="dataartsstudio_01_0583__text816235219455">DataArts Studio</span> console, locate the target <span id="dataartsstudio_01_0583__text121631052124516">DataArts Studio</span> instance, and click <strong id="dataartsstudio_01_0583__b15165185214452">Access</strong> on the instance card.</span></li><li id="dataartsstudio_01_0583__li164111461190"><span>Click the <strong id="dataartsstudio_01_0583__b082016717384">Workspaces</strong> tab. In the workspace list, locate the target workspace and click <strong id="dataartsstudio_01_0583__b882518783819">DataArts Factory</strong>. The DataArts Factory console is displayed.</span></li><li id="dataartsstudio_01_0583__li141511417637"><span>On the DataArts Factory console, choose <strong id="dataartsstudio_01_0583__b177534619541">Configuration</strong> &gt; <strong id="dataartsstudio_01_0583__b18803124935417">Configure</strong> &gt; <strong id="dataartsstudio_01_0583__b95667221550">Default Configuration</strong>.</span></li><li id="dataartsstudio_01_0583__li1065634413613"><a name="dataartsstudio_01_0583__li1065634413613"></a><a name="li1065634413613"></a><span>Select <strong id="dataartsstudio_01_0583__b2648842115515">AND</strong> or <strong id="dataartsstudio_01_0583__b121031408551">OR</strong> for <strong id="dataartsstudio_01_0583__b11261158105515">Multi-IF Policy</strong>.</span></li><li id="dataartsstudio_01_0583__li11261959151211"><span>Click <strong id="dataartsstudio_01_0583__b15178040155712">Save</strong>.</span></li></ol>
<p id="dataartsstudio_01_0583__p95981934165">Develop a job.</p>
<ol id="dataartsstudio_01_0583__ol02821710141518"><li id="dataartsstudio_01_0583__li25981632161"><span>On the <strong id="dataartsstudio_01_0583__b5601144105818">Develop Job</strong> page, create a data development job.</span></li><li id="dataartsstudio_01_0583__li34604323118"><span>Drag three DWS SQL operators as parent nodes and one Python operator as a child node to the canvas. Click and hold <span><img id="dataartsstudio_01_0583__image10224536034" src="en-us_image_0000002234237340.png"></span> to connect the nodes to orchestrate the job shown in <a href="#dataartsstudio_01_0583__fig1727474115310">Figure 11</a>.</span></li><li id="dataartsstudio_01_0583__li1946153216117"><span>Right-click the connection line and select <strong id="dataartsstudio_01_0583__b1358162022">Set Condition</strong>. In the <strong id="dataartsstudio_01_0583__b1150249649">Edit EL Expression</strong> dialog box, enter the IF statement in the text box.</span><p><p id="dataartsstudio_01_0583__p11462332161117">Each statement branch requires an IF statement. The IF statement is a ternary expression based on the EL expression syntax.</p>
<ul id="dataartsstudio_01_0583__ul194621432181119"><li id="dataartsstudio_01_0583__li4462183212114">The IF statement expression for the test1 node is <strong id="dataartsstudio_01_0583__b1020618388411">#{(Job.getNodeStatus("test1")) == "success" ? </strong> <strong id="dataartsstudio_01_0583__b628815599418">"true" : "false"},</strong></li><li id="dataartsstudio_01_0583__li44621232181114">The IF statement expression for the test2 node is <strong id="dataartsstudio_01_0583__b83271117611">#{(Job.getNodeStatus("test2")) == "success" ? </strong> <strong id="dataartsstudio_01_0583__b164009281567">"true" : "false"},</strong></li><li id="dataartsstudio_01_0583__li2462173291119">The IF statement expression for the test3 node is <strong id="dataartsstudio_01_0583__b3820168720">#{(Job.getNodeStatus("test3")) == "success" ? </strong> <strong id="dataartsstudio_01_0583__b46180141175">"true" : "false"},</strong></li></ul>
<p id="dataartsstudio_01_0583__p14731134818249">The expression of each node is determined using the IF statement based on the execution status of the previous node.</p>
<p id="dataartsstudio_01_0583__p646218322118">After entering the IF statement expression, you can select either <strong id="dataartsstudio_01_0583__b902029852">Skip all subsequent nodes</strong> or <strong id="dataartsstudio_01_0583__b1670779990">Skip the next node</strong> for <strong id="dataartsstudio_01_0583__b1282947286">Failure Policy</strong>.</p>
</p></li></ol>
<p id="dataartsstudio_01_0583__p17134347271">Test the job.</p>
<ol id="dataartsstudio_01_0583__ol19134244272"><li id="dataartsstudio_01_0583__li373612279299"><span>Click <strong id="dataartsstudio_01_0583__b571917521487">Save</strong> above the canvas to save the job.</span></li><li id="dataartsstudio_01_0583__li16134194192715"><span>Click <strong id="dataartsstudio_01_0583__b6175571846113">Test</strong> above the canvas to test the job.</span><p><p id="dataartsstudio_01_0583__p11337152463713">If <strong id="dataartsstudio_01_0583__b197441355181312">test1</strong> is executed successfully, the corresponding IF statement is true.</p>
<p id="dataartsstudio_01_0583__p3581171593818">If <strong id="dataartsstudio_01_0583__b120020129143">test2</strong> is executed successfully, the corresponding IF statement is true.</p>
<p id="dataartsstudio_01_0583__p749233214380">If <strong id="dataartsstudio_01_0583__b13793280147">test3</strong> fails to be executed, the corresponding IF statement is false.</p>
<p id="dataartsstudio_01_0583__p1053091115348">If <a href="#dataartsstudio_01_0583__li1065634413613">Multi-IF Policy</a> is set to <strong id="dataartsstudio_01_0583__b82272594192">OR</strong>, the <strong id="dataartsstudio_01_0583__b198241412152019">showtables</strong> node is executed and the job execution is complete.</p>
<div class="fignone" id="dataartsstudio_01_0583__fig997516917426"><span class="figcap"><b>Figure 12 </b>How the job runs if Multi-IF Policy is OR</span><br><span><img id="dataartsstudio_01_0583__image1965743615310" src="en-us_image_0000002234237268.png" title="Click to enlarge" class="imgResize"></span></div>
<p id="dataartsstudio_01_0583__p1420714473422">If <a href="#dataartsstudio_01_0583__li1065634413613">Multi-IF Policy</a> is set to <strong id="dataartsstudio_01_0583__b1216564112113">AND</strong>, the <strong id="dataartsstudio_01_0583__b6181154642117">showtables</strong> node is skipped and the job execution is complete.</p>
<div class="fignone" id="dataartsstudio_01_0583__fig1914818084419"><span class="figcap"><b>Figure 13 </b>How the job runs if Multi-IF Policy is AND</span><br><span><img id="dataartsstudio_01_0583__image20695989230" src="en-us_image_0000002234077444.png" title="Click to enlarge" class="imgResize"></span></div>
</p></li></ol>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="dataartsstudio_01_0520.html">Usage Guidance</a></div>
</div>
</div>
<script language="JavaScript">
<!--
initImageViewer('.imgResize');
var msg_imageMax = "view original image";
var msg_imageClose = "close";
//--></script>