spark-test commented on code in PR #60631:
URL: https://github.com/apache/spark/pull/60631#discussion_r4607715550
##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/FilterPushdownSuite.scala:
##########
@@ -185,6 +185,30 @@ class FilterPushdownSuite extends PlanTest {
}
}
+ test("SPARK-61886: a condition over a column that can fail is not combined
ahead of a " +
+ "non-deterministic one") {
+ // `i` can fail as the cast does, and `j` as it reads `i`, also through
the sample, the
+ // projection and the filter above them. A condition over either stays
above, while one over
+ // the non-deterministic `r`, which is computed on every row, or over `w`,
an alias that can
+ // not fail, is combined.
+ val projected = testStringRelation
+ .select($"a", Cast($"e", IntegerType, evalMode = EvalMode.ANSI).as("i"),
+ Cast($"a", LongType).as("w"), Rand(1).as("r"))
+ .sample(0.0, 0.5, withReplacement = false, 1L)
+ .select($"a", $"i", IsNull($"i").as("j"), $"w", $"r")
+ val originalQuery = projected
+ .where($"a" > 0)
+ .where($"a" > 1)
+ .where(Rand(0) > 0.1 && $"i" > 0 && $"j" && $"w" > 0 && $"r" > 0.5)
+
+ val correctAnswer = projected
+ .where($"a" > 0 && $"a" > 1 && $"w" > 0 && $"r" > 0.5)
+ .where(Rand(0) > 0.1 && $"i" > 0 && $"j")
Review Comment:
**Nit (P3):** Each conjunct this test places after `Rand(0)` reads a single
column, and so does `q > 0` in the new `DataFrameSuite` case, so neither test
would notice if the check in `CombineFilters` changed from "any column it reads
can fail" (`!p.references.exists(failable.contains)`) to "every column it reads
can fail", for example `!p.references.subsetOf(failable)`. With that change, by
this review's reading, a conjunct such as `q > id` in the `DataFrameSuite`
shape would be combined again, pushed below the projection as `10L / (id - 3) >
id`, and fail with `DIVIDE_BY_ZERO` on id 3. A conjunct that reads both a
column that can fail and one that cannot, expected in the upper filter, pins
the rule:
```suggestion
.where(Rand(0) > 0.1 && $"i" > 0 && $"j" && $"i" > $"a" && $"w" > 0 &&
$"r" > 0.5)
val correctAnswer = projected
.where($"a" > 0 && $"a" > 1 && $"w" > 0 && $"r" > 0.5)
.where(Rand(0) > 0.1 && $"i" > 0 && $"j" && $"i" > $"a")
```
**Verification:**
- **Regression:** Changing the check so that it keeps a conjunct above only
when every column the conjunct reads can fail makes the plan test fail, because
the mixed conjunct is then combined into the filter below.
- **Behavior:** With the current check, the plan test expects the mixed
conjunct in the upper filter together with the other conjuncts over columns
that can fail, and still expects the conjuncts over the widening-cast alias and
the non-deterministic column combined into the filter below.
--
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]