LuciferYang commented on code in PR #60672:
URL: https://github.com/apache/spark/pull/60672#discussion_r4631218995
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/V2ScanRelationPushDown.scala:
##########
@@ -931,7 +944,8 @@ object V2ScanRelationPushDown extends Rule[LogicalPlan]
with PredicateHelper {
// changes to aggregate columns. When validConstraints is wired up, this
needs revisiting.
// A pushed aggregate cannot be reproduced by rebuilding the scan, so
this scan stays
// not-mergeable (the default `mergeableScan = false`).
- val scanRelation = DataSourceV2ScanRelation(holder.relation,
wrappedScan, realOutput)
+ val scanRelation = DataSourceV2ScanRelation(holder.relation,
wrappedScan, realOutput,
+ repeatableRead = !hasRowSelectingPushdown(holder))
Review Comment:
Done in c53bf5b49cf. The aggregate build site sets `repeatableRead` only if
every pushed group-by expression and aggregate function is deterministic, and
for a `V2Aggregator` it also checks `BoundFunction.isDeterministic()`, which
its `deterministic` ignores. The new `JDBCV2Suite` test pushes `my_avg` and the
same function marked non-deterministic, and only the first scan is repeatable.
Skipping the pushdown itself would change which aggregates sources get, so I
left `rewriteAggregate` as it is.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/InjectRuntimeFilter.scala:
##########
@@ -431,8 +435,9 @@ object InjectRuntimeFilter extends Rule[LogicalPlan] with
PredicateHelper with J
// plan it reads must give the same rows again (SPARK-60808). So it must
read no CTE, whose
// reference hides the determinism of its plan, a cache only if Spark can
tell that scanning it
// again gives the same rows, and a V2 scan only if every operation pushed
into it works on each
- // row by itself. A pushed limit or top-N, for example, lets the source pick
other rows on a
- // second read. It must not read a file metadata column either, such as
+ // row by itself. `extract` already drops a V2 scan that is not
`repeatableRead`, so this keeps
Review Comment:
There is no other reason in this PR, so the comment now says that this check
is stricter than `extract` and what that costs: a scan with a pushed aggregate
or join, or a copy-on-write target read, gives no bloom filter for a key whose
DPP filters are all dropped. Results stay the same. I'd keep this fix to the
wrong results and switch the check in #60387. There `canEvaluateAgain` also
checks the scan's `pushedFilters` with `cannotFail`, and only the plain and
variant builds record them, so the switch needs that part settled too.
`injectPerPartitionBloomFilter` can switch with it.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/execution/datasources/v2/DataSourceV2Relation.scala:
##########
@@ -269,7 +277,13 @@ case class DataSourceV2ScanRelation(
pushedFilters: Seq[Expression] = Seq.empty,
inferredFilters: Seq[Expression] = Seq.empty,
mergeableScan: Boolean = false,
- onlyRowWisePushdowns: Boolean = false) extends LeafNode with NamedRelation
{
+ onlyRowWisePushdowns: Boolean = false,
+ repeatableRead: Boolean = false) extends LeafNode with NamedRelation {
+
+ // A scan whose pushed operations all work on each row by itself returns the
same rows when read
+ // again, so DPP and the runtime bloom filter, which read different flags,
agree on it.
Review Comment:
I'd leave `PartitionPruning` to a separate change. With the defaults,
`spark.sql.exchange.reuse` and
`spark.sql.optimizer.dynamicPartitionPruning.reuseBroadcastOnly` both true,
`hasBenefit` is never evaluated (`PartitionPruning.scala` L126 and L134), so
the flag it reads matters only when one of the two is off.
`hasSelectivePredicate` (L261) runs with the defaults, but a scan with a pushed
aggregate or join, or a copy-on-write target read, records no `pushedFilters`,
so switching it would change nothing. With item 4 the plain build no longer
sets `repeatableRead`, so the `rowWise = false` case in
`DataSourceV2FileSourceDPPSuite` now gives a scan that is not
`isRepeatableRead` either. The comment that said the two rules agree is gone
with item 4.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/execution/datasources/v2/DataSourceV2Relation.scala:
##########
@@ -269,7 +277,13 @@ case class DataSourceV2ScanRelation(
pushedFilters: Seq[Expression] = Seq.empty,
inferredFilters: Seq[Expression] = Seq.empty,
mergeableScan: Boolean = false,
- onlyRowWisePushdowns: Boolean = false) extends LeafNode with NamedRelation
{
+ onlyRowWisePushdowns: Boolean = false,
+ repeatableRead: Boolean = false) extends LeafNode with NamedRelation {
+
+ // A scan whose pushed operations all work on each row by itself returns the
same rows when read
+ // again, so DPP and the runtime bloom filter, which read different flags,
agree on it.
+ require(!onlyRowWisePushdowns || repeatableRead,
Review Comment:
Done in c53bf5b49cf. The `require` is gone. `isRepeatableRead` is
`repeatableRead || onlyRowWisePushdowns`, and `extract` reads it, so a row-wise
scan counts without setting the flag. The plain and variant build sites no
longer set `repeatableRead`, and the `MergeSubplansSuite` fixtures are back as
on master.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/execution/datasources/v2/DataSourceV2Relation.scala:
##########
@@ -269,7 +277,13 @@ case class DataSourceV2ScanRelation(
pushedFilters: Seq[Expression] = Seq.empty,
inferredFilters: Seq[Expression] = Seq.empty,
mergeableScan: Boolean = false,
- onlyRowWisePushdowns: Boolean = false) extends LeafNode with NamedRelation
{
+ onlyRowWisePushdowns: Boolean = false,
+ repeatableRead: Boolean = false) extends LeafNode with NamedRelation {
Review Comment:
Yes. Paimon's `PushDownMapSelectedKeys`, for one, rebuilds its scan with the
first five arguments, so it sets neither flag, and such a scan is no longer a
bloom filter's creation side under a selective `Filter`. With item 4, a rule
that marks its scan `onlyRowWisePushdowns` keeps it. I added a line to the SQL
migration guide in c53bf5b49cf.
--
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]