dongjoon-hyun commented on code in PR #60631:
URL: https://github.com/apache/spark/pull/60631#discussion_r4607821832


##########
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:
   Thanks. I added `i > a`, which reads both a column that can fail and one 
that can not, and the expected plan keeps it above (dbf22075c08). The test now 
fails if the check becomes `subsetOf`.



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