cloud-fan commented on code in PR #47462:
URL: https://github.com/apache/spark/pull/47462#discussion_r1713142010
##########
sql/core/src/main/scala/org/apache/spark/sql/scripting/SqlScriptingExecutionNode.scala:
##########
@@ -260,3 +260,58 @@ class IfElseStatementExec(
elseBody.foreach(b => b.reset())
}
}
+
+/**
+ * Executable node for WhileStatement.
+ * @param condition Executable node for the condition.
+ * @param body Executable node for the body.
+ * @param session Spark session that SQL script is executed within.
+ */
+class WhileStatementExec(
+ condition: SingleStatementExec,
+ body: CompoundBodyExec,
+ session: SparkSession) extends NonLeafStatementExec {
+
+ private object WhileState extends Enumeration {
+ val Condition, Body = Value
+ }
+
+ private var state = WhileState.Condition
+ private var curr: Option[CompoundStatementExec] = Some(condition)
+
+ private lazy val treeIterator: Iterator[CompoundStatementExec] =
+ new Iterator[CompoundStatementExec] {
+ override def hasNext: Boolean = curr.nonEmpty
+
+ override def next(): CompoundStatementExec = state match {
+ case WhileState.Condition =>
+ assert(curr.get.isInstanceOf[SingleStatementExec])
+ val condition = curr.get.asInstanceOf[SingleStatementExec]
+ if (evaluateBooleanCondition(session, condition)) {
+ state = WhileState.Body
+ curr = Some(body)
+ body.reset()
+ } else {
+ curr = None
+ }
+ condition
Review Comment:
I think the while condition should not be part of the final result set, how
should the execution layer exclude this statement?
--
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]