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 af7b0c9 [SPARK-52317] Identify `InvalidTypeException` in
`SparkConnectClient`
af7b0c9 is described below
commit af7b0c9867d2a8aa523a34c87a9477d8f14ead2b
Author: Dongjoon Hyun <[email protected]>
AuthorDate: Mon May 26 18:02:41 2025 -0700
[SPARK-52317] Identify `InvalidTypeException` in `SparkConnectClient`
### What changes were proposed in this pull request?
This PR aims to identify `InvalidTypeException` in `SparkConnectClient`.
### Why are the changes needed?
To centralize the `InvalidTypeException` handling into a single place.
Previously, three actors do the same error handling logic redundantly.
- `DataFrame`
- `DataFrameReader`
- `DataStreamReader`
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Pass the CIs.
### Was this patch authored or co-authored using generative AI tooling?
No.
Closes #176 from dongjoon-hyun/SPARK-52317.
Authored-by: Dongjoon Hyun <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
---
Sources/SparkConnect/DataFrame.swift | 9 ++-------
Sources/SparkConnect/DataFrameReader.swift | 7 +------
Sources/SparkConnect/DataStreamReader.swift | 7 +------
Sources/SparkConnect/SparkConnectClient.swift | 13 +++++++++++--
4 files changed, 15 insertions(+), 21 deletions(-)
diff --git a/Sources/SparkConnect/DataFrame.swift
b/Sources/SparkConnect/DataFrame.swift
index 760ece3..e52226a 100644
--- a/Sources/SparkConnect/DataFrame.swift
+++ b/Sources/SparkConnect/DataFrame.swift
@@ -489,13 +489,8 @@ public actor DataFrame: Sendable {
/// - Parameter schema: The given schema.
/// - Returns: A ``DataFrame`` with the given schema.
public func to(_ schema: String) async throws -> DataFrame {
- // Validate by parsing.
- do {
- let dataType = try await sparkSession.client.ddlParse(schema)
- return DataFrame(spark: self.spark, plan:
SparkConnectClient.getToSchema(self.plan.root, dataType))
- } catch {
- throw SparkConnectError.InvalidTypeException
- }
+ let dataType = try await sparkSession.client.ddlParse(schema)
+ return DataFrame(spark: self.spark, plan:
SparkConnectClient.getToSchema(self.plan.root, dataType))
}
/// Returns the content of the Dataset as a Dataset of JSON strings.
diff --git a/Sources/SparkConnect/DataFrameReader.swift
b/Sources/SparkConnect/DataFrameReader.swift
index 58567db..274efdf 100644
--- a/Sources/SparkConnect/DataFrameReader.swift
+++ b/Sources/SparkConnect/DataFrameReader.swift
@@ -123,12 +123,7 @@ public actor DataFrameReader: Sendable {
/// - Returns: A ``DataFrameReader``.
@discardableResult
public func schema(_ schema: String) async throws -> DataFrameReader {
- // Validate by parsing.
- do {
- try await sparkSession.client.ddlParse(schema)
- } catch {
- throw SparkConnectError.InvalidTypeException
- }
+ try await sparkSession.client.ddlParse(schema)
self.userSpecifiedSchemaDDL = schema
return self
}
diff --git a/Sources/SparkConnect/DataStreamReader.swift
b/Sources/SparkConnect/DataStreamReader.swift
index e90a1c1..da87505 100644
--- a/Sources/SparkConnect/DataStreamReader.swift
+++ b/Sources/SparkConnect/DataStreamReader.swift
@@ -50,12 +50,7 @@ public actor DataStreamReader: Sendable {
/// - Returns: A ``DataStreamReader``.
@discardableResult
public func schema(_ schema: String) async throws -> DataStreamReader {
- // Validate by parsing.
- do {
- try await sparkSession.client.ddlParse(schema)
- } catch {
- throw SparkConnectError.InvalidTypeException
- }
+ try await sparkSession.client.ddlParse(schema)
self.userSpecifiedSchemaDDL = schema
return self
}
diff --git a/Sources/SparkConnect/SparkConnectClient.swift
b/Sources/SparkConnect/SparkConnectClient.swift
index 5c6b4cc..f8a0073 100644
--- a/Sources/SparkConnect/SparkConnectClient.swift
+++ b/Sources/SparkConnect/SparkConnectClient.swift
@@ -781,8 +781,17 @@ public actor SparkConnectClient {
ddlParse.ddlString = ddlString
return OneOf_Analyze.ddlParse(ddlParse)
})
- let response = try await service.analyzePlan(request)
- return response.ddlParse.parsed
+ do {
+ let response = try await service.analyzePlan(request)
+ return response.ddlParse.parsed
+ } catch let error as RPCError where error.code == .internalError {
+ switch error.message {
+ case let m where m.contains("UNSUPPORTED_DATATYPE") ||
m.contains("INVALID_IDENTIFIER"):
+ throw SparkConnectError.InvalidTypeException
+ default:
+ throw error
+ }
+ }
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]