davidm-db commented on code in PR #47442:
URL: https://github.com/apache/spark/pull/47442#discussion_r1688267605


##########
sql/core/src/main/scala/org/apache/spark/sql/scripting/SqlScriptingExecutionNode.scala:
##########
@@ -155,3 +157,98 @@ abstract class 
CompoundNestedStatementIteratorExec(collection: Seq[CompoundState
  */
 class CompoundBodyExec(statements: Seq[CompoundStatementExec])
   extends CompoundNestedStatementIteratorExec(statements)
+
+/**
+ * Executable node for IfElseStatement.
+ * @param conditions Collection of executable conditions. First condition 
corresponds to IF clause,
+ *                   while others (if any) correspond to following ELSE IF 
clauses.
+ * @param bodies  Collection of executable bodies.
+ * @param booleanEvaluator Evaluator for Boolean conditions.
+ */
+class IfElseStatementExec(
+    conditions: Seq[SingleStatementExec],
+    bodies: Seq[CompoundBodyExec],
+    booleanEvaluator: StatementBooleanEvaluator) extends NonLeafStatementExec {
+  private object IfElseState extends Enumeration {
+    val Condition, Body = Value
+  }
+
+  private var state = IfElseState.Condition
+  private var curr: Option[CompoundStatementExec] = Some(conditions.head)
+
+  private var clauseIdx: Int = 0
+  private val conditionsCount: Int = conditions.length
+  private val bodiesCount: Int = bodies.length
+  assert(conditionsCount == bodiesCount || conditionsCount + 1 == bodiesCount)
+
+  private lazy val treeIterator: Iterator[CompoundStatementExec] =

Review Comment:
   Not sure what exactly do you mean - do you think from implementation or user 
perspective?
   
   What I mentioned in the comment above is nothing visible from the user 
perspective because they cannot explicitly drive the interpreter execution. For 
more details, you can check the execution PR linked in the previous comment - 
`SqlScriptingInterpreter` will have `execute()` function, in which we determine 
whether or not we are collecting results for specific statement. This is where 
we decide not to take results from conditions.
   This PR also sorts out the naming, so `isExecuted` flag that we use here 
will be changed to more meaningful `shouldCollectResults` flag.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to