pan3793 commented on code in PR #52619:
URL: https://github.com/apache/spark/pull/52619#discussion_r2440375267


##########
sql/connect/client/jdbc/src/main/scala/org/apache/spark/sql/connect/client/jdbc/NonRegisteringSparkConnectDriver.scala:
##########
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.connect.client.jdbc
+
+import java.sql.{Connection, Driver, DriverPropertyInfo, 
SQLFeatureNotSupportedException}
+import java.util.Properties
+import java.util.logging.Logger
+
+import org.apache.spark.SparkBuildInfo.{spark_version => SPARK_VERSION}
+import org.apache.spark.util.VersionUtils
+
+class NonRegisteringSparkConnectDriver extends Driver {

Review Comment:
   Another reason that I lean towards using Scala for implementation - while 
implementing the `java.sql.DatabaseMetaData`, I found it's better to use Spark 
DataFrame API, and Scala is simpler than Java in this case.
   
   Take [`ResultSet getSchemas() throws 
SQLException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.sql/java/sql/DatabaseMetaData.html#getSchemas())
 as example
   ```java
      /**
        * Retrieves the schema names available in this database.  The results
        * are ordered by {@code TABLE_CATALOG} and
        * {@code TABLE_SCHEM}.
        *
        * <P>The schema columns are:
        *  <OL>
        *  <LI><B>TABLE_SCHEM</B> String {@code =>} schema name
        *  <LI><B>TABLE_CATALOG</B> String {@code =>} catalog name (may be 
{@code null})
        *  </OL>
        *
        * @return a {@code ResultSet} object in which each row is a
        *         schema description
        * @throws SQLException if a database access error occurs
        *
        */
       ResultSet getSchemas() throws SQLException;
   ```
   
   Due to the limitations of Spark SQL, I can not write SQL like 
   ```
   WITH r AS (SHOW CATALOGS)
   SELECT catalog AS TABLE_CATALOG FROM r;
   
   ( WITH r AS (SHOW SCHEMAS IN `catalog_1`)
     SELECT 'catalog_1' AS TABLE_CATALOG, namespace AS TABLE_CATALOG FROM r)
   ...
   UNION ALL
   ...
   UNION ALL (
     WITH r AS (SHOW SCHEMAS IN `catalog_N`)
     SELECT 'catalog_N' AS TABLE_CATALOG, namespace AS TABLE_CATALOG FROM r);
   ```
   
   So it's better to use the DataFrame API, e.g.
   ```scala
     override def getSchemas: ResultSet = {
       conn.checkOpen()
   
       val emptyDf = spark.emptyDataFrame
         .withColumn("TABLE_CATALOG", lit(""))
         .withColumn("TABLE_SCHEM", lit(""))
   
       val df = spark.catalog.listCatalogs().collect().map(_.name)
         .map { catalog =>
           spark.sql(s"SHOW SCHEMAS IN `$catalog`")
             .toDF("TABLE_SCHEM")
             .withColumn("TABLE_CATALOG", lit(catalog))
             .select("TABLE_CATALOG", "TABLE_SCHEM")
         }.fold(emptyDf) { (l, r) => l.unionAll(r) }
           .orderBy("TABLE_CATALOG", "TABLE_SCHEM")
   
       new SparkConnectQueryResultSet(df.collectResult())
     }
   ```
   
   Note, Thrift Server introduces a dedicated RPC Req/Resp for such cases, it 
looks too overkill to me for Connect Server.
   
   @zhengruifeng @LuciferYang I lean towards keeping in Scala unless you 
strongly discourage. Can you elaborate more on why you suggest writing it in 
Java? 



-- 
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]

Reply via email to