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 ccf841c [SPARK-57051] Support `getCreateTableString` in `Catalog`
ccf841c is described below
commit ccf841c98ef968b02eae521f8d0533f947428aa1
Author: Dongjoon Hyun <[email protected]>
AuthorDate: Sun May 24 21:45:43 2026 -0700
[SPARK-57051] Support `getCreateTableString` in `Catalog`
### What changes were proposed in this pull request?
This PR aims to support `Spark_Connect_GetCreateTableString` message added
in Apache Spark Connect 4.2.0-preview5.
- https://github.com/apache/spark/pull/55025
### Why are the changes needed?
For feature parity with Spark Connect.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Pass the CIs with the newly added test case.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 4.7
This patch had conflicts when merged, resolved by
Committer: Dongjoon Hyun <[email protected]>
Closes #386 from dongjoon-hyun/SPARK-57051.
Authored-by: Dongjoon Hyun <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
---
Sources/SparkConnect/Catalog.swift | 19 +++++++++++++++++++
Tests/SparkConnectTests/CatalogTests.swift | 19 +++++++++++++++++++
2 files changed, 38 insertions(+)
diff --git a/Sources/SparkConnect/Catalog.swift
b/Sources/SparkConnect/Catalog.swift
index cbfb69c..bb3f617 100644
--- a/Sources/SparkConnect/Catalog.swift
+++ b/Sources/SparkConnect/Catalog.swift
@@ -401,6 +401,25 @@ public actor Catalog: Sendable {
return properties
}
+ /// Returns the CREATE TABLE statement string for the given table.
+ /// - Parameters:
+ /// - tableName: A qualified or unqualified name that designates a table.
+ /// - asSerde: If true, returns the CREATE TABLE statement in Hive `SERDE`
format.
+ /// - Returns: The CREATE TABLE statement string.
+ public func getCreateTableString(_ tableName: String, asSerde: Bool = false)
async throws
+ -> String
+ {
+ let df = getDataFrame({
+ var getCreateTableString = Spark_Connect_GetCreateTableString()
+ getCreateTableString.tableName = tableName
+ getCreateTableString.asSerde = asSerde
+ var catalog = Spark_Connect_Catalog()
+ catalog.catType = .getCreateTableString(getCreateTableString)
+ return catalog
+ })
+ return try await df.collect()[0][0] as! String
+ }
+
/// Check if the table or view with the specified name exists. This can
either be a temporary
/// view or a table/view.
/// - Parameter tableName: a qualified or unqualified name that designates a
table/view. It follows the same
diff --git a/Tests/SparkConnectTests/CatalogTests.swift
b/Tests/SparkConnectTests/CatalogTests.swift
index ee00da8..1456bba 100644
--- a/Tests/SparkConnectTests/CatalogTests.swift
+++ b/Tests/SparkConnectTests/CatalogTests.swift
@@ -570,6 +570,25 @@ struct CatalogTests {
await spark.stop()
}
+ @Test
+ func getCreateTableString() async throws {
+ let spark = try await SparkSession.builder.getOrCreate()
+ if await spark.version >= "4.2" {
+ let tableName = "TABLE_" + UUID().uuidString.replacingOccurrences(of:
"-", with: "")
+ try await SQLHelper.withTable(spark, tableName)({
+ try await spark.range(1).write.saveAsTable(tableName)
+ let stmt = try await spark.catalog.getCreateTableString(tableName)
+ #expect(stmt.contains("CREATE TABLE"))
+ #expect(stmt.contains(tableName))
+ })
+
+ try await #require(throws: SparkConnectError.TableOrViewNotFound) {
+ try await spark.catalog.getCreateTableString("not_exist_table")
+ }
+ }
+ await spark.stop()
+ }
+
@Test
func truncateTable() async throws {
let spark = try await SparkSession.builder.getOrCreate()
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]