jding-xyz opened a new pull request, #148:
URL: https://github.com/apache/arrow-swift/pull/148

   ## Problem
   
   `ArrowWriter.writeStreaming()` crashes with a FlatBuffers assertion when 
writing any schema containing a `Timestamp` field with a timezone (e.g. 
`timestamp[us, UTC]`):
   
   ```
   FlatBuffers/FlatBufferBuilder.swift:317: Assertion failed: Object 
serialization must not be nested
   ```
   
   In `toFBType()` (ArrowWriterHelper.swift), the `.timestamp` case calls 
`fbb.create(string: timezone)` inside the `startTimestamp`/`endTimestamp` table 
context. FlatBuffers' `create(string:)` calls `notNested()` which asserts 
`!isNested`, but `startTimestamp` (which calls `startTable`) has already set 
`isNested = true`.
   
   ## Fix
   
   Move the `fbb.create(string:)` call before `startTimestamp()`. This is the 
standard FlatBuffers pattern: all child objects (strings, vectors, tables) must 
be created before starting their parent table.
   
   ```swift
   // Before (buggy):
   let startOffset = org_apache_arrow_flatbuf_Timestamp.startTimestamp(&fbb)
   // ...
   if let timezone = timestampType.timezone {
       let timezoneOffset = fbb.create(string: timezone) // ASSERTS
   }
   
   // After (fixed):
   let timezoneOffset = timestampType.timezone.map { fbb.create(string: $0) }
   let startOffset = org_apache_arrow_flatbuf_Timestamp.startTimestamp(&fbb)
   // ...
   if let offset = timezoneOffset {
       org_apache_arrow_flatbuf_Timestamp.add(timezone: offset, &fbb)
   }
   ```
   
   ## Additional change
   
   Added `.iOS(.v15)` and `.watchOS(.v8)` to the `platforms` array in 
Package.swift. The `Arrow` target uses only Foundation and FlatBuffers, both of 
which are available on iOS/watchOS. This addresses #142.
   
   ## Testing
   
   All existing in-memory tests pass (the 5 pre-existing file-based test 
failures that require generated `testdata_*.arrow` files are unaffected):
   
   ```
   Executed 45 tests, with 5 failures (5 unexpected) in 0.240 seconds
   ```
   
   The 5 failures (`testFileReader_bool`, `testFileReader_double`, 
`testFileReader_struct`, `testFileWriter_bool`, `testFileWriter_struct`) fail 
identically on `main` — they require test data files not present in the repo.
   
   Made with [Cursor](https://cursor.com)


-- 
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]

Reply via email to