GH-49674: [C++][Array] Preserve ordered flag for DictionaryType in MakeEmptyArray#49798
Open
Reranko05 wants to merge 1 commit intoapache:mainfrom
Open
GH-49674: [C++][Array] Preserve ordered flag for DictionaryType in MakeEmptyArray#49798Reranko05 wants to merge 1 commit intoapache:mainfrom
Reranko05 wants to merge 1 commit intoapache:mainfrom
Conversation
|
|
paleolimbot
reviewed
Apr 20, 2026
Member
paleolimbot
left a comment
There was a problem hiding this comment.
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!).
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale for this change
RecordBatch::MakeEmpty()creates arrays usingMakeEmptyArray(), which relies onArrayBuilder::Finish(). For dictionary-encoded types,DictionaryBuilderreconstructs theDictionaryTypewithout 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 originalDataTypefor dictionary types only afterbuilder->Finish(), ensuring the ordered flag is preserved.Add a unit test to verify:
Are these changes tested?
Yes. A unit test has been added that:
ordered = true.RecordBatch::MakeEmpty().num_rows == 0,num_columns == 1).Are there any user-facing changes?
No.
Closes #49674
RecordBatch::MakeEmpty()may drop ordered flag when creating dictionary-encoded column #49674