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 20113d8  [SPARK-52678] Update `ArrowReader.swift` with GH-54
20113d8 is described below

commit 20113d8ccf7dfb885f003a1f74de6be0fd07b926
Author: Dongjoon Hyun <[email protected]>
AuthorDate: Thu Jul 3 16:20:17 2025 -0700

    [SPARK-52678] Update `ArrowReader.swift` with GH-54
    
    ### What changes were proposed in this pull request?
    
    This PR aims to update `ArrowReader.swift` with `GH-54`.
    
    Please note that we cannot use `Apache Arrow Swift` directly yet because
    - It is still unable to support `Decimal`.
      - https://github.com/apache/arrow/pull/46628
    - It still uses `GRPC Swift` while we use `GRPC Swift 2`.
    
    ### Why are the changes needed?
    
    To be ready for the upstream release because `v21.0.0-rc0` tag is created.
    - https://github.com/apache/arrow-swift/releases/tag/v21.0.0-rc0
    
    According to the release notes, this seems to be the only one which needs 
to catch up.
    
    ### Does this PR introduce _any_ user-facing change?
    
    No behavior change because this is a refactoring to suppress warning 
messages.
    
    ### How was this patch tested?
    
    Pass the CIs.
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    No.
    
    Closes #207 from dongjoon-hyun/SPARK-52678.
    
    Authored-by: Dongjoon Hyun <[email protected]>
    Signed-off-by: Dongjoon Hyun <[email protected]>
---
 Sources/SparkConnect/ArrowReader.swift | 65 ++++++++++++++++------------------
 1 file changed, 31 insertions(+), 34 deletions(-)

diff --git a/Sources/SparkConnect/ArrowReader.swift 
b/Sources/SparkConnect/ArrowReader.swift
index 8af28ce..218351c 100644
--- a/Sources/SparkConnect/ArrowReader.swift
+++ b/Sources/SparkConnect/ArrowReader.swift
@@ -274,23 +274,22 @@ public class ArrowReader {  // swiftlint:disable:this 
type_body_length
       let message = org_apache_arrow_flatbuf_Message.getRootAsMessage(bb: 
dataBuffer)
       switch message.headerType {
       case .recordbatch:
-        do {
-          let rbMessage = message.header(type: 
org_apache_arrow_flatbuf_RecordBatch.self)!
-          let recordBatch = try loadRecordBatch(
-            rbMessage,
-            schema: schemaMessage!,
-            arrowSchema: result.schema!,
-            data: input,
-            messageEndOffset: (Int64(offset) + Int64(length))
-          ).get()
+        let rbMessage = message.header(type: 
org_apache_arrow_flatbuf_RecordBatch.self)!
+        let recordBatchResult = try loadRecordBatch(
+          rbMessage,
+          schema: schemaMessage!,
+          arrowSchema: result.schema!,
+          data: input,
+          messageEndOffset: (Int64(offset) + Int64(length))
+        )
+        switch recordBatchResult {
+        case .success(let recordBatch):
           result.batches.append(recordBatch)
-          offset += Int(message.bodyLength + Int64(length))
-          length = getUInt32(input, offset: offset)
-        } catch let error as ArrowError {
+        case .failure(let error):
           return .failure(error)
-        } catch {
-          return .failure(.unknownError("Unexpected error: \(error)"))
         }
+        offset += Int(message.bodyLength + Int64(length))
+        length = getUInt32(input, offset: offset)
       case .schema:
         schemaMessage = message.header(type: 
org_apache_arrow_flatbuf_Schema.self)!
         let schemaResult = loadSchema(schemaMessage!)
@@ -363,20 +362,19 @@ public class ArrowReader {  // swiftlint:disable:this 
type_body_length
       let message = org_apache_arrow_flatbuf_Message.getRootAsMessage(bb: mbb)
       switch message.headerType {
       case .recordbatch:
-        do {
-          let rbMessage = message.header(type: 
org_apache_arrow_flatbuf_RecordBatch.self)!
-          let recordBatch = try loadRecordBatch(
-            rbMessage,
-            schema: footer.schema!,
-            arrowSchema: result.schema!,
-            data: fileData,
-            messageEndOffset: messageEndOffset
-          ).get()
+        let rbMessage = message.header(type: 
org_apache_arrow_flatbuf_RecordBatch.self)!
+        let recordBatchResult = try loadRecordBatch(
+          rbMessage,
+          schema: footer.schema!,
+          arrowSchema: result.schema!,
+          data: fileData,
+          messageEndOffset: messageEndOffset
+        )
+        switch recordBatchResult {
+        case .success(let recordBatch):
           result.batches.append(recordBatch)
-        } catch let error as ArrowError {
+        case .failure(let error):
           return .failure(error)
-        } catch {
-          return .failure(.unknownError("Unexpected error: \(error)"))
         }
       default:
         return .failure(.unknownError("Unhandled header type: 
\(message.headerType)"))
@@ -429,17 +427,16 @@ public class ArrowReader {  // swiftlint:disable:this 
type_body_length
       }
     case .recordbatch:
       let rbMessage = message.header(type: 
org_apache_arrow_flatbuf_RecordBatch.self)!
-      do {
-        let recordBatch = try loadRecordBatch(
-          rbMessage, schema: result.messageSchema!, arrowSchema: 
result.schema!,
-          data: dataBody, messageEndOffset: 0
-        ).get()
+      let recordBatchResult = try loadRecordBatch(
+        rbMessage, schema: result.messageSchema!, arrowSchema: result.schema!,
+        data: dataBody, messageEndOffset: 0
+      )
+      switch recordBatchResult {
+      case .success(let recordBatch):
         result.batches.append(recordBatch)
         return .success(())
-      } catch let error as ArrowError {
+      case .failure(let error):
         return .failure(error)
-      } catch {
-        return .failure(.unknownError("Unexpected error: \(error)"))
       }
     default:
       return .failure(.unknownError("Unhandled header type: 
\(message.headerType)"))


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

Reply via email to