dongjoon-hyun commented on PR #60771:
URL: https://github.com/apache/spark/pull/60771#issuecomment-7058887749

   Thank you for the review. I checked the findings with a temporary suite (not 
included) on the head of this PR and on its base, 03a2b318c4f, in ANSI mode 
with whole-stage codegen on and off:
   
   - The `EXCEPT` returns no rows instead of `(4, 2, 0)`, so it was a wrong 
result of this PR.
   - The stacked filters over a two-input inner join fail with 
`DIVIDE_BY_ZERO`, where the base returns no rows.
   - With the lower condition NULL inside an inner join, both the head and the 
base fail, with two and three inputs.
   
   I also confirmed the lookup join, the merged bloom filter, the per-partition 
placeholder and the column pruning of the `PhysicalOperation` consumers by 
reading the code.
   
   All of these came from keeping the conjuncts that can fail in a separate 
filter, which rules that rely on `CombineFilters` combining adjacent filters do 
not expect. So I changed the approach in 30b883423d4. `CombineFilters` combines 
the filters into one again, as before, and puts the outer conjuncts that can 
fail under `If(<inner condition>, <them>, false)` when the inner condition can 
be NULL. The `If` evaluates them only where the inner condition is TRUE, 
wherever a later rule moves it, and the inner condition stays a top-level 
conjunct. `CombineFilters` removes the `If` once the conjuncts before it make 
its condition TRUE and can not be NULL, e.g. after 
`InferFiltersFromConstraints` adds `IS NOT NULL` checks, or once it holds 
conjuncts that can not fail. The `OperationHelper` change is reverted.
   
   On the findings:
   
   1. **EXCEPT (P1):** `ReplaceExceptWithFilter` gets one filter again, so the 
query returns `(4, 2, 0)`, as on the base.
   2. **Two-input inner join (P1):** the stacked filters are combined before 
they are pushed, as on the base, so the query returns no rows.
   3. **Lower condition in an inner join (P2):** with two inputs, the `If` goes 
into the join condition, so the query now returns no rows. I added a 
`DataFrameSuite` test. With three inputs, `ReorderJoin` flattens the filter 
between the joins and the condition above them into one join condition, so it 
still fails, as on the base. I will file a separate JIRA issue for it.
   4. **External lookup join (P2):** it gets one filter again, as on the base.
   5. **Runtime filters (P2):** `canFail` now looks only at the key of a merged 
bloom filter, `GetStructField(ScalarSubquery(...), i)`, and of the 
per-partition placeholder too. A new `FilterPushdownSuite` test covers each 
kind.
   6. **Conservative check (P3):** the Scaladoc of `canFail` now says that it 
also rejects many expressions that can not fail in fact. The JDBC example in 
the description now says what is pushed down.
   7. **Untested decisions (P3):** the alias substitution in `canCombine` is 
gone with the reverted change. `FilterPushdownSuite` now checks that 
`coalesce(c, b) IS NOT NULL` does not make `c = 1 OR b = 2` not NULL.
   
   On the decision challenges:
   
   - **Column pruning:** the `PhysicalOperation` consumers see one filter 
again, so they prune columns as before.
   - **Rollback flag:** the filters stay combined, so a plan changes only where 
a conjunct that can fail is over a condition that can still be NULL after the 
inferred `IS NOT NULL` checks. Among the TPC-DS plans, only the filter 
condition of q39b changes, in the same plan. So I did not add a flag or a 
migration guide entry.
   
   `canFail` also counts constant parts as what they fold to. Without that, 
`d_moy = 1 + 1` in q39a and `d_year = 2002 - 1` in q75, which can overflow in 
ANSI mode before `ConstantFolding` runs, went under an `If`, and no longer 
reached the scans below an aggregate or a join.
   
   I updated the PR description.
   


-- 
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]

Reply via email to