From 1b9034da8f0e367ae9bd379cc616dd5d8dd88ab6 Mon Sep 17 00:00:00 2001 From: Dongjoon Hyun Date: Wed, 14 May 2025 20:02:23 -0700 Subject: [PATCH] [SPARK-52152] Fix `Catalog.databaseExists` to handle multi catalogs --- 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``.