Rich-T-kid opened a new issue, #9841: URL: https://github.com/apache/arrow-rs/issues/9841
**Is your feature request related to a problem or challenge? Please describe what you are trying to do.** There is currently no way to express that a DictionaryArray's values array is normalized (i.e., contains no duplicate entries), which leaves meaningful computation savings on the table. Several Arrow builders (StringDictionaryBuilder, LargeStringDictionaryBuilder, BinaryDictionaryBuilder, LargeBinaryDictionaryBuilder) already deduplicate their values arrays by construction, but there is currently no way to communicate this guarantee to downstream consumers. Knowing whether a dictionary's values array is normalized is extremely useful, consumers that want to leverage uniqueness guarantees (e.g., for optimized grouping or lookups) currently have no cheap way to check this. Verifying normalization requires a full linear scan of the entire values array just to confirm uniqueness, and that doesn't even account for the logic required to actually normalize it if it isn't. This isn't a bug — the Arrow spec does allow duplicate values in a dictionary's values array, but the absence of a normalization flag leaves performance on the table in cases where the builder already guarantees deduplication. This would be a simple, backwards-compatible addition that could meaningfully benefit downstream consumers. <!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] (This section helps Arrow developers understand the context and *why* for this feature, in addition to the *what*) --> **Describe the solution you'd like** <!-- A clear and concise description of what you want to happen. --> Add an **is_normalized** boolean flag to DictionaryArray, similar to the existing [is_ordered flag](https://github.com/apache/arrow-rs/blob/a3dbc154af4b9f6aebf38b4e5343fed176449a8e/arrow-array/src/array/dictionary_array.rs#L256), that denotes whether the values array is canonicalized. The change would be fully backwards compatible, the flag defaults to false for all existing dictionaries, and builders that already guarantee deduplication would set it to true at construction time. **_No existing behavior changes._** **Describe alternatives you've considered** <!-- A clear and concise description of any alternative solutions or features you've considered. --> Without this flag, downstream consumers must either perform a linear scan to verify uniqueness on every call or make unsafe assumptions about the dictionary's structure. Neither is ideal, one is expensive, the other is error-prone. ### Additional context <!-- Add any other context or screenshots about the feature request here. --> **Downstream Benefits** Implementations such as [DictionaryCountAccumulator](https://github.com/apache/datafusion/blob/f802ed1c51ad82cb1194d4f2bd3010ec451b2d38/datafusion/functions-aggregate-common/src/aggregate/count_distinct/dict.rs) stand to benefit from this improvement as well, currently it simply delegates accumulation work to an inner accumulator rather than taking advantage of the fact that the values array may already be unique. A normalization flag would allow such implementations to short-circuit redundant work entirely. On the aggregation side, hash aggregation in particular stands to benefit. Work like [#21765](https://github.com/apache/datafusion/pull/21765), which introduces a specialized GroupValuesDictionary path that operates directly on dictionary structure, could leverage this flag to avoid redundant uniqueness checks and unlock further optimizations when the values array is already known to be canonical. (also applies to the 2+ column grouping, even more so as the normalization cost only increases) **Arrow Ecosystem** It is also worth noting that widely used Parquet writers, including those in Arrow, Spark, and pandas already write deduplicated dictionaries by default. This is not forbidden by the spec, meaning normalized dictionaries are already common in practice, yet there is no way to communicate that guarantee programmatically. This proposal is fully backwards compatible with the [Arrow columnar format specification](https://github.com/apache/arrow/blob/main/docs/source/format/Columnar.rst) — the flag defaults to false for all existing dictionaries, no existing behavior changes, and consumers are free to ignore it entirely. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
