Skip to content

Commit

Permalink
[SPARK-21103][SQL] QueryPlanConstraints should be part of LogicalPlan
Browse files Browse the repository at this point in the history
## What changes were proposed in this pull request?
QueryPlanConstraints should be part of LogicalPlan, rather than QueryPlan, since the constraint framework is only used for query plan rewriting and not for physical planning.

## How was this patch tested?
Should be covered by existing tests, since it is a simple refactoring.

Author: Reynold Xin <rxin@databricks.com>

Closes apache#18310 from rxin/SPARK-21103.
  • Loading branch information
rxin authored and Robert Kruszewski committed Jun 29, 2017
1 parent 17eeed7 commit 299645f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
Expand Up @@ -22,10 +22,7 @@ import org.apache.spark.sql.catalyst.trees.TreeNode
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.types.{DataType, StructType}

abstract class QueryPlan[PlanType <: QueryPlan[PlanType]]
extends TreeNode[PlanType]
with QueryPlanConstraints[PlanType] {

abstract class QueryPlan[PlanType <: QueryPlan[PlanType]] extends TreeNode[PlanType] {
self: PlanType =>

def conf: SQLConf = SQLConf.get
Expand Down
Expand Up @@ -27,7 +27,7 @@ import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.types.StructType


abstract class LogicalPlan extends QueryPlan[LogicalPlan] with Logging {
abstract class LogicalPlan extends QueryPlan[LogicalPlan] with QueryPlanConstraints with Logging {

private var _analyzed: Boolean = false

Expand Down
Expand Up @@ -15,12 +15,12 @@
* limitations under the License.
*/

package org.apache.spark.sql.catalyst.plans
package org.apache.spark.sql.catalyst.plans.logical

import org.apache.spark.sql.catalyst.expressions._


trait QueryPlanConstraints[PlanType <: QueryPlan[PlanType]] { self: QueryPlan[PlanType] =>
trait QueryPlanConstraints { self: LogicalPlan =>

/**
* An [[ExpressionSet]] that contains invariants about the rows output by this operator. For
Expand Down Expand Up @@ -99,7 +99,8 @@ trait QueryPlanConstraints[PlanType <: QueryPlan[PlanType]] { self: QueryPlan[Pl
private lazy val aliasMap: AttributeMap[Expression] = AttributeMap(
expressions.collect {
case a: Alias => (a.toAttribute, a.child)
} ++ children.flatMap(_.asInstanceOf[QueryPlanConstraints[PlanType]].aliasMap))
} ++ children.flatMap(_.asInstanceOf[QueryPlanConstraints].aliasMap))
// Note: the explicit cast is necessary, since Scala compiler fails to infer the type.

/**
* Infers an additional set of constraints from a given set of equality constraints.
Expand Down

0 comments on commit 299645f

Please sign in to comment.