yeshengm commented on a change in pull request #24809: [SPARK-21136][SQL] Fix
confusing parsing error due to problematic antlr grammer for Hive-style
single-from statements
URL: https://github.com/apache/spark/pull/24809#discussion_r291374119
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
##########
@@ -403,140 +420,177 @@ class AstBuilder(conf: SQLConf) extends
SqlBaseBaseVisitor[AnyRef] with Logging
throw new ParseException("DISTRIBUTE BY is not supported", ctx)
}
- /**
- * Create a logical plan using a query specification.
- */
- override def visitQuerySpecification(
- ctx: QuerySpecificationContext): LogicalPlan = withOrigin(ctx) {
+ override def visitTransformQuerySpecification(
+ ctx: TransformQuerySpecificationContext): LogicalPlan = withOrigin(ctx) {
val from = OneRowRelation().optional(ctx.fromClause) {
visitFromClause(ctx.fromClause)
}
- withQuerySpecification(ctx, from)
+ withTransformQuerySpecification(ctx, ctx.transformClause, ctx.whereClause,
from)
}
- /**
- * Add a query specification to a logical plan. The query specification is
the core of the logical
- * plan, this is where sourcing (FROM clause), transforming (SELECT
TRANSFORM/MAP/REDUCE),
- * projection (SELECT), aggregation (GROUP BY ... HAVING ...) and filtering
(WHERE) takes place.
- *
- * Note that query hints are ignored (both by the parser and the builder).
- */
- private def withQuerySpecification(
- ctx: QuerySpecificationContext,
- relation: LogicalPlan): LogicalPlan = withOrigin(ctx) {
- import ctx._
-
- // WHERE
- def filter(ctx: BooleanExpressionContext, plan: LogicalPlan): LogicalPlan
= {
- Filter(expression(ctx), plan)
- }
-
- def withHaving(ctx: BooleanExpressionContext, plan: LogicalPlan):
LogicalPlan = {
- // Note that we add a cast to non-predicate expressions. If the
expression itself is
- // already boolean, the optimizer will get rid of the unnecessary cast.
- val predicate = expression(ctx) match {
- case p: Predicate => p
- case e => Cast(e, BooleanType)
- }
- Filter(predicate, plan)
+ override def visitRegularQuerySpecification(
+ ctx: RegularQuerySpecificationContext): LogicalPlan = withOrigin(ctx) {
+ val from = OneRowRelation().optional(ctx.fromClause) {
+ visitFromClause(ctx.fromClause)
}
+ withSelectQuerySpecification(
+ ctx,
+ ctx.selectClause,
+ ctx.lateralView,
+ ctx.whereClause,
+ ctx.aggregationClause,
+ ctx.havingClause,
+ ctx.windowClause,
+ from
+ )
+ }
-
- // Expressions.
- val expressions = Option(namedExpressionSeq).toSeq
+ override def visitNamedExpressionSeq(
Review comment:
Make these functions class methods since they are now reused in several
other places.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]