You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "cloud-fan (via GitHub)" <gi...@apache.org> on 2023/01/30 02:46:39 UTC
[GitHub] [spark] cloud-fan commented on a diff in pull request #39660: [SPARK-42128][SQL] Support TOP (N) for MS SQL Server dialect as an alternative to Limit pushdown
cloud-fan commented on code in PR #39660:
URL: https://github.com/apache/spark/pull/39660#discussion_r1090131480
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JDBCRDD.scala:
##########
@@ -307,11 +307,12 @@ private[jdbc] class JDBCRDD(
""
}
+ val myTopExpression: String = dialect.getTopExpression(limit) // SQL Server Limit alternative
val myLimitClause: String = dialect.getLimitClause(limit)
val myOffsetClause: String = dialect.getOffsetClause(offset)
val sqlText = options.prepareQuery +
- s"SELECT $columnList FROM ${options.tableOrQuery} $myTableSampleClause" +
+ s"SELECT $myTopExpression $columnList FROM ${options.tableOrQuery} $myTableSampleClause" +
Review Comment:
It's hard to define a SQL template that works for all dialects. The approach we take is to try to make it a superset of all dialects.
A better design is to let the dialect build the SQL. For example, we can add a new API in `JdbcDialect`
```
def getSQLBuilder: SQLQueryBuilder = ... the default implementation builds the SQL in a standard way.
```
Then Spark gets the builder and do
```
val builder = ...
builder.withColumns(...).withFromRelation(...).withLimit(...)...build()
```
SQLServerDialect can put the limit before the column list.
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org