You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "kou (via GitHub)" <gi...@apache.org> on 2023/05/26 13:25:06 UTC
[GitHub] [arrow] kou commented on a diff in pull request #35774: GH-35788: [Swift] bug fixes and change reader/writer to user Result type
kou commented on code in PR #35774:
URL: https://github.com/apache/arrow/pull/35774#discussion_r1206767131
##########
swift/Arrow/Sources/Arrow/ArrowArray.swift:
##########
@@ -17,7 +17,60 @@
import Foundation
-public class ArrowArray<T> {
+public class ArrowArrayHolder {
+ public let type: ArrowType.Info
+ public let length: UInt
+ public let nullCount: UInt
+ public let holder: Any
+ public let getBufferData: () -> [Data]
+ public let getBufferDataSizes: () -> [Int]
+ private let getArrowColumn: (ArrowField, [ArrowArrayHolder]) throws -> ArrowColumn
+ public init<T>(_ arrowArray: ArrowArray<T>) {
+ self.holder = arrowArray
+ self.length = arrowArray.length
+ self.type = arrowArray.arrowData.type
+ self.nullCount = arrowArray.nullCount
+ self.getBufferData = {() -> [Data] in
+ var bufferData = [Data]()
+ for buffer in arrowArray.arrowData.buffers {
+ bufferData.append(Data())
+ buffer.append(to: &bufferData[bufferData.count - 1])
+ }
+
+ return bufferData;
+ }
+
+ self.getBufferDataSizes = {() -> [Int] in
+ var bufferDataSizes = [Int]()
+ for buffer in arrowArray.arrowData.buffers {
+ bufferDataSizes.append(Int(buffer.capacity))
+ }
+
+ return bufferDataSizes
+ }
+
+ self.getArrowColumn = {(field: ArrowField, arrayHolders: [ArrowArrayHolder]) throws -> ArrowColumn in
+ var arrays = [ArrowArray<T>]()
+ for arrayHolder in arrayHolders {
+ if let array = arrayHolder.holder as? ArrowArray<T> {
+ arrays.append(array)
+ }
+ }
+
+ return ArrowColumn(field, chunked: ChunkedArrayHolder(try ChunkedArray<T>(arrays)))
+ }
+ }
+
+ public static func makeArrowColumn(_ field: ArrowField, holders: [ArrowArrayHolder]) -> Result<ArrowColumn, ArrowError> {
+ do {
+ return .success(try holders[0].getArrowColumn(field, holders))
+ }catch {
Review Comment:
```suggestion
} catch {
```
##########
swift/Arrow/Sources/Arrow/ArrowArray.swift:
##########
@@ -17,7 +17,60 @@
import Foundation
-public class ArrowArray<T> {
+public class ArrowArrayHolder {
+ public let type: ArrowType.Info
+ public let length: UInt
+ public let nullCount: UInt
+ public let holder: Any
Review Comment:
How about renaming this to `array`?
```suggestion
public let array: Any
```
I feel that `ArrowArrayHolder.holder` is strange.
##########
swift/Arrow/Sources/Arrow/ArrowReader.swift:
##########
@@ -138,26 +158,36 @@ public class ArrowReader {
let message = org_apache_arrow_flatbuf_Message.getRootAsMessage(bb: mbb)
switch message.headerType {
case .recordbatch:
- let recordBatch = try loadRecordBatch(message, schema: footer.schema!,
- data: fileData, messageEndOffset: messageEndOffset)
- recordBatchs.append(recordBatch)
+ do {
+ let recordBatch = try loadRecordBatch(message, schema: footer.schema!,
+ data: fileData, messageEndOffset: messageEndOffset).get()
Review Comment:
```suggestion
data: fileData, messageEndOffset: messageEndOffset).get()
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org