Skip to content

feat: support sending and receiving dictionary-encoded columns over Arrow Flight - #433

Open
owencorrigan wants to merge 4 commits into
apache:mainfrom
owencorrigan:dictionary-flight-support
Open

owencorrigan wants to merge 4 commits into
apache:mainfrom
owencorrigan:dictionary-flight-support

Conversation

@owencorrigan

Copy link
Copy Markdown

What's Changed

The C# Arrow Flight reader (RecordBatchReaderImplementation) threw
NotImplementedException on any dictionary batch, so a Flight stream containing a
dictionary-encoded column could not be read.

  • ReadNextRecordBatchAsync now loops over the incoming Flight messages, feeding
    each through the base CreateArrowObjectFromMessage (which reads dictionary
    batches into the DictionaryMemo and returns null for them) until it yields a
    record batch, instead of throwing on any non-record-batch message. Handles both
    single and replacement dictionaries.
  • The schema is decoded using the reader's DictionaryMemo via a new base helper
    ReadSchemaFromMessage, so dictionary-encoded fields are registered
    (FlightMessageSerializer previously discarded them).

The change routes dictionary batches to the existing ArrowReaderImplementation
decoder, so it is not specific to any particular index or value type. Validated
against a pyarrow RecordBatchStream serving a dictionary<int16, string> column
(single + replacement dictionaries); the current reader throws on the same stream.

Refs #180 (receive side).

Generated-By: Claude Opus 4.8

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Comment on lines +125 to +127
// Dictionary batches precede the record batch that references them; keep
// reading until CreateArrowObjectFromMessage yields a record batch.
while (await _flightDataStream.MoveNext().ConfigureAwait(false))

@CurtHagenlocher CurtHagenlocher left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This would definitely benefit from some tests.

@owencorrigan

Copy link
Copy Markdown
Author

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
Let me know if this is OK

@CurtHagenlocher

Copy link
Copy Markdown
Contributor

A round-trip test sounds like a good idea. Can you also please rebase and then resolve the conflicts?

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

FlightDataStream can retain stale dictionary memo state across schema changes, causing dictionary ID mismatches.

Review effort: Lite
Findings: 1 Low severity

Open (1)
Resolved since last review (1)

owencorrigan and others added 4 commits November 24, 2026 14:36
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>
@owencorrigan
owencorrigan force-pushed the dictionary-flight-support branch from de54023 to c04a955 Compare November 24, 2026 15:02
@owencorrigan owencorrigan changed the title feat: support reading dictionary-encoded columns over Arrow Flight feat: support sending and receiving dictionary-encoded columns over Arrow Flight Nov 24, 2026
@owencorrigan

Copy link
Copy Markdown
Author

Fixed issue raised by copilot above for dictionary-id issue. Missed nested case fixed in latest commit

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment on lines +1577 to 1582
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);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants