LuciferYang commented on code in PR #59217:
URL: https://github.com/apache/spark/pull/59217#discussion_r4206241812


##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/RewriteWithExpressionSuite.scala:
##########
@@ -486,6 +486,53 @@ class RewriteWithExpressionSuite extends PlanTest {
     )
   }
 
+  test("SPARK-59962: a With in a command's condition is inlined instead of 
hoisted") {
+    val a = testRelation.output.head
+    // The condition is translated into source predicates, not evaluated over 
the child's rows, so a
+    // `Project` under the command would sit where the planner expects the 
table.
+    val condition = With(a + a) { case Seq(ref) => ref < 10 && ref > 0 }
+    comparePlans(
+      Optimizer.execute(DeleteFromTable(testRelation, condition)),
+      DeleteFromTable(testRelation, (a + a) < 10 && (a + a) > 0))
+
+    // Nor is one in a conditional branch kept: a `With` translates to no 
source predicate.
+    val inBranch = If(a > 0, With(a + a) { case Seq(ref) => ref < 10 && ref > 
0 }, Literal(false))

Review Comment:
   Done.



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