From 74fd7fa01d42fd328dc2905e65719997c2cb20ab Mon Sep 17 00:00:00 2001 From: Peter Nguyen Date: Sun, 3 Nov 2024 08:59:33 -0800 Subject: [PATCH 1/7] Add camelCase alias for anyRespectNulls and anyLastRespectNulls --- src/AggregateFunctions/AggregateFunctionAnyRespectNulls.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/AggregateFunctions/AggregateFunctionAnyRespectNulls.cpp b/src/AggregateFunctions/AggregateFunctionAnyRespectNulls.cpp index 0b6642bffac..cc0d2cb38c8 100644 --- a/src/AggregateFunctions/AggregateFunctionAnyRespectNulls.cpp +++ b/src/AggregateFunctions/AggregateFunctionAnyRespectNulls.cpp @@ -223,9 +223,11 @@ void registerAggregateFunctionsAnyRespectNulls(AggregateFunctionFactory & factor factory.registerFunction("any_respect_nulls", {createAggregateFunctionAnyRespectNulls, default_properties_for_respect_nulls}); factory.registerAlias("any_value_respect_nulls", "any_respect_nulls", AggregateFunctionFactory::Case::Insensitive); factory.registerAlias("first_value_respect_nulls", "any_respect_nulls", AggregateFunctionFactory::Case::Insensitive); + factory.registerAlias("anyRespectNulls", "any_respect_nulls", AggregateFunctionFactory::Case::Sensitive); factory.registerFunction("anyLast_respect_nulls", {createAggregateFunctionAnyLastRespectNulls, default_properties_for_respect_nulls}); factory.registerAlias("last_value_respect_nulls", "anyLast_respect_nulls", AggregateFunctionFactory::Case::Insensitive); + factory.registerAlias("anyLastRespectNulls", "anyLast_respect_nulls", AggregateFunctionFactory::Case::Sensitive); /// Must happen after registering any and anyLast factory.registerNullsActionTransformation("any", "any_respect_nulls"); From 44130d67650334d41f5ef5bd1c0967314f4738fb Mon Sep 17 00:00:00 2001 From: Peter Nguyen Date: Sun, 3 Nov 2024 08:59:56 -0800 Subject: [PATCH 2/7] Add small note in docs for the alias --- docs/en/sql-reference/aggregate-functions/reference/anylast.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/en/sql-reference/aggregate-functions/reference/anylast.md b/docs/en/sql-reference/aggregate-functions/reference/anylast.md index 202d2e9fb10..f5b75e63399 100644 --- a/docs/en/sql-reference/aggregate-functions/reference/anylast.md +++ b/docs/en/sql-reference/aggregate-functions/reference/anylast.md @@ -18,6 +18,8 @@ anyLast(column) [RESPECT NULLS] :::note Supports the `RESPECT NULLS` modifier after the function name. Using this modifier will ensure the function selects the first value passed, regardless of whether it is `NULL` or not. + +Alias: anyLastRepectNulls ::: **Returned value** From 7d5fc90b19cc322c96eb7bbf6a1b08349c123266 Mon Sep 17 00:00:00 2001 From: Peter Nguyen Date: Sat, 16 Nov 2024 14:43:10 -0800 Subject: [PATCH 3/7] Add lastValueRespectNulls and firstValueRespectNulls aliases --- src/AggregateFunctions/AggregateFunctionAnyRespectNulls.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/AggregateFunctions/AggregateFunctionAnyRespectNulls.cpp b/src/AggregateFunctions/AggregateFunctionAnyRespectNulls.cpp index fe259f2a0f7..0c08eb9aa7d 100644 --- a/src/AggregateFunctions/AggregateFunctionAnyRespectNulls.cpp +++ b/src/AggregateFunctions/AggregateFunctionAnyRespectNulls.cpp @@ -224,10 +224,12 @@ void registerAggregateFunctionsAnyRespectNulls(AggregateFunctionFactory & factor factory.registerAlias("any_value_respect_nulls", "any_respect_nulls", AggregateFunctionFactory::Case::Insensitive); factory.registerAlias("first_value_respect_nulls", "any_respect_nulls", AggregateFunctionFactory::Case::Insensitive); factory.registerAlias("anyRespectNulls", "any_respect_nulls", AggregateFunctionFactory::Case::Sensitive); + factory.registerAlias("firstValueRespectNulls", "any_respect_nulls", AggregateFunctionFactory::Case::Sensitive); factory.registerFunction("anyLast_respect_nulls", {createAggregateFunctionAnyLastRespectNulls, default_properties_for_respect_nulls}); factory.registerAlias("last_value_respect_nulls", "anyLast_respect_nulls", AggregateFunctionFactory::Case::Insensitive); factory.registerAlias("anyLastRespectNulls", "anyLast_respect_nulls", AggregateFunctionFactory::Case::Sensitive); + factory.registerAlias("lastValueRespectNulls", "anyLast_respect_nulls", AggregateFunctionFactory::Case::Sensitive); /// Must happen after registering any and anyLast factory.registerNullsActionTransformation("any", "any_respect_nulls"); From 77d288a3e5d63f6c5b7dac0237348bde10939d01 Mon Sep 17 00:00:00 2001 From: Peter Nguyen Date: Sat, 16 Nov 2024 15:48:09 -0800 Subject: [PATCH 4/7] Add 03261_any_respect_camelCase_aliases.sql --- ...61_any_respect_camelCase_aliases.reference | 20 +++++++++++++ .../03261_any_respect_camelCase_aliases.sql | 28 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 tests/queries/0_stateless/03261_any_respect_camelCase_aliases.reference create mode 100644 tests/queries/0_stateless/03261_any_respect_camelCase_aliases.sql diff --git a/tests/queries/0_stateless/03261_any_respect_camelCase_aliases.reference b/tests/queries/0_stateless/03261_any_respect_camelCase_aliases.reference new file mode 100644 index 00000000000..1e71c0295cc --- /dev/null +++ b/tests/queries/0_stateless/03261_any_respect_camelCase_aliases.reference @@ -0,0 +1,20 @@ +0 +\N +\N +0 +6 +4 +\N +\N +0 +9 +0 +\N +\N +0 +6 +4 +\N +\N +0 +9 diff --git a/tests/queries/0_stateless/03261_any_respect_camelCase_aliases.sql b/tests/queries/0_stateless/03261_any_respect_camelCase_aliases.sql new file mode 100644 index 00000000000..b09b8b037a0 --- /dev/null +++ b/tests/queries/0_stateless/03261_any_respect_camelCase_aliases.sql @@ -0,0 +1,28 @@ + +-- anyRespectNulls +SELECT anyRespectNulls(number) from numbers(5); +SELECT arrayReduce('anyRespectNulls', [NULL, 10]::Array(Nullable(UInt8))); +SELECT anyRespectNullsMerge(t) FROM (SELECT anyRespectNullsState(NULL::Nullable(UInt8)) as t FROM numbers(5)); +SELECT finalizeAggregation(CAST(unhex('01'), 'AggregateFunction(anyRespectNulls, UInt64)')); +SELECT anyRespectNullsIf (number, NOT isNull(number) AND (assumeNotNull(number) > 5)) FROM numbers(10); + +-- anyLastRespectNulls +SELECT anyLastRespectNulls(number) from numbers(5); +SELECT arrayReduce('anyLastRespectNulls', [10, NULL]::Array(Nullable(UInt8))); +SELECT anyLastRespectNullsMerge(t) FROM (SELECT anyLastRespectNullsState(NULL::Nullable(UInt8)) as t FROM numbers(5)); +SELECT finalizeAggregation(CAST(unhex('01'), 'AggregateFunction(anyLastRespectNulls, UInt64)')); +SELECT anyLastRespectNullsIf (number, NOT isNull(number) AND (assumeNotNull(number) > 5)) FROM numbers(10); + +-- firstValueRespectNulls +SELECT firstValueRespectNulls(number) from numbers(5); +SELECT arrayReduce('firstValueRespectNulls', [NULL, 10]::Array(Nullable(UInt8))); +SELECT firstValueRespectNullsMerge(t) FROM (SELECT firstValueRespectNullsState(NULL::Nullable(UInt8)) as t FROM numbers(5)); +SELECT finalizeAggregation(CAST(unhex('01'), 'AggregateFunction(firstValueRespectNulls, UInt64)')); +SELECT firstValueRespectNullsIf (number, NOT isNull(number) AND (assumeNotNull(number) > 5)) FROM numbers(10); + +-- lastValueRespectNulls +SELECT lastValueRespectNulls(number) from numbers(5); +SELECT arrayReduce('lastValueRespectNulls', [10, NULL]::Array(Nullable(UInt8))); +SELECT lastValueRespectNullsMerge(t) FROM (SELECT lastValueRespectNullsState(NULL::Nullable(UInt8)) as t FROM numbers(5)); +SELECT finalizeAggregation(CAST(unhex('01'), 'AggregateFunction(lastValueRespectNulls, UInt64)')); +SELECT lastValueRespectNullsIf (number, NOT isNull(number) AND (assumeNotNull(number) > 5)) FROM numbers(10); From f9431a3150aef6b68a9f0b5e06fd6b3ff3b6cb0e Mon Sep 17 00:00:00 2001 From: Peter Nguyen Date: Sat, 16 Nov 2024 15:49:35 -0800 Subject: [PATCH 5/7] Update docs for any, anyLast, first_value, and last_value --- .../aggregate-functions/reference/any.md | 12 +++++++----- .../aggregate-functions/reference/anylast.md | 12 ++++++------ .../en/sql-reference/window-functions/first_value.md | 6 ++++-- docs/en/sql-reference/window-functions/last_value.md | 6 ++++-- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/docs/en/sql-reference/aggregate-functions/reference/any.md b/docs/en/sql-reference/aggregate-functions/reference/any.md index 972263585f2..f7bc375b381 100644 --- a/docs/en/sql-reference/aggregate-functions/reference/any.md +++ b/docs/en/sql-reference/aggregate-functions/reference/any.md @@ -21,7 +21,9 @@ Aliases: `any_value`, [`first_value`](../reference/first_value.md). **Returned value** :::note -Supports the `RESPECT NULLS` modifier after the function name. Using this modifier will ensure the function selects the first value passed, regardless of whether it is `NULL` or not. +By default, the `anyLast` function never returns `NULL`. However, it supports the `RESPECT NULLS` modifier after the function name. Using this modifier will ensure the function selects the first value passed, regardless of whether it is `NULL` or not. + +Alias: `anyRespectNulls` ::: :::note @@ -48,11 +50,11 @@ CREATE TABLE any_nulls (city Nullable(String)) ENGINE=Log; INSERT INTO any_nulls (city) VALUES (NULL), ('Amsterdam'), ('New York'), ('Tokyo'), ('Valencia'), (NULL); -SELECT any(city) FROM any_nulls; +SELECT any(city), anyRespectNulls(city) FROM any_nulls; ``` ```response -┌─any(city)─┐ -│ Amsterdam │ -└───────────┘ +┌─any(city)─┬─anyRespectNulls(city)─┐ +│ Amsterdam │ ᴺᵁᴸᴸ │ +└───────────┴───────────────────────┘ ``` diff --git a/docs/en/sql-reference/aggregate-functions/reference/anylast.md b/docs/en/sql-reference/aggregate-functions/reference/anylast.md index fd0bc5c23e1..48cb7124fca 100644 --- a/docs/en/sql-reference/aggregate-functions/reference/anylast.md +++ b/docs/en/sql-reference/aggregate-functions/reference/anylast.md @@ -18,9 +18,9 @@ anyLast(column) [RESPECT NULLS] :::note -Supports the `RESPECT NULLS` modifier after the function name. Using this modifier will ensure the function selects the last value passed, regardless of whether it is `NULL` or not. +By default, the `anyLast` function never returns `NULL`. However, it supports the `RESPECT NULLS `modifier after the function name, which will ensure the function selects the last value passed, regardless of whether it is `NULL` or not. -Alias: `anyLastRepectNulls` +Alias: `anyLastRespectNulls` ::: **Returned value** @@ -36,11 +36,11 @@ CREATE TABLE any_last_nulls (city Nullable(String)) ENGINE=Log; INSERT INTO any_last_nulls (city) VALUES ('Amsterdam'),(NULL),('New York'),('Tokyo'),('Valencia'),(NULL); -SELECT anyLast(city) FROM any_last_nulls; +SELECT anyLast(city), anyLastRespectNulls(city) FROM any_last_nulls; ``` ```response -┌─anyLast(city)─┐ -│ Valencia │ -└───────────────┘ +┌─anyLast(city)─┬─anyLastRespectNulls(city)─┐ +│ Valencia │ ᴺᵁᴸᴸ │ +└───────────────┴───────────────────────────┘ ``` diff --git a/docs/en/sql-reference/window-functions/first_value.md b/docs/en/sql-reference/window-functions/first_value.md index 30c3b1f99dc..c6e978bfc92 100644 --- a/docs/en/sql-reference/window-functions/first_value.md +++ b/docs/en/sql-reference/window-functions/first_value.md @@ -15,7 +15,7 @@ first_value (column_name) [[RESPECT NULLS] | [IGNORE NULLS]] OVER ([[PARTITION BY grouping_column] [ORDER BY sorting_column] [ROWS or RANGE expression_to_bound_rows_withing_the_group]] | [window_name]) FROM table_name -WINDOW window_name as ([[PARTITION BY grouping_column] [ORDER BY sorting_column]) +WINDOW window_name as ([PARTITION BY grouping_column] [ORDER BY sorting_column]) ``` Alias: `any`. @@ -23,6 +23,8 @@ Alias: `any`. :::note Using the optional modifier `RESPECT NULLS` after `first_value(column_name)` will ensure that `NULL` arguments are not skipped. See [NULL processing](../aggregate-functions/index.md/#null-processing) for more information. + +Alias: `firstValueRespectNulls` ::: For more detail on window function syntax see: [Window Functions - Syntax](./index.md/#syntax). @@ -48,7 +50,7 @@ CREATE TABLE salaries ) Engine = Memory; -INSERT INTO salaries FORMAT Values +INSERT INTO salaries FORMAT VALUES ('Port Elizabeth Barbarians', 'Gary Chen', 196000, 'F'), ('New Coreystad Archdukes', 'Charles Juarez', 190000, 'F'), ('Port Elizabeth Barbarians', 'Michael Stanley', 100000, 'D'), diff --git a/docs/en/sql-reference/window-functions/last_value.md b/docs/en/sql-reference/window-functions/last_value.md index dd7f5fa078a..9f3ef8ba4f6 100644 --- a/docs/en/sql-reference/window-functions/last_value.md +++ b/docs/en/sql-reference/window-functions/last_value.md @@ -23,6 +23,8 @@ Alias: `anyLast`. :::note Using the optional modifier `RESPECT NULLS` after `first_value(column_name)` will ensure that `NULL` arguments are not skipped. See [NULL processing](../aggregate-functions/index.md/#null-processing) for more information. + +Alias: `lastValueRespectNulls` ::: For more detail on window function syntax see: [Window Functions - Syntax](./index.md/#syntax). @@ -33,7 +35,7 @@ For more detail on window function syntax see: [Window Functions - Syntax](./ind **Example** -In this example the `last_value` function is used to find the highest paid footballer from a fictional dataset of salaries of Premier League football players. +In this example the `last_value` function is used to find the lowest paid footballer from a fictional dataset of salaries of Premier League football players. Query: @@ -48,7 +50,7 @@ CREATE TABLE salaries ) Engine = Memory; -INSERT INTO salaries FORMAT Values +INSERT INTO salaries FORMAT VALUES ('Port Elizabeth Barbarians', 'Gary Chen', 196000, 'F'), ('New Coreystad Archdukes', 'Charles Juarez', 190000, 'F'), ('Port Elizabeth Barbarians', 'Michael Stanley', 100000, 'D'), From 082d63904315b71eee534c289bf3ce722a603a8b Mon Sep 17 00:00:00 2001 From: Peter Nguyen Date: Sat, 16 Nov 2024 20:38:18 -0800 Subject: [PATCH 6/7] Empty commit From 3bdd4a5173e0a87318d99d5f3540f61fb9fe560d Mon Sep 17 00:00:00 2001 From: Robert Schulze Date: Sun, 17 Nov 2024 10:10:51 +0000 Subject: [PATCH 7/7] Consistency fixups --- .../aggregate-functions/reference/any.md | 49 ++++++++++++------- .../aggregate-functions/reference/anylast.md | 32 +++++++----- .../AggregateFunctionAnyRespectNulls.cpp | 7 +-- ...61_any_respect_camelCase_aliases.reference | 20 ++++++-- .../03261_any_respect_camelCase_aliases.sql | 38 +++++++++----- 5 files changed, 94 insertions(+), 52 deletions(-) diff --git a/docs/en/sql-reference/aggregate-functions/reference/any.md b/docs/en/sql-reference/aggregate-functions/reference/any.md index f7bc375b381..e7bebd4d460 100644 --- a/docs/en/sql-reference/aggregate-functions/reference/any.md +++ b/docs/en/sql-reference/aggregate-functions/reference/any.md @@ -5,7 +5,15 @@ sidebar_position: 102 # any -Selects the first encountered value of a column, ignoring any `NULL` values. +Selects the first encountered value of a column. + +:::warning +As a query can be executed in arbitrary order, the result of this function is non-deterministic. +If you need an arbitrary but deterministic result, use functions [`min`](../reference/min.md) or [`max`](../reference/max.md). +::: + +By default, the function never returns NULL, i.e. ignores NULL values in the input column. +However, if the function is used with the `RESPECT NULLS` modifier, it returns the first value reads no matter if NULL or not. **Syntax** @@ -13,44 +21,47 @@ Selects the first encountered value of a column, ignoring any `NULL` values. any(column) [RESPECT NULLS] ``` -Aliases: `any_value`, [`first_value`](../reference/first_value.md). +Aliases `any(column)` (without `RESPECT NULLS`) +- `any_value` +- [`first_value`](../reference/first_value.md). + +Alias for `any(column) RESPECT NULLS` +- `anyRespectNulls`, `any_respect_nulls` +- `firstValueRespectNulls`, `first_value_respect_nulls` +- `anyValueRespectNulls`, `any_value_respect_nulls` **Parameters** -- `column`: The column name. +- `column`: The column name. **Returned value** -:::note -By default, the `anyLast` function never returns `NULL`. However, it supports the `RESPECT NULLS` modifier after the function name. Using this modifier will ensure the function selects the first value passed, regardless of whether it is `NULL` or not. - -Alias: `anyRespectNulls` -::: +The first value encountered. :::note -The return type of the function is the same as the input, except for LowCardinality which is discarded. This means that given no rows as input it will return the default value of that type (0 for integers, or Null for a Nullable() column). You might use the `-OrNull` [combinator](../../../sql-reference/aggregate-functions/combinators.md) ) to modify this behaviour. -::: - -:::warning -The query can be executed in any order and even in a different order each time, so the result of this function is indeterminate. -To get a determinate result, you can use the [`min`](../reference/min.md) or [`max`](../reference/max.md) function instead of `any`. +The return type of the function is the same as the input, except for LowCardinality which is discarded. +This means that given no rows as input it will return the default value of that type (0 for integers, or Null for a Nullable() column). +You might use the `-OrNull` [combinator](../../../sql-reference/aggregate-functions/combinators.md) ) to modify this behaviour. ::: **Implementation details** -In some cases, you can rely on the order of execution. This applies to cases when `SELECT` comes from a subquery that uses `ORDER BY`. +In some cases, you can rely on the order of execution. +This applies to cases when `SELECT` comes from a subquery that uses `ORDER BY`. -When a `SELECT` query has the `GROUP BY` clause or at least one aggregate function, ClickHouse (in contrast to MySQL) requires that all expressions in the `SELECT`, `HAVING`, and `ORDER BY` clauses be calculated from keys or from aggregate functions. In other words, each column selected from the table must be used either in keys or inside aggregate functions. To get behavior like in MySQL, you can put the other columns in the `any` aggregate function. +When a `SELECT` query has the `GROUP BY` clause or at least one aggregate function, ClickHouse (in contrast to MySQL) requires that all expressions in the `SELECT`, `HAVING`, and `ORDER BY` clauses be calculated from keys or from aggregate functions. +In other words, each column selected from the table must be used either in keys or inside aggregate functions. +To get behavior like in MySQL, you can put the other columns in the `any` aggregate function. **Example** Query: ```sql -CREATE TABLE any_nulls (city Nullable(String)) ENGINE=Log; +CREATE TABLE tab (city Nullable(String)) ENGINE=Memory; -INSERT INTO any_nulls (city) VALUES (NULL), ('Amsterdam'), ('New York'), ('Tokyo'), ('Valencia'), (NULL); +INSERT INTO tab (city) VALUES (NULL), ('Amsterdam'), ('New York'), ('Tokyo'), ('Valencia'), (NULL); -SELECT any(city), anyRespectNulls(city) FROM any_nulls; +SELECT any(city), anyRespectNulls(city) FROM tab; ``` ```response diff --git a/docs/en/sql-reference/aggregate-functions/reference/anylast.md b/docs/en/sql-reference/aggregate-functions/reference/anylast.md index 48cb7124fca..3d80533e146 100644 --- a/docs/en/sql-reference/aggregate-functions/reference/anylast.md +++ b/docs/en/sql-reference/aggregate-functions/reference/anylast.md @@ -5,7 +5,15 @@ sidebar_position: 105 # anyLast -Selects the last value encountered, ignoring any `NULL` values by default. The result is just as indeterminate as for the [any](../../../sql-reference/aggregate-functions/reference/any.md) function. +Selects the last encountered value of a column. + +:::warning +As a query can be executed in arbitrary order, the result of this function is non-deterministic. +If you need an arbitrary but deterministic result, use functions [`min`](../reference/min.md) or [`max`](../reference/max.md). +::: + +By default, the function never returns NULL, i.e. ignores NULL values in the input column. +However, if the function is used with the `RESPECT NULLS` modifier, it returns the first value reads no matter if NULL or not. **Syntax** @@ -13,15 +21,15 @@ Selects the last value encountered, ignoring any `NULL` values by default. The r anyLast(column) [RESPECT NULLS] ``` +Alias `anyLast(column)` (without `RESPECT NULLS`) +- [`last_value`](../reference/last_value.md). + +Aliases for `anyLast(column) RESPECT NULLS` +- `anyLastRespectNulls`, `anyLast_respect_nulls` +- `lastValueRespectNulls`, `last_value_respect_nulls` + **Parameters** -- `column`: The column name. - -:::note - -By default, the `anyLast` function never returns `NULL`. However, it supports the `RESPECT NULLS `modifier after the function name, which will ensure the function selects the last value passed, regardless of whether it is `NULL` or not. - -Alias: `anyLastRespectNulls` -::: +- `column`: The column name. **Returned value** @@ -32,11 +40,11 @@ Alias: `anyLastRespectNulls` Query: ```sql -CREATE TABLE any_last_nulls (city Nullable(String)) ENGINE=Log; +CREATE TABLE tab (city Nullable(String)) ENGINE=Memory; -INSERT INTO any_last_nulls (city) VALUES ('Amsterdam'),(NULL),('New York'),('Tokyo'),('Valencia'),(NULL); +INSERT INTO tab (city) VALUES ('Amsterdam'),(NULL),('New York'),('Tokyo'),('Valencia'),(NULL); -SELECT anyLast(city), anyLastRespectNulls(city) FROM any_last_nulls; +SELECT anyLast(city), anyLastRespectNulls(city) FROM tab; ``` ```response diff --git a/src/AggregateFunctions/AggregateFunctionAnyRespectNulls.cpp b/src/AggregateFunctions/AggregateFunctionAnyRespectNulls.cpp index 0c08eb9aa7d..83fc98ada11 100644 --- a/src/AggregateFunctions/AggregateFunctionAnyRespectNulls.cpp +++ b/src/AggregateFunctions/AggregateFunctionAnyRespectNulls.cpp @@ -221,14 +221,15 @@ void registerAggregateFunctionsAnyRespectNulls(AggregateFunctionFactory & factor = {.returns_default_when_only_null = false, .is_order_dependent = true, .is_window_function = true}; factory.registerFunction("any_respect_nulls", {createAggregateFunctionAnyRespectNulls, default_properties_for_respect_nulls}); - factory.registerAlias("any_value_respect_nulls", "any_respect_nulls", AggregateFunctionFactory::Case::Insensitive); - factory.registerAlias("first_value_respect_nulls", "any_respect_nulls", AggregateFunctionFactory::Case::Insensitive); factory.registerAlias("anyRespectNulls", "any_respect_nulls", AggregateFunctionFactory::Case::Sensitive); + factory.registerAlias("first_value_respect_nulls", "any_respect_nulls", AggregateFunctionFactory::Case::Insensitive); factory.registerAlias("firstValueRespectNulls", "any_respect_nulls", AggregateFunctionFactory::Case::Sensitive); + factory.registerAlias("any_value_respect_nulls", "any_respect_nulls", AggregateFunctionFactory::Case::Insensitive); + factory.registerAlias("anyValueRespectNulls", "any_respect_nulls", AggregateFunctionFactory::Case::Sensitive); factory.registerFunction("anyLast_respect_nulls", {createAggregateFunctionAnyLastRespectNulls, default_properties_for_respect_nulls}); - factory.registerAlias("last_value_respect_nulls", "anyLast_respect_nulls", AggregateFunctionFactory::Case::Insensitive); factory.registerAlias("anyLastRespectNulls", "anyLast_respect_nulls", AggregateFunctionFactory::Case::Sensitive); + factory.registerAlias("last_value_respect_nulls", "anyLast_respect_nulls", AggregateFunctionFactory::Case::Insensitive); factory.registerAlias("lastValueRespectNulls", "anyLast_respect_nulls", AggregateFunctionFactory::Case::Sensitive); /// Must happen after registering any and anyLast diff --git a/tests/queries/0_stateless/03261_any_respect_camelCase_aliases.reference b/tests/queries/0_stateless/03261_any_respect_camelCase_aliases.reference index 1e71c0295cc..39f78128b24 100644 --- a/tests/queries/0_stateless/03261_any_respect_camelCase_aliases.reference +++ b/tests/queries/0_stateless/03261_any_respect_camelCase_aliases.reference @@ -1,18 +1,28 @@ +anyRespectNulls 0 \N \N 0 6 -4 -\N -\N -0 -9 +firstValueRespectNulls 0 \N \N 0 6 +anyValueRespectNulls +0 +\N +\N +0 +6 +lastValueRespectNulls +4 +\N +\N +0 +9 +anyLastRespectNulls 4 \N \N diff --git a/tests/queries/0_stateless/03261_any_respect_camelCase_aliases.sql b/tests/queries/0_stateless/03261_any_respect_camelCase_aliases.sql index b09b8b037a0..c56f096242c 100644 --- a/tests/queries/0_stateless/03261_any_respect_camelCase_aliases.sql +++ b/tests/queries/0_stateless/03261_any_respect_camelCase_aliases.sql @@ -1,28 +1,40 @@ +-- Tests aliases of any and anyLast functions --- anyRespectNulls -SELECT anyRespectNulls(number) from numbers(5); +-- aliases of any + +SELECT 'anyRespectNulls'; +SELECT anyRespectNulls(number) FROM numbers(5); SELECT arrayReduce('anyRespectNulls', [NULL, 10]::Array(Nullable(UInt8))); SELECT anyRespectNullsMerge(t) FROM (SELECT anyRespectNullsState(NULL::Nullable(UInt8)) as t FROM numbers(5)); SELECT finalizeAggregation(CAST(unhex('01'), 'AggregateFunction(anyRespectNulls, UInt64)')); SELECT anyRespectNullsIf (number, NOT isNull(number) AND (assumeNotNull(number) > 5)) FROM numbers(10); --- anyLastRespectNulls -SELECT anyLastRespectNulls(number) from numbers(5); -SELECT arrayReduce('anyLastRespectNulls', [10, NULL]::Array(Nullable(UInt8))); -SELECT anyLastRespectNullsMerge(t) FROM (SELECT anyLastRespectNullsState(NULL::Nullable(UInt8)) as t FROM numbers(5)); -SELECT finalizeAggregation(CAST(unhex('01'), 'AggregateFunction(anyLastRespectNulls, UInt64)')); -SELECT anyLastRespectNullsIf (number, NOT isNull(number) AND (assumeNotNull(number) > 5)) FROM numbers(10); - --- firstValueRespectNulls -SELECT firstValueRespectNulls(number) from numbers(5); +SELECT 'firstValueRespectNulls'; +SELECT firstValueRespectNulls(number) FROM numbers(5); SELECT arrayReduce('firstValueRespectNulls', [NULL, 10]::Array(Nullable(UInt8))); SELECT firstValueRespectNullsMerge(t) FROM (SELECT firstValueRespectNullsState(NULL::Nullable(UInt8)) as t FROM numbers(5)); SELECT finalizeAggregation(CAST(unhex('01'), 'AggregateFunction(firstValueRespectNulls, UInt64)')); SELECT firstValueRespectNullsIf (number, NOT isNull(number) AND (assumeNotNull(number) > 5)) FROM numbers(10); --- lastValueRespectNulls -SELECT lastValueRespectNulls(number) from numbers(5); +SELECT 'anyValueRespectNulls'; +SELECT anyValueRespectNulls(number) FROM numbers(5); +SELECT arrayReduce('anyValueRespectNulls', [NULL, 10]::Array(Nullable(UInt8))); +SELECT anyValueRespectNullsMerge(t) FROM (SELECT anyValueRespectNullsState(NULL::Nullable(UInt8)) as t FROM numbers(5)); +SELECT finalizeAggregation(CAST(unhex('01'), 'AggregateFunction(anyValueRespectNulls, UInt64)')); +SELECT anyValueRespectNullsIf (number, NOT isNull(number) AND (assumeNotNull(number) > 5)) FROM numbers(10); + +-- aliases of anyLast + +SELECT 'lastValueRespectNulls'; +SELECT lastValueRespectNulls(number) FROM numbers(5); SELECT arrayReduce('lastValueRespectNulls', [10, NULL]::Array(Nullable(UInt8))); SELECT lastValueRespectNullsMerge(t) FROM (SELECT lastValueRespectNullsState(NULL::Nullable(UInt8)) as t FROM numbers(5)); SELECT finalizeAggregation(CAST(unhex('01'), 'AggregateFunction(lastValueRespectNulls, UInt64)')); SELECT lastValueRespectNullsIf (number, NOT isNull(number) AND (assumeNotNull(number) > 5)) FROM numbers(10); + +SELECT 'anyLastRespectNulls'; +SELECT anyLastRespectNulls(number) FROM numbers(5); +SELECT arrayReduce('anyLastRespectNulls', [10, NULL]::Array(Nullable(UInt8))); +SELECT anyLastRespectNullsMerge(t) FROM (SELECT anyLastRespectNullsState(NULL::Nullable(UInt8)) as t FROM numbers(5)); +SELECT finalizeAggregation(CAST(unhex('01'), 'AggregateFunction(anyLastRespectNulls, UInt64)')); +SELECT anyLastRespectNullsIf (number, NOT isNull(number) AND (assumeNotNull(number) > 5)) FROM numbers(10);