jding-xyz commented on code in PR #149:
URL: https://github.com/apache/arrow-swift/pull/149#discussion_r2992849833
##########
Sources/Arrow/ArrowWriter.swift:
##########
@@ -178,16 +185,23 @@ public class ArrowWriter { // swiftlint:disable:this
type_body_length
fbb: inout FlatBufferBuilder) {
for index in (0 ..< fields.count).reversed() {
let column = columns[index]
- let fieldNode =
- org_apache_arrow_flatbuf_FieldNode(length:
Int64(column.length),
- nullCount:
Int64(column.nullCount))
- offsets.append(fbb.create(struct: fieldNode))
+ // FlatBuffer vectors use prepend semantics: last-written element
becomes
+ // the first when read. Arrow IPC requires depth-first pre-order
(parent
+ // before children), so children must be written before their
parent here.
if let nestedType = column.type as? ArrowTypeStruct {
let nestedArray = column.array as? NestedArray
if let nestedFields = nestedArray?.fields {
writeFieldNodes(nestedType.fields, columns: nestedFields,
offsets: &offsets, fbb: &fbb)
}
+ } else if let listType = column.type as? ArrowTypeList {
+ if let nestedArray = column.array as? NestedArray, let
valuesHolder = nestedArray.values {
+ writeFieldNodes([listType.elementField], columns:
[valuesHolder], offsets: &offsets, fbb: &fbb)
+ }
}
+ let fieldNode =
+ org_apache_arrow_flatbuf_FieldNode(length:
Int64(column.length),
+ nullCount:
Int64(column.nullCount))
+ offsets.append(fbb.create(struct: fieldNode))
Review Comment:
Added testListInt32RBInMemoryToFromStream and
testListStructRBInMemoryToFromStream in IPCTests.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]