@@ -200,6 +200,114 @@ public actor Catalog: Sendable {
200200 return try await self . listDatabases ( pattern: dbName) . count > 0
201201 }
202202
203+ /// Creates a table from the given path and returns the corresponding ``DataFrame``.
204+ /// - Parameters:
205+ /// - tableName: A qualified or unqualified name that designates a table. If no database
206+ /// identifier is provided, it refers to a table in the current database.
207+ /// - path: A path to load a table.
208+ /// - source: A data source.
209+ /// - description: A table description.
210+ /// - options: A dictionary for table options
211+ /// - Returns: A ``DataFrame``.
212+ public func createTable(
213+ _ tableName: String ,
214+ _ path: String ? = nil ,
215+ source: String ? = nil ,
216+ description: String ? = nil ,
217+ options: [ String : String ] ? = nil
218+ ) -> DataFrame {
219+ let df = getDataFrame ( {
220+ var createTable = Spark_Connect_CreateTable ( )
221+ createTable. tableName = tableName
222+ if let source {
223+ createTable. source = source
224+ }
225+ createTable. description_p = description ?? " "
226+ if let options {
227+ for (k, v) in options {
228+ createTable. options [ k] = v
229+ }
230+ }
231+ if let path {
232+ createTable. options [ " path " ] = path
233+ }
234+ var catalog = Spark_Connect_Catalog ( )
235+ catalog. createTable = createTable
236+ return catalog
237+ } )
238+ return df
239+ }
240+
241+ /// Check if the table or view with the specified name exists. This can either be a temporary
242+ /// view or a table/view.
243+ /// - Parameter tableName: a qualified or unqualified name that designates a table/view. It follows the same
244+ /// resolution rule with SQL: search for temp views first then table/views in the current
245+ /// database (namespace).
246+ /// - Returns: Return true if it exists.
247+ public func tableExists( _ tableName: String ) async throws -> Bool {
248+ let df = getDataFrame ( {
249+ var tableExists = Spark_Connect_TableExists ( )
250+ tableExists. tableName = tableName
251+ var catalog = Spark_Connect_Catalog ( )
252+ catalog. tableExists = tableExists
253+ return catalog
254+ } )
255+ return " true " == ( try await df. collect ( ) . first!. get ( 0 ) as! String )
256+ }
257+
258+ /// Check if the table or view with the specified name exists. This can either be a temporary
259+ /// view or a table/view.
260+ /// - Parameters:
261+ /// - dbName: an unqualified name that designates a database.
262+ /// - tableName: an unqualified name that designates a table.
263+ /// - Returns: Return true if it exists.
264+ public func tableExists( _ dbName: String , _ tableName: String ) async throws -> Bool {
265+ let df = getDataFrame ( {
266+ var tableExists = Spark_Connect_TableExists ( )
267+ tableExists. tableName = tableName
268+ tableExists. dbName = dbName
269+ var catalog = Spark_Connect_Catalog ( )
270+ catalog. tableExists = tableExists
271+ return catalog
272+ } )
273+ return " true " == ( try await df. collect ( ) . first!. get ( 0 ) as! String )
274+ }
275+
276+ /// Check if the function with the specified name exists. This can either be a temporary function
277+ /// or a function.
278+ /// - Parameter functionName: a qualified or unqualified name that designates a function. It follows the same
279+ /// resolution rule with SQL: search for built-in/temp functions first then functions in the
280+ /// current database (namespace).
281+ /// - Returns: Return true if it exists.
282+ public func functionExists( _ functionName: String ) async throws -> Bool {
283+ let df = getDataFrame ( {
284+ var functionExists = Spark_Connect_FunctionExists ( )
285+ functionExists. functionName = functionName
286+ var catalog = Spark_Connect_Catalog ( )
287+ catalog. functionExists = functionExists
288+ return catalog
289+ } )
290+ return " true " == ( try await df. collect ( ) . first!. get ( 0 ) as! String )
291+ }
292+
293+ /// Check if the function with the specified name exists in the specified database under the Hive
294+ /// Metastore.
295+ /// - Parameters:
296+ /// - dbName: an unqualified name that designates a database.
297+ /// - functionName: an unqualified name that designates a function.
298+ /// - Returns: Return true if it exists.
299+ public func functionExists( _ dbName: String , _ functionName: String ) async throws -> Bool {
300+ let df = getDataFrame ( {
301+ var functionExists = Spark_Connect_FunctionExists ( )
302+ functionExists. functionName = functionName
303+ functionExists. dbName = dbName
304+ var catalog = Spark_Connect_Catalog ( )
305+ catalog. functionExists = functionExists
306+ return catalog
307+ } )
308+ return " true " == ( try await df. collect ( ) . first!. get ( 0 ) as! String )
309+ }
310+
203311 /// Caches the specified table in-memory.
204312 /// - Parameters:
205313 /// - tableName: A qualified or unqualified name that designates a table/view.
0 commit comments