eric-wang-1990 commented on code in PR #2886:
URL: https://github.com/apache/arrow-adbc/pull/2886#discussion_r2112265283


##########
csharp/src/Drivers/Databricks/DatabricksStatement.cs:
##########
@@ -386,5 +387,119 @@ protected override async Task<QueryResult> 
GetColumnsAsync(CancellationToken can
             // Call the base implementation with the potentially modified 
catalog name
             return await base.GetColumnsAsync(cancellationToken);
         }
+
+        /// <summary>
+        /// Determines whether PK/FK metadata queries 
(GetPrimaryKeys/GetCrossReference) should return an empty result set without 
hitting the server.
+        ///
+        /// Why:
+        /// - For certain catalog names (null, empty, "SPARK", 
"hive_metastore"), Databricks does not support PK/FK metadata,
+        ///   or these are legacy/synthesized catalogs that should gracefully 
return empty results for compatibility.
+        /// - The EnablePKFK flag allows the client to globally disable PK/FK 
metadata queries for performance or compatibility reasons.
+        ///
+        /// What it does:
+        /// - Returns true if PK/FK queries should return an empty result (and 
not hit the server), based on:
+        ///   - The EnablePKFK flag (if false, always return empty)
+        ///   - The catalog name (SPARK, hive_metastore, null, or empty string)
+        /// - Returns false if the query should proceed to the server (for 
valid, supported catalogs).
+        /// </summary>
+        internal bool ShouldReturnEmptyPkFkResult()
+        {
+            if (!enablePKFK)
+                return true;
+
+            // Handle special catalog cases
+            if (string.IsNullOrEmpty(CatalogName) ||
+                string.Equals(CatalogName, "SPARK", 
StringComparison.OrdinalIgnoreCase) ||
+                string.Equals(CatalogName, "hive_metastore", 
StringComparison.OrdinalIgnoreCase))
+            {
+                return true;
+            }
+
+            return false;
+        }
+
+        protected override async Task<QueryResult> 
GetPrimaryKeysAsync(CancellationToken cancellationToken = default)
+        {
+            if (ShouldReturnEmptyPkFkResult())
+                return EmptyPrimaryKeysResult();
+
+            return await base.GetPrimaryKeysAsync(cancellationToken);
+        }
+
+        private QueryResult EmptyPrimaryKeysResult()
+        {
+            var fields = new[]
+            {
+                new Field("TABLE_CAT", StringType.Default, true),
+                new Field("TABLE_SCHEM", StringType.Default, true),
+                new Field("TABLE_NAME", StringType.Default, true),
+                new Field("COLUMN_NAME", StringType.Default, true),
+                new Field("KEQ_SEQ", Int32Type.Default, true),

Review Comment:
   Nope this should be KEQ



-- 
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: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to