Skip to content

GH-49674: [C++][Array] Preserve ordered flag for DictionaryType in MakeEmptyArray#49798

Open
Reranko05 wants to merge 1 commit intoapache:mainfrom
Reranko05:fix-dictionary-ordered-makeempty
Open

GH-49674: [C++][Array] Preserve ordered flag for DictionaryType in MakeEmptyArray#49798
Reranko05 wants to merge 1 commit intoapache:mainfrom
Reranko05:fix-dictionary-ordered-makeempty

Conversation

@Reranko05
Copy link
Copy Markdown
Contributor

@Reranko05 Reranko05 commented Apr 19, 2026

Rationale for this change

RecordBatch::MakeEmpty() creates arrays using MakeEmptyArray(), which relies on ArrayBuilder::Finish(). For dictionary-encoded types, DictionaryBuilder reconstructs the DictionaryType without preserving the ordered flag (defaulting it to false). As a result, the resulting array type does not match the input schema.

This change ensures that the original DictionaryType (including the ordered flag) is preserved.

What changes are included in this PR?

Update MakeEmptyArray() to restore the original DataType for dictionary types only after builder->Finish(), ensuring the ordered flag is preserved.

Add a unit test to verify:

  • The ordered flag is preserved.
  • The resulting array type matches the schema.
  • The created batch is empty and structurally correct.

Are these changes tested?

Yes. A unit test has been added that:

  • Constructs a dictionary-encoded schema with ordered = true.
  • Calls RecordBatch::MakeEmpty().
  • Verifies that:
    • The batch is empty (num_rows == 0, num_columns == 1).
    • Both schema and array types preserve the ordered flag.
    • The array type matches the schema type.

Are there any user-facing changes?

No.

Closes #49674

@github-actions
Copy link
Copy Markdown

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

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.

[C++] RecordBatch::MakeEmpty() may drop ordered flag when creating dictionary-encoded column

1 participant