huaxingao commented on a change in pull request #34062:
URL: https://github.com/apache/spark/pull/34062#discussion_r714422369
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/dynamicpruning/PartitionPruning.scala
##########
@@ -201,26 +201,46 @@ object PartitionPruning extends Rule[LogicalPlan] with
PredicateHelper with Join
}
/**
- * Returns whether an expression is likely to be selective
+ * Returns whether an expression is likely to be selective in dynamic
partition filtering.
+ * 1. the predicate is selective.
+ * 2. the filtering predicate must not be subset of join key. In case it is,
key then partition
+ * filter. can be inferred statically in optimization phase, hence return
false.
*/
- private def isLikelySelective(e: Expression): Boolean = e match {
- case Not(expr) => isLikelySelective(expr)
- case And(l, r) => isLikelySelective(l) || isLikelySelective(r)
- case Or(l, r) => isLikelySelective(l) && isLikelySelective(r)
- case _: StringRegexExpression => true
- case _: BinaryComparison => true
- case _: In | _: InSet => true
- case _: StringPredicate => true
- case _: MultiLikeBase => true
- case _ => false
+ private def isLikelySelective(e: Expression, joinKey: Expression): (Boolean,
Boolean) = e match {
+ case Not(expr) => isLikelySelective(expr, joinKey)
+ case And(l, r) =>
+ val (isSelectiveLeft, notSubsetOfJoinKeyLeft) = isLikelySelective(l,
joinKey)
+ val (isSelectiveRight, notSubsetOfJoinKeyRight) = isLikelySelective(r,
joinKey)
+ (isSelectiveLeft || isSelectiveRight, notSubsetOfJoinKeyLeft ||
notSubsetOfJoinKeyRight)
+ case Or(l, r) =>
+ val (isSelectiveLeft, notSubsetOfJoinKeyLeft) = isLikelySelective(l,
joinKey)
+ val (isSelectiveRight, notSubsetOfJoinKeyRight) = isLikelySelective(r,
joinKey)
+ (isSelectiveLeft && isSelectiveRight && (notSubsetOfJoinKeyLeft ||
notSubsetOfJoinKeyRight),
+ notSubsetOfJoinKeyLeft || notSubsetOfJoinKeyRight)
+ case expr: StringRegexExpression => (true, !isSubsetOfJoinKey(expr,
joinKey))
+ case expr: BinaryComparison => (true, !isSubsetOfJoinKey(expr, joinKey))
+ case expr: In => (true, !isSubsetOfJoinKey(expr, joinKey))
+ case expr: InSet => (true, !isSubsetOfJoinKey(expr, joinKey))
+ case expr: StringPredicate => (true, !isSubsetOfJoinKey(expr, joinKey))
+ case expr: MultiLikeBase => (true, !isSubsetOfJoinKey(expr, joinKey))
+ case _ => (false, false)
}
+ private def isSubsetOfJoinKey(e: Expression, joinKey: Expression): Boolean
= {
Review comment:
nit: add an empty line in between of the two methods? Also, is that a
three space indent?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]