MaxGekk commented on code in PR #47756:
URL: https://github.com/apache/spark/pull/47756#discussion_r1750178397
##########
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.
Review Comment:
It would be nice if you provide more info about parameters like "... shall
be evaluated to a row with single boolean value otherwise it throws an
exception."
##########
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.
Review Comment:
Please, describe `label` here.
##########
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:
In which cases does this happen? Shall we raise an error here like
unsupported or unexpected statement?
##########
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.
Review Comment:
Is there any contract/restriction for the `body`?
--
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]