cloud-fan commented on code in PR #56688:
URL: https://github.com/apache/spark/pull/56688#discussion_r3462830475


##########
sql/connect/client/jdbc/src/main/scala/org/apache/spark/sql/connect/client/jdbc/SparkConnectDatabaseMetaData.scala:
##########
@@ -598,14 +598,54 @@ class SparkConnectDatabaseMetaData(conn: 
SparkConnectConnection) extends Databas
       catalog: String, schema: String, table: String): ResultSet =
     throw new SQLFeatureNotSupportedException
 
-  override def getPrimaryKeys(catalog: String, schema: String, table: String): 
ResultSet =
-    throw new SQLFeatureNotSupportedException
+  // Spark supports informational PRIMARY KEY constraints on DSv2 tables 
(SPARK-51207), but the
+  // Spark Connect JDBC client cannot retrieve them in a structured way yet, 
so return an empty
+  // result set instead of throwing. JDBC clients call this during schema 
introspection.
+  override def getPrimaryKeys(catalog: String, schema: String, table: String): 
ResultSet = {
+    conn.checkOpen()
 
-  override def getImportedKeys(catalog: String, schema: String, table: 
String): ResultSet =
-    throw new SQLFeatureNotSupportedException
+    val df = conn.spark.emptyDataFrame
+      .withColumn("TABLE_CAT", lit(""))
+      .withColumn("TABLE_SCHEM", lit(""))
+      .withColumn("TABLE_NAME", lit(""))
+      .withColumn("COLUMN_NAME", lit(""))
+      .withColumn("KEY_SEQ", lit(0.toShort))
+      .withColumn("PK_NAME", lit(""))
+    new SparkConnectResultSet(df.collectResult())
+  }
 
-  override def getExportedKeys(catalog: String, schema: String, table: 
String): ResultSet =
-    throw new SQLFeatureNotSupportedException
+  // getImportedKeys and getExportedKeys share the JDBC foreign-key result 
schema. Spark supports
+  // informational FOREIGN KEY constraints on DSv2 tables (SPARK-51207), but 
the Spark Connect JDBC
+  // client cannot retrieve them in a structured way yet, so both return an 
empty result set
+  // instead of throwing.
+  private def emptyForeignKeys: ResultSet = {
+    val df = conn.spark.emptyDataFrame
+      .withColumn("PKTABLE_CAT", lit(""))
+      .withColumn("PKTABLE_SCHEM", lit(""))
+      .withColumn("PKTABLE_NAME", lit(""))
+      .withColumn("PKCOLUMN_NAME", lit(""))
+      .withColumn("FKTABLE_CAT", lit(""))
+      .withColumn("FKTABLE_SCHEM", lit(""))
+      .withColumn("FKTABLE_NAME", lit(""))
+      .withColumn("FKCOLUMN_NAME", lit(""))
+      .withColumn("KEY_SEQ", lit(0.toShort))
+      .withColumn("UPDATE_RULE", lit(0.toShort))
+      .withColumn("DELETE_RULE", lit(0.toShort))
+      .withColumn("FK_NAME", lit(""))
+      .withColumn("PK_NAME", lit(""))
+      .withColumn("DEFERRABILITY", lit(0.toShort))
+    new SparkConnectResultSet(df.collectResult())
+  }
+
+  override def getImportedKeys(catalog: String, schema: String, table: 
String): ResultSet = {
+    conn.checkOpen()
+    emptyForeignKeys
+  }
+
+  override def getExportedKeys(catalog: String, schema: String, table: 
String): ResultSet = {
+    conn.checkOpen()
+    emptyForeignKeys
+  }
 
   override def getCrossReference(

Review Comment:
   Was leaving `getCrossReference` throwing intentional? It returns the same 
14-column JDBC foreign-key schema as `getImportedKeys`/`getExportedKeys`, so 
the new `emptyForeignKeys` helper applies verbatim, and your rationale (the 
Connect client can't read FK constraints structurally, so return empty rather 
than throw) holds identically here. As written, a client probing 
cross-references still hits the `SQLFeatureNotSupportedException` this PR is 
removing for the other two FK methods. I'd return `emptyForeignKeys` here too; 
if it's a deliberate scope cut, worth a note in the PR description alongside 
the `getFunctions` one.



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