beliefer commented on code in PR #36295:
URL: https://github.com/apache/spark/pull/36295#discussion_r904473795


##########
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:
   OK



-- 
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: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to