Repository navigation
Commit 8f0280b
authored
Document and enforce compatibility between an aggregate's accumulators (#25710)
## 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
`Closes #123` indicates that this PR will close issue #123.
-->
- Closes #25660.
## Rationale for this change
See #25660.
This change only documents/enforces this requirement for built-in
aggregate UDF functions. Anyone who implements their own aggregate UDFs
do not need to adhere to this requirement since vanilla datafusion
doesn't require it. This does add a public test that user's can use to
make sure this requirement is satisfied if they desire.
## What changes are included in this PR?
This change adds:
- Internal documentation explaining this requirement and how to check
for it using the provided test function.
-
`datafusion_functions_aggregate::testing::check_state_compatibility()`:
A generic test that identifies cases where the `Accumulator` and
`GroupsAccumulator` of an `AggregateUDF` differ. This is exposed as a
public function that can be used to test this requirement on
`AggregateUDFImpl`s implemented by downstream consumers. The test is run
on all built-in default aggregation functions.
- Fixes for `approx_distinct()` and `avg()`, which both violated this
requirement
- This takes the changes from #25659 to fix `approx_distinct()`
- The `Accumulator` for `avg()` would return `0` for the count if it
hasn't seen any non-null values. The `GroupsAccumulator` would return
`null` instead. This change updates the `Accumulator`s to also return
`null` for the count in this case.
## What is the testing strategy for this PR?
This adds a test to enforce this new requirement in a generic way.
<!--
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
Briefly describe how this PR is tested, and point to the specific tests
you added. For example: 'This new feature is covered by the
`sqllogictest` cases added in `foo.slt`'.
If this PR does not add tests, explain why. For example, if the change
is already covered by existing tests, please mention it.
You should also check the `codecov` bot reply on this PR to confirm the
changed code is exercised.
-->
## Are there any user-facing changes?
This changes the intermediate state of the `avg()` accumulator to match
the `avg()` groups accumulator, which some users may be affected by.
<!--
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.
-->1 parent 9dec775 commit 8f0280b
7 files changed
Lines changed: 909 additions & 64 deletions
File tree
- datafusion
- expr-common/src
- functions-aggregate
- src
- tests
- physical-plan/src/windows
- docs/source/contributor-guide
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
100 | | - | |
| 100 | + | |
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| |||
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
| 121 | + | |
121 | 122 | | |
122 | 123 | | |
123 | 124 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
129 | 188 | | |
130 | 189 | | |
131 | 190 | | |
| |||
166 | 225 | | |
167 | 226 | | |
168 | 227 | | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
| 228 | + | |
179 | 229 | | |
180 | 230 | | |
181 | 231 | | |
| |||
226 | 276 | | |
227 | 277 | | |
228 | 278 | | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
| 279 | + | |
239 | 280 | | |
240 | 281 | | |
241 | 282 | | |
| |||
335 | 376 | | |
336 | 377 | | |
337 | 378 | | |
338 | | - | |
339 | | - | |
| 379 | + | |
340 | 380 | | |
341 | | - | |
342 | | - | |
343 | | - | |
344 | | - | |
345 | | - | |
346 | | - | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | | - | |
352 | | - | |
353 | | - | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
354 | 384 | | |
355 | | - | |
356 | | - | |
357 | | - | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
362 | | - | |
363 | | - | |
364 | | - | |
365 | | - | |
366 | | - | |
367 | | - | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
368 | 390 | | |
369 | 391 | | |
370 | 392 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
653 | 653 | | |
654 | 654 | | |
655 | 655 | | |
656 | | - | |
657 | | - | |
658 | | - | |
659 | | - | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
660 | 664 | | |
661 | 665 | | |
662 | 666 | | |
| |||
833 | 837 | | |
834 | 838 | | |
835 | 839 | | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
836 | 847 | | |
837 | | - | |
838 | | - | |
| 848 | + | |
| 849 | + | |
839 | 850 | | |
840 | 851 | | |
841 | 852 | | |
| |||
916 | 927 | | |
917 | 928 | | |
918 | 929 | | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
919 | 937 | | |
920 | | - | |
921 | | - | |
922 | | - | |
923 | | - | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
924 | 942 | | |
925 | 943 | | |
926 | | - | |
| 944 | + | |
927 | 945 | | |
928 | 946 | | |
929 | 947 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| |||
92 | 93 | | |
93 | 94 | | |
94 | 95 | | |
| 96 | + | |
95 | 97 | | |
96 | 98 | | |
97 | 99 | | |
98 | 100 | | |
99 | 101 | | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
100 | 110 | | |
101 | 111 | | |
102 | 112 | | |
| |||
285 | 295 | | |
286 | 296 | | |
287 | 297 | | |
288 | | - | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
289 | 301 | | |
290 | 302 | | |
291 | 303 | | |
| |||
0 commit comments