[Feature](agg) Add aggregate function entropy#60859
Closed
Conversation
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
Co-authored-by: zclllyybb <61408379+zclllyybb@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Review algorithm implementation for correctness and performance
[Feature](agg) Add aggregate function Feb 26, 2026
entropy
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.
Implements Shannon Entropy (base-2) as a new aggregate function, supporting single-column numeric/string types and multi-column generic inputs via serialized composite keys.
BE (
aggregate_function_entropy.h/.cpp)AggregateFunctionEntropyData<Value, Hash>: frequency map +total_countfield tracked incrementally soget_result()is a single pass (original two-pass design iterated the map twice).SingleNumericData<T>: direct typed value keySingleStringData: XXH128 hash of raw bytesGenericData: XXH128 hash of arena-serialized concatenation of all columns (multi-arg support)AggregateFunctionEntropy<Data>: markedfinal, inheritsVarargsExpression + NullableAggregateFunction; registered viaregister_function_both.FE (
Entropy.java)NullableAggregateFunctionwithvarArgs(AnyDataType)→DoubleType; wired intoBuiltinAggregateFunctionsandAggregateFunctionVisitor.visitEntropy.Test infrastructure fixes
agg_function_test.h: Guardsdeserialize_and_merge_from_column_rangewithblock.rows() != 0to preventsize_tunderflow on empty input (was passing0 - 1 = SIZE_MAXas end index).column_helper.h: Extends two-columncreate_blocktocreate_block<T1, T2 = T1>so mixed-type blocks (e.g.int+string) can be constructed in unit tests.Tests
Unit tests (
agg_entropy_test.cpp) cover numeric, string, multi-column generic, nullable (NULLs skipped), and empty-input cases via serialize/deserialize/merge round-trips. Regression suite (aggregate_function_entropy.groovy) exercises all SQL types including complex types,GROUP BY, and window functions.💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.