dtenedor commented on code in PR #48794:
URL: https://github.com/apache/spark/pull/48794#discussion_r1851144925
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala:
##########
@@ -369,6 +387,10 @@ class AstBuilder extends DataTypeAstBuilder
if Option(c.beginLabel()).isDefined &&
c.beginLabel().multipartIdentifier().getText.toLowerCase(Locale.ROOT).equals(label)
=> true
+ case c: ForStatementContext
+ if Option(c.beginLabel()).isDefined &&
Review Comment:
you can express it as
```
if Option(c.beginLabel).map { b =>
b.multipartIdentifier().getText...)
}.getOrElse(false)
```
this way you don't have to repeat the name of the field.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala:
##########
@@ -347,6 +349,22 @@ class AstBuilder extends DataTypeAstBuilder
RepeatStatement(condition, body, Some(labelText))
}
+ private def visitForStatementImpl(
+ ctx: ForStatementContext,
Review Comment:
```suggestion
ctx: ForStatementContext,
```
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala:
##########
@@ -347,6 +349,22 @@ class AstBuilder extends DataTypeAstBuilder
RepeatStatement(condition, body, Some(labelText))
}
+ private def visitForStatementImpl(
+ ctx: ForStatementContext,
+ labelCtx: SqlScriptingLabelContext): ForStatement = {
Review Comment:
```suggestion
labelCtx: SqlScriptingLabelContext): ForStatement = {
```
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/SqlScriptingLogicalPlans.scala:
##########
@@ -267,3 +267,35 @@ case class LoopStatement(
LoopStatement(newChildren(0).asInstanceOf[CompoundBody], label)
}
}
+
+/**
+ * Logical operator for FOR statement.
+ * @param query Query which is executed once, then it's result set is iterated
on, row by row.
+ * @param variableName Name of variable which is used to access the current
row during iteration.
+ * @param body Compound body is a collection of statements that are executed
for each row in
+ * the result set of the query.
+ * @param label An optional label for the loop which is unique amongst all
labels for statements
+ * within which the FOR statement is contained.
+ * If an end label is specified it must match the beginning label.
+ * The label can be used to LEAVE or ITERATE the loop.
+ */
+case class ForStatement(
+ query: SingleStatement,
+ variableName: Option[String],
+ body: CompoundBody,
+ label: Option[String]) extends CompoundPlanStatement {
+
+ override def output: Seq[Attribute] = Seq.empty
+
+ override def children: Seq[LogicalPlan] = Seq(query, body)
+
+ override protected def withNewChildrenInternal(
+ newChildren: IndexedSeq[LogicalPlan]): LogicalPlan = {
+ assert(newChildren.length == 2)
Review Comment:
you can pattern-match the two children:
```
newChildren match {
case (s: SingleStatement, c: CompoundBody) =>
ForStatement(s, variableName, c, label)
}
```
--
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]