dusantism-db commented on code in PR #47756:
URL: https://github.com/apache/spark/pull/47756#discussion_r1750356265
##########
sql/core/src/main/scala/org/apache/spark/sql/scripting/SqlScriptingExecutionNode.scala:
##########
@@ -405,6 +405,80 @@ class WhileStatementExec(
}
}
+/**
+ * Executable node for RepeatStatement.
+ * @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 RepeatStatementExec(
+ condition: SingleStatementExec,
+ body: CompoundBodyExec,
+ label: Option[String],
+ session: SparkSession) extends NonLeafStatementExec {
+
+ private object RepeatState extends Enumeration {
+ val Condition, Body = Value
+ }
+
+ private var state = RepeatState.Body
+ private var curr: Option[CompoundStatementExec] = Some(body)
+
+ private lazy val treeIterator: Iterator[CompoundStatementExec] =
+ new Iterator[CompoundStatementExec] {
+ override def hasNext: Boolean = curr.nonEmpty
+
+ override def next(): CompoundStatementExec = state match {
+ case RepeatState.Condition =>
+ val condition = curr.get.asInstanceOf[SingleStatementExec]
+ if (!evaluateBooleanCondition(session, condition)) {
+ state = RepeatState.Body
+ curr = Some(body)
+ body.reset()
+ } else {
+ curr = None
+ }
+ condition
+ case RepeatState.Body =>
+ val retStmt = body.getTreeIterator.next()
+
+ retStmt match {
+ case leaveStatementExec: LeaveStatementExec if
!leaveStatementExec.hasBeenMatched =>
+ if (label.contains(leaveStatementExec.label)) {
+ leaveStatementExec.hasBeenMatched = true
+ }
+ curr = None
+ return retStmt
+ case iterStatementExec: IterateStatementExec if
!iterStatementExec.hasBeenMatched =>
+ if (label.contains(iterStatementExec.label)) {
+ iterStatementExec.hasBeenMatched = true
+ }
+ state = RepeatState.Condition
+ curr = Some(condition)
+ condition.reset()
+ return retStmt
+ case _ =>
Review Comment:
This match checks if the returned statement is LEAVE or ITERATE, because in
those cases it should return early. If it's not LEAVE or ITERATE, then the
method will continue normally. Because we only check if we should return early,
we shouldn't throw any error. Similar logic exists in WhileStatementExec.
--
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]