cloud-fan commented on code in PR #38713: URL: https://github.com/apache/spark/pull/38713#discussion_r1027630891
########## sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala: ########## @@ -1263,60 +1263,71 @@ class AstBuilder extends SqlBaseParserBaseVisitor[AnyRef] with SQLConfHelper wit * }}} */ override def visitRelation(ctx: RelationContext): LogicalPlan = withOrigin(ctx) { - withJoinRelations(plan(ctx.relationPrimary), ctx) + withRelationExtensions(ctx, plan(ctx.relationPrimary)) + } + + private def withRelationExtensions(ctx: RelationContext, query: LogicalPlan): LogicalPlan = { + ctx.relationExtension().asScala.foldLeft(query) { (left, extension) => + if (extension.joinRelation() != null) { + withJoinRelation(extension.joinRelation(), left) + } else if (extension.pivotClause() != null) { + withPivot(extension.pivotClause(), left) + } else { + assert(extension.unpivotClause() != null) + withUnpivot(extension.unpivotClause(), left) + } + } } /** - * Join one more [[LogicalPlan]]s to the current logical plan. + * Join one more [[LogicalPlan]] to the current logical plan. */ - private def withJoinRelations(base: LogicalPlan, ctx: RelationContext): LogicalPlan = { - ctx.joinRelation.asScala.foldLeft(base) { (left, join) => Review Comment: The actually code change is very small, just remove this loop and rename a few variables. ########## sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala: ########## @@ -1263,60 +1263,71 @@ class AstBuilder extends SqlBaseParserBaseVisitor[AnyRef] with SQLConfHelper wit * }}} */ override def visitRelation(ctx: RelationContext): LogicalPlan = withOrigin(ctx) { - withJoinRelations(plan(ctx.relationPrimary), ctx) + withRelationExtensions(ctx, plan(ctx.relationPrimary)) + } + + private def withRelationExtensions(ctx: RelationContext, query: LogicalPlan): LogicalPlan = { + ctx.relationExtension().asScala.foldLeft(query) { (left, extension) => + if (extension.joinRelation() != null) { + withJoinRelation(extension.joinRelation(), left) + } else if (extension.pivotClause() != null) { + withPivot(extension.pivotClause(), left) + } else { + assert(extension.unpivotClause() != null) + withUnpivot(extension.unpivotClause(), left) + } + } } /** - * Join one more [[LogicalPlan]]s to the current logical plan. + * Join one more [[LogicalPlan]] to the current logical plan. */ - private def withJoinRelations(base: LogicalPlan, ctx: RelationContext): LogicalPlan = { - ctx.joinRelation.asScala.foldLeft(base) { (left, join) => Review Comment: The actual code change is very small, just remove this loop and rename a few variables. -- 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: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org