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

dongjoon-hyun 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 0380236  [SPARK-57087] Support `listFunctions` in `Catalog`
0380236 is described below

commit 0380236c20060ff176d1e56c63c51c599488cfa9
Author: Dongjoon Hyun <[email protected]>
AuthorDate: Tue May 26 14:59:49 2026 -0700

    [SPARK-57087] Support `listFunctions` in `Catalog`
    
    This PR aims to support `listFunctions` in `Catalog`.
    
    For feature parity with Apache Spark's `Catalog.listFunctions` API.
    
    No, this is a new API.
    
    Pass the CIs with the newly added test case.
    
    Generated-by: Claude Code
    
    This patch had conflicts when merged, resolved by
    Committer: Dongjoon Hyun <[email protected]>
    
    Closes #395 from dongjoon-hyun/SPARK-57087.
    
    Authored-by: Dongjoon Hyun <[email protected]>
    Signed-off-by: Dongjoon Hyun <[email protected]>
---
 Sources/SparkConnect/Catalog.swift         | 31 ++++++++++++++++++++++++++++++
 Tests/SparkConnectTests/CatalogTests.swift | 14 ++++++++++++++
 2 files changed, 45 insertions(+)

diff --git a/Sources/SparkConnect/Catalog.swift 
b/Sources/SparkConnect/Catalog.swift
index 64d5574..d846e4c 100644
--- a/Sources/SparkConnect/Catalog.swift
+++ b/Sources/SparkConnect/Catalog.swift
@@ -293,6 +293,37 @@ public actor Catalog: Sendable {
     }
   }
 
+  /// Returns a list of functions registered in the specified database (or the 
current database).
+  /// This includes all temporary functions.
+  /// - Parameters:
+  ///   - dbName: An optional database name. Defaults to the current database.
+  ///   - pattern: The pattern that the function name needs to match.
+  /// - Returns: A list of ``Function``.
+  public func listFunctions(dbName: String? = nil, pattern: String? = nil) 
async throws -> [Function]
+  {
+    let df = getDataFrame({
+      var listFunctions = Spark_Connect_ListFunctions()
+      if let dbName {
+        listFunctions.dbName = dbName
+      }
+      if let pattern {
+        listFunctions.pattern = pattern
+      }
+      var catalog = Spark_Connect_Catalog()
+      catalog.catType = .listFunctions(listFunctions)
+      return catalog
+    })
+    return try await df.collect().map {
+      try Function(
+        name: $0[0] as! String,
+        catalog: $0[1] as? String,
+        namespace: $0[2] as? [String],
+        description: $0[3] as? String,
+        className: ($0[4] as? String) ?? "",
+        isTemporary: $0[5] as! Bool)
+    }
+  }
+
   /// Returns a list of views in the given database (or the current database).
   /// - Parameters:
   ///   - dbName: The name of the database to list views from.
diff --git a/Tests/SparkConnectTests/CatalogTests.swift 
b/Tests/SparkConnectTests/CatalogTests.swift
index 94c21dc..2f18cb1 100644
--- a/Tests/SparkConnectTests/CatalogTests.swift
+++ b/Tests/SparkConnectTests/CatalogTests.swift
@@ -380,6 +380,20 @@ struct CatalogTests {
     await spark.stop()
   }
 
+  @Test
+  func listFunctions() async throws {
+    let spark = try await SparkSession.builder.getOrCreate()
+    #expect(try await spark.catalog.listFunctions().count > 0)
+
+    let base64 = try await spark.catalog.listFunctions(pattern: "base64")
+    #expect(base64.count == 1)
+    #expect(base64[0].name == "base64")
+    #expect(base64[0].isTemporary == true)
+
+    #expect(try await spark.catalog.listFunctions(pattern: 
"non_exist_function").count == 0)
+    await spark.stop()
+  }
+
   @Test
   func createTempView() async throws {
     let spark = try await SparkSession.builder.getOrCreate()


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

Reply via email to