Add aggregate function combinators: -OrNull & -OrDefault#7331
Add aggregate function combinators: -OrNull & -OrDefault#7331akuzm merged 6 commits intoClickHouse:masterfrom
Conversation
|
See also #6741 |
|
Looks very useful. Please add a mention of these combinators to the docs (it would be in docs/en/query_language/agg_functions/combinators.md). A recent related issue: #7336 |
| private: | ||
| AggregateFunctionPtr nested_function; | ||
|
|
||
| size_t sod; |
There was a problem hiding this comment.
Let's use a full name like size_of_data.
| @@ -0,0 +1,173 @@ | |||
| #pragma once | |||
There was a problem hiding this comment.
| #pragma once | |
| /** | |
| * -OrNull and -OrDefault combinators for aggregate functions. | |
| * If there are no input values, return NULL or a default value, accordingly. | |
| * Use a single additional byte of data after the nested function data: | |
| * 0 means there was no input, 1 means there was some. | |
| */ | |
| #pragma once |
|
|
||
| size_t sizeOfData() const override | ||
| { | ||
| return sod + sizeof(bool); |
There was a problem hiding this comment.
sizeof(bool) is implementation-defined, may be greater that 1. Maybe we should decide that our marker is char and just use 1 here?
| SELECT arrayReduce('maxOrDefault', arrayPopBack(['hello'])); | ||
| SELECT arrayReduce('maxOrNull', arrayPopBack(['hello'])); | ||
|
|
||
| SELECT arrayReduce('maxOrDefault', arrayPopBack(arrayPopBack([toDateTime('2011-04-05 14:19:19'), null]))); |
There was a problem hiding this comment.
JFYI, this can be written more explicitly with cast, like SELECT arrayReduce('maxOrDefault', cast([], 'Array(Nullable(DateTime))'));
You don't have to change it, the current way is also OK.
|
I'm not sure about the Maybe |
|
@akuzm |
akuzm
left a comment
There was a problem hiding this comment.
@alexey-milovidov says orDefault is OK, so let's merge.
I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en
For changelog. Remove if this is non-significant change.
Category (leave one):
Short description (up to few sentences):
Add aggregate function combinators which fill null or default value when there is nothing to aggregate.