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.

Copy link
Copy Markdown
Member

@paleolimbot paleolimbot left a comment

Choose a reason for hiding this comment

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

Thank you for this!

It seems like this may also be solved by #49797 , which applies the DictionaryBuilder approach you also mentioned. In the absence of that I think this is a reasonable workaround (but somebody more active in the C++ implementation should also take a look!).

@github-actions github-actions bot added awaiting changes Awaiting changes and removed awaiting review Awaiting review labels Apr 20, 2026
@Reranko05
Copy link
Copy Markdown
Contributor Author

@paleolimbot That makes sense, this was mainly scoped as a minimal fix for the current behavior. If #49797 fully addresses it at the builder level, that would be a cleaner solution.

I can adjust or follow up based on further feedback.

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

2 participants