beliefer commented on code in PR #40359: URL: https://github.com/apache/spark/pull/40359#discussion_r1132181650
########## sql/core/src/main/scala/org/apache/spark/sql/jdbc/OracleDialect.scala: ########## @@ -181,19 +181,35 @@ private case object OracleDialect extends JdbcDialect { if (limit > 0) s"WHERE rownum <= $limit" else "" } + override def getOffsetClause(offset: Integer): String = { + // Oracle doesn't support OFFSET clause. + // We can use rownum > n to skip some rows in the result set. + // Note: rn is an alias of rownum. + if (offset > 0) s"WHERE rn > $offset" else "" + } + class OracleSQLQueryBuilder(dialect: JdbcDialect, options: JDBCOptions) extends JdbcSQLQueryBuilder(dialect, options) { - // TODO[SPARK-42289]: DS V2 pushdown could let JDBC dialect decide to push down offset override def build(): String = { val selectStmt = s"SELECT $columnList FROM ${options.tableOrQuery} $tableSampleClause" + s" $whereClause $groupByClause $orderByClause" - if (limit > 0) { - val limitClause = dialect.getLimitClause(limit) - options.prepareQuery + s"SELECT tab.* FROM ($selectStmt) tab $limitClause" + val finalSelectStmt = if (limit > 0) { + if (offset > 0) { + s"SELECT $columnList FROM (SELECT tab.*, rownum rn FROM ($selectStmt) tab)" + Review Comment: Maybe it is a bug of Oracle. If we using rownum directly, the result will incorrect. -- 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