cloud-fan commented on code in PR #36295:
URL: https://github.com/apache/spark/pull/36295#discussion_r903820510


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCScanBuilder.scala:
##########
@@ -139,6 +142,25 @@ case class JDBCScanBuilder(
     false
   }
 
+  override def pushOffset(offset: Int): Boolean = {
+    if (jdbcOptions.pushDownOffset && !isPartiallyPushed) {
+      // Spark pushes down LIMIT first, then OFFSET. In SQL statements, OFFSET 
is applied before
+      // LIMIT. Here we need to adjust the LIMIT value to match SQL statements.
+      // 1. For `dataset.limit(m).offset(n)`, try to push down `LIMIT (m - n) 
OFFSET n`.
+      //    For example, `dataset.limit(5).offset(3)`, we can push down `LIMIT 
2 OFFSET 3`.
+      // 2. For `dataset.offset(n).limit(m)`, try to push down `LIMIT m OFFSET 
n`.
+      //    For example, `dataset.offset(3).limit(5)`, we can push down `LIMIT 
5 OFFSET 3`.
+      // 3. For `dataset.offset(n)`, try to push down `OFFSET n`.

Review Comment:
   I don't think the 1,2,3 comments make sense here. It's about the internal 
details of the spark pushdown rule, and data source shouldn't care about it.



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