forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DPP should considered as selective predicate
- Loading branch information
Showing
15 changed files
with
464 additions
and
69 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
105 changes: 105 additions & 0 deletions
105
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/runtimefilter.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,105 @@ | ||
/* | ||
* 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.expressions | ||
|
||
import org.apache.spark.sql.catalyst.InternalRow | ||
import org.apache.spark.sql.catalyst.expressions.codegen.{CodegenContext, ExprCode} | ||
import org.apache.spark.sql.catalyst.plans.logical.{HintInfo, LogicalPlan} | ||
import org.apache.spark.sql.catalyst.trees.TreePattern.{RUNTIME_FILTER_EXPRESSION, RUNTIME_FILTER_SUBQUERY, TreePattern} | ||
import org.apache.spark.sql.catalyst.trees.UnaryLike | ||
import org.apache.spark.sql.types.{BinaryType, DataType} | ||
|
||
/** | ||
* The RuntimeFilterSubquery expression is only used in runtime filter. It is inserted in cases | ||
* when broadcast exchange can be reused. | ||
* | ||
* @param filterApplicationSideKey the filtering key of the application side. | ||
* @param filterCreationSidePlan the build side of the join. | ||
* @param filterCreationSideKey the key of the creation side. | ||
*/ | ||
case class RuntimeFilterSubquery( | ||
filterApplicationSideKey: Expression, | ||
filterCreationSidePlan: LogicalPlan, | ||
filterCreationSideKey: Expression, | ||
exprId: ExprId = NamedExpression.newExprId, | ||
hint: Option[HintInfo] = None) | ||
extends SubqueryExpression( | ||
filterCreationSidePlan, Seq(filterApplicationSideKey), exprId, Seq.empty, hint) | ||
with Unevaluable | ||
with UnaryLike[Expression] { | ||
|
||
override def child: Expression = filterApplicationSideKey | ||
|
||
override def dataType: DataType = BinaryType | ||
|
||
override def plan: LogicalPlan = filterCreationSidePlan | ||
|
||
override def nullable: Boolean = false | ||
|
||
override def withNewPlan(plan: LogicalPlan): RuntimeFilterSubquery = | ||
copy(filterCreationSidePlan = plan) | ||
|
||
override def withNewOuterAttrs(outerAttrs: Seq[Expression]): RuntimeFilterSubquery = { | ||
// Updating outer attrs of RuntimeFilterSubquery is unsupported; assert that they match | ||
// filterApplicationSideKey and return a copy without any changes. | ||
assert(outerAttrs.size == 1 && outerAttrs.head.semanticEquals(filterApplicationSideKey)) | ||
copy() | ||
} | ||
|
||
override def withNewHint(hint: Option[HintInfo]): SubqueryExpression = copy(hint = hint) | ||
|
||
override lazy val resolved: Boolean = | ||
filterApplicationSideKey.resolved && | ||
filterCreationSidePlan.resolved && | ||
filterCreationSideKey.resolved | ||
|
||
final override def nodePatternsInternal(): Seq[TreePattern] = Seq(RUNTIME_FILTER_SUBQUERY) | ||
|
||
override def toString: String = s"runtimefilter#${exprId.id} $conditionString" | ||
|
||
override lazy val canonicalized: RuntimeFilterSubquery = { | ||
copy( | ||
filterApplicationSideKey = filterApplicationSideKey.canonicalized, | ||
filterCreationSidePlan = filterCreationSidePlan.canonicalized, | ||
filterCreationSideKey = filterCreationSideKey.canonicalized, | ||
exprId = ExprId(0)) | ||
} | ||
|
||
override protected def withNewChildInternal(newChild: Expression): RuntimeFilterSubquery = | ||
copy(filterApplicationSideKey = newChild) | ||
} | ||
|
||
/** | ||
* Marker for a planned runtime filter expression. | ||
* The expression is created during planning, and it defers to its child for evaluation. | ||
* | ||
* @param child underlying aggregate for runtime filter. | ||
*/ | ||
case class RuntimeFilterExpression(child: Expression) | ||
extends UnaryExpression { | ||
override def dataType: DataType = child.dataType | ||
override def eval(input: InternalRow): Any = child.eval(input) | ||
final override val nodePatterns: Seq[TreePattern] = Seq(RUNTIME_FILTER_EXPRESSION) | ||
|
||
override protected def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = { | ||
child.genCode(ctx) | ||
} | ||
|
||
override protected def withNewChildInternal(newChild: Expression): RuntimeFilterExpression = | ||
copy(child = newChild) | ||
} |
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
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
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
Oops, something went wrong.