rdtr commented on code in PR #59194:
URL: https://github.com/apache/spark/pull/59194#discussion_r4164314051


##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/LimitPushdownSuite.scala:
##########
@@ -335,6 +335,20 @@ class LimitPushdownSuite extends PlanTest {
       GlobalLimit(1, Offset(2, LocalLimit(3, testRelation))).analyze)
   }
 
+  test("SPARK-57125: Push down limit through Offset folds the merged limit") {
+    // LimitPushDown must produce a plannable plan without a later 
ConstantFolding run.
+    object OptimizeOnlyLimitPushDown extends RuleExecutor[LogicalPlan] {
+      val batches = Batch("Limit pushdown", Once, LimitPushDown) :: Nil
+    }
+    comparePlans(
+      
OptimizeOnlyLimitPushDown.execute(testRelation.offset(2).limit(1).analyze),
+      GlobalLimit(1, Offset(2, LocalLimit(3, testRelation))).analyze)
+    comparePlans(
+      OptimizeOnlyLimitPushDown.execute(
+        testRelation.offset(Literal(1) + Literal(1)).limit(1).analyze),
+      GlobalLimit(1, Offset(Literal(1) + Literal(1), LocalLimit(3, 
testRelation))).analyze)

Review Comment:
   Thanks, good catch. I went with narrowing the scope: the comments now say 
only that the merged `LocalLimit` is folded so it can be planned without a 
later `ConstantFolding` run, and I removed the `1 + 1` offset case, since a 
non-literal `OFFSET` or `LIMIT` written by the user still relies on 
`ConstantFolding`, like before.
   
   I also updated `PushProjectionThroughLimitAndOffsetSuite`, which expected 
the unfolded `LocalLimit (15 + 5)`.
   



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