This is an automated email from the ASF dual-hosted git repository.

dongjoon pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/spark-connect-swift.git


The following commit(s) were added to refs/heads/main by this push:
     new 8ec6921  [SPARK-52152] Fix `Catalog.databaseExists` to handle multi 
catalogs
8ec6921 is described below

commit 8ec6921d3c4bbdf2236a70a0f52bc459c33e22c6
Author: Dongjoon Hyun <[email protected]>
AuthorDate: Wed May 14 20:15:02 2025 -0700

    [SPARK-52152] Fix `Catalog.databaseExists` to handle multi catalogs
    
    ### What changes were proposed in this pull request?
    
    This PR aims to fix `Catalog.databaseExists` to handle multi-catalogs.
    
    ### Why are the changes needed?
    
    To handle Iceberg catalog.
    
    ### Does this PR introduce _any_ user-facing change?
    
    No.
    
    ### How was this patch tested?
    
    Pass the CIs. Apache Iceberg CI will be added soon.
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    No.
    
    Closes #150 from dongjoon-hyun/SPARK-52152.
    
    Authored-by: Dongjoon Hyun <[email protected]>
    Signed-off-by: Dongjoon Hyun <[email protected]>
---
 Sources/SparkConnect/Catalog.swift | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/Sources/SparkConnect/Catalog.swift 
b/Sources/SparkConnect/Catalog.swift
index 6c86f61..4f3c917 100644
--- a/Sources/SparkConnect/Catalog.swift
+++ b/Sources/SparkConnect/Catalog.swift
@@ -197,7 +197,14 @@ public actor Catalog: Sendable {
   /// - Parameter dbName: name of the database to check existence
   /// - Returns: Indicating whether the database exists.
   public func databaseExists(_ dbName: String) async throws -> Bool {
-    return try await self.listDatabases(pattern: dbName).count > 0
+    let df = getDataFrame({
+      var databaseExists = Spark_Connect_DatabaseExists()
+      databaseExists.dbName = dbName
+      var catalog = Spark_Connect_Catalog()
+      catalog.catType = .databaseExists(databaseExists)
+      return catalog
+    })
+    return try await df.collect().first![0] as! Bool
   }
 
   /// Creates a table from the given path and returns the corresponding 
``DataFrame``.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to