Uh oh!
There was an error while loading. Please reload this page.
test: add advanced dictionary test - #23483
Conversation
Rich-T-kid
commented
Jul 11, 2026
cc @kosiew |
There was a problem hiding this comment.
@Rich-T-kid
Thanks for working on this. I think the regression test is headed in the right direction, but I don't think it currently exercises the case we want to protect against. In addition, I have one small suggestion to simplify the coverage.
| FROM (VALUES ('west'), ('east'), ('west'), (NULL)) AS t(column1) | ||
| ), | ||
| second_batch AS ( | ||
| SELECT arrow_cast(column1, 'Dictionary(Int16, LargeUtf8)') AS region |
There was a problem hiding this comment.
I don't think these new regression cases are exercising dictionary grouping at the aggregation boundary.
Because the UNION inputs use different dictionary key/value types, for example Dictionary(Int32, Utf8) unioned with Dictionary(Int16, LargeUtf8) here, the physical plan coerces both branches back to LargeUtf8 before UnionExec and AggregateExec: CAST(CAST(column1 AS Dictionary(...)) AS LargeUtf8).
That means the GROUP BY sees plain strings, so an implementation that incorrectly hashed dictionary key ids would still pass these tests.
Could you construct the inputs using the same dictionary type while varying the dictionary value order instead? Alternatively, if there's another approach, could you verify through the plan or test setup that AggregateExec is actually consuming separate dictionary arrays with different dictionaries?
There was a problem hiding this comment.
🤔 I didn't consider that datafusion would cast them before reaching the aggregation stage. Ive updated the test to use the same key/value types while varying the order.
Uh oh!
There was an error while loading. Please reload this page.
Rich-T-kid
commented
Jul 14, 2026
the test in 4ca86a1 Key id 0 means 'west' in the first batch but 'east' in the second. A buggy implementation that groups by raw key id would put those together: so west (group 0) would be seen 6 times while east (group 1) would be seen 2 times. this would be incorrect. |
Rich-T-kid
commented
Jul 17, 2026
thanks @kosiew |
Uh oh!
There was an error while loading. Please reload this page.
## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closesapache#123` indicates that this PR will close issue apache#123. --> follow up PR for apache#23280 ## Rationale for this change see comment apache#23280 (comment) <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. --> ## What changes are included in this PR? Adds SQL logic tests to verify that GROUP BY on dictionary-encoded columns resolves on values rather than raw dictionary key integers. The tests use UNION ALL between independently-encoded subqueries (mixing Int32/Int16/Int8 key types and Utf8/LargeUtf8 value types) <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> ## Are these changes tested? the test cover - Correct grouping when the same value maps to different keys in different batches - No false merging of distinct values that happen to share the same key number - Null handling across batches with mismatched key assignments <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> ## Are there any user-facing changes? no <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> <!-- If there are any breaking changes to public APIs, please add the `api change` label. -->
Which issue does this PR close?
follow up PR for #23280
Rationale for this change
see comment #23280 (comment)
What changes are included in this PR?
Adds SQL logic tests to verify that GROUP BY on dictionary-encoded columns resolves on values rather than raw dictionary key integers. The tests use UNION ALL between independently-encoded subqueries (mixing Int32/Int16/Int8 key types and Utf8/LargeUtf8 value types)
Are these changes tested?
the test cover
Are there any user-facing changes?
no