Repository navigation
feat: support sending and receiving dictionary-encoded columns over Arrow Flight - #433
owencorrigan wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Preserve cancellation in the Flight read loop and add dictionary-stream regression coverage.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
This PR adds Arrow Flight support for reading dictionary-encoded columns, including replacement dictionaries.
Changes:
- Decode schemas using the reader’s
DictionaryMemo. - Process dictionary messages before record batches.
File summaries
| File | Summary |
|---|---|
src/Apache.Arrow/Ipc/ArrowReaderImplementation.cs |
Adds dictionary-aware schema decoding. |
src/Apache.Arrow.Flight/Internal/RecordBatchReaderImplementation.cs |
Processes dictionary and record-batch messages; needs cancellation propagation and Flight regression tests. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| // Dictionary batches precede the record batch that references them; keep | ||
| // reading until CreateArrowObjectFromMessage yields a record batch. | ||
| while (await _flightDataStream.MoveNext().ConfigureAwait(false)) |
|
I've added support for cancellation. I have also added support for sending dictionary encoded columns over flight so that we could do a round trip test |
|
A round-trip test sounds like a good idea. Can you also please rebase and then resolve the conflicts? |
7b8592e to
7f6f7bf
Compare
There was a problem hiding this comment.
🟡 Changes recommended
A critical issue remains in dictionary emission for later Flight batches.
Get a fresh assessment by requesting another Copilot review.
Review details
Suppressed comments (1)
test/Apache.Arrow.Flight.Tests/FlightTests.cs:94
- This regression test only sends one record batch, so it covers a single dictionary message but not the new loop's multi-message/replacement behavior described by the PR. Add a Flight-level fixture with an initial dictionary and a subsequent replacement (and assert both batches), otherwise a regression in dictionary replacement handling can still pass the test suite.
[Fact]
public async Task TestGetRecordBatchWithDictionaryColumn()
{
var flightDescriptor = FlightDescriptor.CreatePathDescriptor("test");
var expectedBatch = CreateTestBatchWithDictionaryColumn(0, 100);
GivenStoreBatches(flightDescriptor, new RecordBatchWithMetadata(expectedBatch));
- Files reviewed: 4/4 changed files
- Comments generated: 1
- Review effort level: Lite
Registers dictionary-encoded fields in the reader's DictionaryMemo when decoding a schema message, and buffers/flushes each dictionary-batch and record-batch message as its own Flight data frame so dictionary batches are delivered before the record batch that references them. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013HtVU4FRn8N9TEZkWsTya7
Flight batches may be consumed independently, so the writer now resends the full dictionary for each dictionary-encoded column before every record batch instead of only the first, per apache#180. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013HtVU4FRn8N9TEZkWsTya7
DictionaryMemo keys dictionary ids on Field reference identity (Dictionary<Field, long>, and Field has no value equality). The per-batch dictionary collector looked up ids from recordBatch.Schema's Field objects, which are not guaranteed to be the same instances the writer used when serializing the stream's schema. A batch built with its own Schema instance for the same logical columns would therefore be assigned a fresh id instead of reusing the one already declared in the schema, and the reader would reject the resulting DictionaryBatch with "Dictionary with id N not found". Use the writer's own Schema (stable for the life of the stream) as the source of Field identity for id lookups; only read column data from the record batch. Adds a regression test building each batch from its own Schema instance to pin down the failure mode. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
WalkChildren derived child Field identity from the batch's own type tree, so a nested dictionary column in a batch built from a distinct (value-equal) Schema instance was minted a fresh id the stream's schema never declared, and the reader failed with "Dictionary with id N not found" — the same reference-identity bug fixed for top-level columns, one level down. Thread the writer schema's type tree through the recursion instead. Also deletes the now-unused FlightMessageSerializer.DecodeSchema (ByteBuffer) overload, trims MR comments to the surrounding style, and adds a nested-dictionary round-trip regression test. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
de54023 to
c04a955
Compare
|
Fixed issue raised by copilot above for dictionary-id issue. Missed nested case fixed in latest commit |
There was a problem hiding this comment.
🟡 Changes recommended
A critical active issue remains because distinct but value-equal batch schemas can assign inconsistent dictionary IDs between dictionary emission and record-batch headers, preventing readers from resolving the dictionary.
2 open issues
Review effort: Lite
| internal static void Collect(Schema writerSchema, RecordBatch recordBatch, ref DictionaryMemo dictionaryMemo) | ||
| { | ||
| Schema schema = recordBatch.Schema; | ||
| for (int i = 0; i < schema.FieldsList.Count; i++) | ||
| for (int i = 0; i < writerSchema.FieldsList.Count; i++) | ||
| { | ||
| Field field = schema.GetFieldByIndex(i); | ||
| Field field = writerSchema.GetFieldByIndex(i); | ||
| IArrowArray array = recordBatch.Column(i); |
There was a problem hiding this comment.
I don't think this is correct. The test TestGetRecordBatchesWithDistinctSchemaInstancesPerBatch is passing for me locally.
the record batch header is encoded with a newly assigned ID
RecordBatch only has length, field nodes, buffers, and compression, no ID field


What's Changed
The C# Arrow Flight reader (
RecordBatchReaderImplementation) threwNotImplementedExceptionon any dictionary batch, so a Flight stream containing adictionary-encoded column could not be read.
ReadNextRecordBatchAsyncnow loops over the incoming Flight messages, feedingeach through the base
CreateArrowObjectFromMessage(which reads dictionarybatches into the
DictionaryMemoand returns null for them) until it yields arecord batch, instead of throwing on any non-record-batch message. Handles both
single and replacement dictionaries.
DictionaryMemovia a new base helperReadSchemaFromMessage, so dictionary-encoded fields are registered(
FlightMessageSerializerpreviously discarded them).The change routes dictionary batches to the existing
ArrowReaderImplementationdecoder, so it is not specific to any particular index or value type. Validated
against a pyarrow
RecordBatchStreamserving adictionary<int16, string>column(single + replacement dictionaries); the current reader throws on the same stream.
Refs #180 (receive side).
Generated-By: Claude Opus 4.8