LuciferYang commented on code in PR #60387:
URL: https://github.com/apache/spark/pull/60387#discussion_r4573098282
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/InjectRuntimeFilter.scala:
##########
@@ -244,6 +245,18 @@ object InjectRuntimeFilter extends Rule[LogicalPlan] with
PredicateHelper with J
targetKey,
currentPlan,
useMaterializedThreshold = false))
+ // A DSv2 scan can take a filter in fully and leave no `Filter` for it,
as a built-in file
+ // scan does with its partition filters. With no selective `Filter`
above the scan, its
+ // pushed filters count as such a `Filter` would, but only for a scan
whose pushed operations
+ // all work on each row by itself, since the bloom filter's subquery
reads it again. A pushed
+ // limit, for example, lets the source pick other rows on a second read.
+ case scan: DataSourceV2ScanRelation if scan.onlyRowWisePushdowns &&
+ scan.pushedFilters.forall(isSimpleExpression) &&
+ scan.pushedFilters.exists(isLikelySelective) =>
Review Comment:
Done in 04f8a85e9ce. `DataSourceV2ScanRelation.hasSelectivePushedFilters`
holds the check, and `PartitionPruning.hasSelectivePredicate` and this rule
both call it.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/InjectRuntimeFilter.scala:
##########
@@ -244,6 +245,18 @@ object InjectRuntimeFilter extends Rule[LogicalPlan] with
PredicateHelper with J
targetKey,
currentPlan,
useMaterializedThreshold = false))
+ // A DSv2 scan can take a filter in fully and leave no `Filter` for it,
as a built-in file
Review Comment:
I agree a leaf-level notion is the better long-term shape. For now
04f8a85e9ce keeps one definition on `DataSourceV2ScanRelation`, which both
rules call. Turning `pushedFilters` into `validConstraints` changes which
filters `InferFiltersFromConstraints` adds or removes, as its TODO says, so I'd
leave that to its own change.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/InjectRuntimeFilter.scala:
##########
@@ -244,6 +245,18 @@ object InjectRuntimeFilter extends Rule[LogicalPlan] with
PredicateHelper with J
targetKey,
currentPlan,
useMaterializedThreshold = false))
+ // A DSv2 scan can take a filter in fully and leave no `Filter` for it,
as a built-in file
+ // scan does with its partition filters. With no selective `Filter`
above the scan, its
+ // pushed filters count as such a `Filter` would, but only for a scan
whose pushed operations
+ // all work on each row by itself, since the bloom filter's subquery
reads it again. A pushed
+ // limit, for example, lets the source pick other rows on a second read.
+ case scan: DataSourceV2ScanRelation if scan.onlyRowWisePushdowns &&
+ scan.pushedFilters.forall(isSimpleExpression) &&
+ scan.pushedFilters.exists(isLikelySelective) =>
+ Some(FilterCreationSide(
Review Comment:
Done in 04f8a85e9ce. The two cases are now one `case leaf: LeafNode`, taken
under a selective `Filter` or with selective pushed filters
(`hasSelectivePushedFilters`), after the case that rules out an unsafe DSv2
scan.
--
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]