Skip to content

GH-51779: [C++][IPC] Read a DictionaryEncoding without indexType as int32 indices - #51807

Open
CaptainAni187 wants to merge 2 commits into
apache:mainfrom
CaptainAni187:GH-51779-default-dictionary-index-type
Open

CaptainAni187 wants to merge 2 commits into
apache:mainfrom
CaptainAni187:GH-51779-default-dictionary-index-type

Conversation

@CaptainAni187

@CaptainAni187 CaptainAni187 commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Rationale for this change

Schema.fbs allows DictionaryEncoding.indexType to be omitted: "If this field is null, the indices must be signed int32." The C++ IPC reader required it instead, so C++ and PyArrow failed to read such a stream with IOError: Unexpected null field DictionaryEncoding.indexType in flatbuffer-encoded metadata.

What changes are included in this PR?

FieldFromFlatbuffer uses int32() as the index type when indexType is absent, instead of failing the null check.

Are these changes tested?

Yes. TestMessageInternal.DictionaryEncodingWithoutIndexType builds a schema message whose dictionary-encoded field has no indexType and checks that ReadSchema returns dictionary<values=string, indices=int32>. On main it fails with the error above. The arrow-ipc-* tests pass locally.

Are there any user-facing changes?

Streams that omit indexType can now be read. Streams that include it are read as before.

Was AI used for this PR?

In accordance to the AI generation guidelines, please disclose below whether and how AI was used in this PR.

PR code and description written by:

  • Human
  • AI

Reviewed before submission by:

  • Human
  • AI
  • Not reviewed

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown

⚠️ GitHub issue #51779 has been automatically assigned in GitHub to PR creator.

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown

⚠️ GitHub issue #51779 has been automatically assigned in GitHub to PR creator.

@CaptainAni187
CaptainAni187 marked this pull request as ready for review October 5, 2026 23:54
Comment on lines +131 to +132
auto metadata = Buffer::FromString(
std::string(reinterpret_cast<const char*>(fbb.GetBufferPointer()), fbb.GetSize()));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The test copies the flatbuffer into a Buffer by hand through a std::string. internal::WriteFlatbufferBuilder(fbb) already does this (read_write_test.cc uses it) and would also make the new #include <string> unnecessary.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 7453d8a, and the <string> include is gone.

@github-actions github-actions Bot added awaiting changes Awaiting changes and removed awaiting review Awaiting review labels Oct 9, 2026

ASSERT_OK_AND_ASSIGN(auto message, Message::Open(metadata, /*body=*/nullptr));
DictionaryMemo memo;
ASSERT_OK_AND_ASSIGN(auto schema, ReadSchema(*message, &memo));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we also check that the field was registered in memo? The schema comparison passes even if the new code path never registers the field. A reader needs that registration to match the field to the DictionaryBatch and RecordBatch that follow, and that's where #51779 failed. Something like:

  ASSERT_OK_AND_EQ(0, memo.fields().GetFieldId({0}));
  ASSERT_OK_AND_ASSIGN(auto dict_value_type, memo.GetDictionaryType(0));
  AssertTypeEqual(utf8(), dict_value_type);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added in 7453d8a: the test now checks the field ID and that the dictionary value type is utf8().

@github-actions github-actions Bot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants