Skip to content

Commit

Permalink
style
Browse files Browse the repository at this point in the history
  • Loading branch information
yeshengm committed Jun 6, 2019
1 parent d0bf38d commit aa6bca0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ dmlStatementNoWith
;

queryNoWith
: queryTerm queryOrganization #noWithQuery
: queryTerm queryOrganization
;

queryOrganization
Expand Down Expand Up @@ -446,15 +446,6 @@ querySpecification
windowClause? #regularQuerySpecification
;

hint
: '/*+' hintStatements+=hintStatement (','? hintStatements+=hintStatement)* '*/'
;

hintStatement
: hintName=identifier
| hintName=identifier '(' parameters+=primaryExpression (',' parameters+=primaryExpression)* ')'
;

transformClause
: (SELECT kind=TRANSFORM '(' namedExpressionSeq ')'
| kind=MAP namedExpressionSeq
Expand All @@ -471,10 +462,6 @@ selectClause
: SELECT (hints+=hint)* setQuantifier? namedExpressionSeq
;

fromClause
: FROM relation (',' relation)* lateralView* pivotClause?
;

whereClause
: WHERE booleanExpression
;
Expand All @@ -483,6 +470,19 @@ havingClause
: HAVING booleanExpression
;

hint
: '/*+' hintStatements+=hintStatement (','? hintStatements+=hintStatement)* '*/'
;

hintStatement
: hintName=identifier
| hintName=identifier '(' parameters+=primaryExpression (',' parameters+=primaryExpression)* ')'
;

fromClause
: FROM relation (',' relation)* lateralView* pivotClause?
;

aggregationClause
: GROUP BY groupingExpressions+=expression (',' groupingExpressions+=expression)* (
WITH kind=ROLLUP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,12 @@ class AstBuilder(conf: SQLConf) extends SqlBaseBaseVisitor[AnyRef] with Logging
With(plan, ctes)
}

/**
* Create a logical query plan for a hive-style FROM statement body.
*/
private def withFromStatementBody(
ctx: FromStatementBodyContext, plan: LogicalPlan): LogicalPlan = withOrigin(ctx) {
// two cases for transforms and selects because otherwise we can't get the table
// info before visiting these query bodies
// two cases for transforms and selects
if (ctx.transformClause != null) {
withTransformQuerySpecification(
ctx,
Expand Down Expand Up @@ -173,7 +175,7 @@ class AstBuilder(conf: SQLConf) extends SqlBaseBaseVisitor[AnyRef] with Logging
}
}

override def visitNoWithQuery(ctx: NoWithQueryContext): LogicalPlan = withOrigin(ctx) {
override def visitQueryNoWith(ctx: QueryNoWithContext): LogicalPlan = withOrigin(ctx) {
plan(ctx.queryTerm).optionalMap(ctx.queryOrganization)(withQueryResultClauses)
}

Expand Down Expand Up @@ -209,8 +211,7 @@ class AstBuilder(conf: SQLConf) extends SqlBaseBaseVisitor[AnyRef] with Logging
val inserts = ctx.multiInsertQueryBody.asScala.map { body =>
withInsertInto(body.insertInto,
withFromStatementBody(body.fromStatementBody, from).
// Add organization statements.
optionalMap(body.fromStatementBody.queryOrganization)(withQueryResultClauses))
optionalMap(body.fromStatementBody.queryOrganization)(withQueryResultClauses))
}

// If there are multiple INSERTS just UNION them together into one query.
Expand Down Expand Up @@ -455,7 +456,7 @@ class AstBuilder(conf: SQLConf) extends SqlBaseBaseVisitor[AnyRef] with Logging
* Create a logical plan using a having clause.
*/
private def withHavingClause(
ctx: HavingClauseContext, plan: LogicalPlan): LogicalPlan = {
ctx: HavingClauseContext, 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.booleanExpression) match {
Expand All @@ -476,9 +477,9 @@ class AstBuilder(conf: SQLConf) extends SqlBaseBaseVisitor[AnyRef] with Logging
* Add a hive-style transform (SELECT TRANSFORM/MAP/REDUCE) query specification to a logical plan.
*/
private def withTransformQuerySpecification(
ctx: ParserRuleContext,
transformClause: TransformClauseContext,
whereClause: WhereClauseContext,
ctx: ParserRuleContext,
transformClause: TransformClauseContext,
whereClause: WhereClauseContext,
relation: LogicalPlan): LogicalPlan = withOrigin(ctx) {
// Add where.
val withFilter = relation.optionalMap(whereClause)(withWhereClause)
Expand Down

0 comments on commit aa6bca0

Please sign in to comment.