-
Notifications
You must be signed in to change notification settings - Fork 28.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-21726][SQL] Check for structural integrity of the plan in Opti…
…mzer in test mode. ## What changes were proposed in this pull request? We have many optimization rules now in `Optimzer`. Right now we don't have any checks in the optimizer to check for the structural integrity of the plan (e.g. resolved). When debugging, it is difficult to identify which rules return invalid plans. It would be great if in test mode, we can check whether a plan is still resolved after the execution of each rule, so we can catch rules that return invalid plans. ## How was this patch tested? Added tests. Author: Liang-Chi Hsieh <viirya@gmail.com> Closes #18956 from viirya/SPARK-21726.
- Loading branch information
1 parent
f62b20f
commit 6e37524
Showing
5 changed files
with
103 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...la/org/apache/spark/sql/catalyst/optimizer/OptimizerStructuralIntegrityCheckerSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.spark.sql.catalyst.optimizer | ||
|
||
import org.apache.spark.sql.catalyst.analysis.{EmptyFunctionRegistry, UnresolvedAttribute} | ||
import org.apache.spark.sql.catalyst.catalog.{InMemoryCatalog, SessionCatalog} | ||
import org.apache.spark.sql.catalyst.dsl.plans._ | ||
import org.apache.spark.sql.catalyst.errors.TreeNodeException | ||
import org.apache.spark.sql.catalyst.expressions.{Alias, Literal} | ||
import org.apache.spark.sql.catalyst.plans.PlanTest | ||
import org.apache.spark.sql.catalyst.plans.logical.{LogicalPlan, OneRowRelation, Project} | ||
import org.apache.spark.sql.catalyst.rules._ | ||
import org.apache.spark.sql.internal.SQLConf | ||
|
||
|
||
class OptimizerStructuralIntegrityCheckerSuite extends PlanTest { | ||
|
||
object OptimizeRuleBreakSI extends Rule[LogicalPlan] { | ||
def apply(plan: LogicalPlan): LogicalPlan = plan transform { | ||
case Project(projectList, child) => | ||
val newAttr = UnresolvedAttribute("unresolvedAttr") | ||
Project(projectList ++ Seq(newAttr), child) | ||
} | ||
} | ||
|
||
object Optimize extends Optimizer( | ||
new SessionCatalog( | ||
new InMemoryCatalog, | ||
EmptyFunctionRegistry, | ||
new SQLConf())) { | ||
val newBatch = Batch("OptimizeRuleBreakSI", Once, OptimizeRuleBreakSI) | ||
override def batches: Seq[Batch] = Seq(newBatch) ++ super.batches | ||
} | ||
|
||
test("check for invalid plan after execution of rule") { | ||
val analyzed = Project(Alias(Literal(10), "attr")() :: Nil, OneRowRelation()).analyze | ||
assert(analyzed.resolved) | ||
val message = intercept[TreeNodeException[LogicalPlan]] { | ||
Optimize.execute(analyzed) | ||
}.getMessage | ||
val ruleName = OptimizeRuleBreakSI.ruleName | ||
assert(message.contains(s"After applying rule $ruleName in batch OptimizeRuleBreakSI")) | ||
assert(message.contains("the structural integrity of the plan is broken")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters