sadikovi commented on code in PR #40134:
URL: https://github.com/apache/spark/pull/40134#discussion_r1115208845
##########
sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCSuite.scala:
##########
@@ -1028,6 +1028,19 @@ class JDBCSuite extends QueryTest with
SharedSparkSession {
"SELECT TOP (123) a,b FROM test")
}
+ test("SPARK-42534: DB2Dialect Limit query test") {
+ // JDBC url is a required option but is not used in this test.
+ val options = new JDBCOptions(Map("url" -> "jdbc:db2://host:port",
"dbtable" -> "test"))
+ assert(
+ DB2Dialect
+ .getJdbcSQLQueryBuilder(options)
+ .withColumns(Array("a", "b"))
+ .withLimit(123)
+ .build()
+ .trim() ==
+ "SELECT a,b FROM test FETCH FIRST 123 ROWS ONLY")
Review Comment:
Yes, I do. This is because of the string interpolation for the JDBC query
that is written like `$a $b $c...`. So when some of the components are empty,
whitespaces are still kept between the components resulting in the long gaps.
```scala
options.prepareQuery +
s"SELECT $myTopExpression $columnList FROM ${options.tableOrQuery}
$myTableSampleClause" +
s" $myWhereClause $getGroupByClause $getOrderByClause $myLimitClause
$myOffsetClause"
```
https://github.com/apache/spark/blob/4b50a46f1c6ba4ffe2c42f70a512879c28d11dcf/sql/core/src/main/scala/org/apache/spark/sql/jdbc/JdbcSQLQueryBuilder.scala#L163.
--
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]