pan3793 commented on code in PR #52757:
URL: https://github.com/apache/spark/pull/52757#discussion_r2476329537
##########
sql/connect/client/jdbc/src/main/scala/org/apache/spark/sql/connect/client/jdbc/SparkConnectDatabaseMetaData.scala:
##########
@@ -76,8 +77,11 @@ class SparkConnectDatabaseMetaData(conn:
SparkConnectConnection) extends Databas
override def getIdentifierQuoteString: String = "`"
- override def getSQLKeywords: String =
- throw new SQLFeatureNotSupportedException
+ override def getSQLKeywords: String = {
+ conn.checkOpen()
+ conn.spark.sql("SELECT keyword FROM sql_keywords()").collect()
+ .map(_.getString(0)).diff(SQL_2003_RESERVED_KEYWORDS).mkString(",")
Review Comment:
@LuciferYang about the performance, I write a simple benchmark, the result
shows your suggestion is a little faster, but given this is not critical path
and the time cost is negligible, I prefer a simple approach here if you don't
mind.
```scala
test("SparkConnectDatabaseMetaData getSQLKeywords benchmark") {
withConnection { conn =>
val sparkKeywords: Array[String] =
conn.asInstanceOf[SparkConnectConnection].spark
.sql("SELECT keyword FROM sql_keywords()").collect()
.map(_.getString(0))
var start = System.nanoTime()
val sql2003KeywordsSet =
SparkConnectDatabaseMetaData.SQL_2003_RESERVED_KEYWORDS.toSet
(1 to 100000).foreach { i =>
sparkKeywords.filterNot(sql2003KeywordsSet.contains).mkString(",")
}
// scalastyle:off println
println(s"filter by testing set contains cost ${System.nanoTime() -
start}ns")
start = System.nanoTime()
(1 to 100000).foreach { i =>
sparkKeywords.diff(SparkConnectDatabaseMetaData.SQL_2003_RESERVED_KEYWORDS).mkString(",")
}
// scalastyle:off println
println(s"diff cost ${System.nanoTime() - start}ns")
}
}
```
```
filter by testing set contains cost 852094417ns
diff cost 1211112125ns
```
--
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]