Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
dilipbiswal committed Apr 2, 2019
1 parent f664d1c commit bbab4c1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -377,25 +377,22 @@ trait CheckAnalysis extends PredicateHelper {
"Internal error: logical hint operator should have been removed during analysis")

case f @ Filter(condition, _)
if PlanHelper.specialExpressionInUnsupportedOperator(f).nonEmpty =>
val invalidExprSqls = PlanHelper.specialExpressionInUnsupportedOperator(f).map(_.sql)
if PlanHelper.specialExpressionsInUnsupportedOperator(f).nonEmpty =>
val invalidExprSqls = PlanHelper.specialExpressionsInUnsupportedOperator(f).map(_.sql)
failAnalysis(
s"""
|Aggregate/Window/Generate expressions are not valid in where clause of the query.
|Expression in where clause: [${condition.sql}]
|Invalid expressions: [${invalidExprSqls.mkString(", ")}]
""".stripMargin)
|Invalid expressions: [${invalidExprSqls.mkString(", ")}]""".stripMargin)

case other if PlanHelper.specialExpressionInUnsupportedOperator(other).nonEmpty =>
case other if PlanHelper.specialExpressionsInUnsupportedOperator(other).nonEmpty =>
val invalidExprSqls =
PlanHelper.specialExpressionInUnsupportedOperator(other).map(_.sql)
PlanHelper.specialExpressionsInUnsupportedOperator(other).map(_.sql)
failAnalysis(
s"""
|The query operator `${other.nodeName}` contains one or more unsupported
|expression types Aggregate, Window or Generate.
|Invalid expressions: [${invalidExprSqls.mkString(", ")}]
|
""".stripMargin
|Invalid expressions: [${invalidExprSqls.mkString(", ")}]""".stripMargin
)

case _ => // Analysis successful!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ abstract class Optimizer(sessionCatalog: SessionCatalog)
// - only host special expressions in supported operators
override protected def isPlanIntegral(plan: LogicalPlan): Boolean = {
!Utils.isTesting || (plan.resolved &&
plan.find(PlanHelper.specialExpressionInUnsupportedOperator(_).nonEmpty).isEmpty)
plan.find(PlanHelper.specialExpressionsInUnsupportedOperator(_).nonEmpty).isEmpty)
}

protected def fixedPoint = FixedPoint(SQLConf.get.optimizerMaxIterations)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ object PlanHelper {
* Example : SELECT * FROM tab WHERE max(c1) > 0
* 2. Query rewrites inadvertently produce plans that are invalid.
*/
def specialExpressionInUnsupportedOperator(plan: LogicalPlan): Seq[Expression] = {
def specialExpressionsInUnsupportedOperator(plan: LogicalPlan): Seq[Expression] = {
val exprs = plan.expressions
val invalidExpressions = exprs.flatMap { root =>
root.collect {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,7 @@ org.apache.spark.sql.AnalysisException

Aggregate/Window/Generate expressions are not valid in where clause of the query.
Expression in where clause: [(count(1) > 1L)]
Invalid expressions: [count(1)]
;
Invalid expressions: [count(1)];


-- !query 50
Expand All @@ -509,8 +508,7 @@ org.apache.spark.sql.AnalysisException

Aggregate/Window/Generate expressions are not valid in where clause of the query.
Expression in where clause: [((count(1) + 1L) > 1L)]
Invalid expressions: [count(1)]
;
Invalid expressions: [count(1)];


-- !query 51
Expand All @@ -522,5 +520,4 @@ org.apache.spark.sql.AnalysisException

Aggregate/Window/Generate expressions are not valid in where clause of the query.
Expression in where clause: [(((test_agg.`k` = 1) OR (test_agg.`k` = 2)) OR (((count(1) + 1L) > 1L) OR (max(test_agg.`k`) > 1)))]
Invalid expressions: [count(1), max(test_agg.`k`)]
;
Invalid expressions: [count(1), max(test_agg.`k`)];

0 comments on commit bbab4c1

Please sign in to comment.