From bec25f1682c9e9d0058b22f41ecbb4c8b758ae7f Mon Sep 17 00:00:00 2001 From: maxvostrikov Date: Wed, 18 Dec 2024 12:19:06 +0100 Subject: [PATCH 1/2] Added some tests with meta-array functions Added some tests with meta-array functions, related to https://github.com/ClickHouse/ClickHouse/pull/70093 Also added tests for ArrayLast --- ...unctions_higher_order_and_consts.reference | 387 ++++++++++++++++++ ...0182_functions_higher_order_and_consts.sql | 51 +++ 2 files changed, 438 insertions(+) diff --git a/tests/queries/0_stateless/00182_functions_higher_order_and_consts.reference b/tests/queries/0_stateless/00182_functions_higher_order_and_consts.reference index 79e0ef261d0..cccaabd394c 100644 --- a/tests/queries/0_stateless/00182_functions_higher_order_and_consts.reference +++ b/tests/queries/0_stateless/00182_functions_higher_order_and_consts.reference @@ -1,6 +1,11 @@ +--{echoOn} +SELECT '---map--'; ---map-- +SELECT arrayMap(x -> 123, emptyArrayUInt8()); [] +SELECT arrayMap(x -> 123, [1, 2, 3]); [123,123,123] +SELECT arrayMap(x -> 123, range(number)) FROM system.numbers LIMIT 10; [] [123] [123,123] @@ -11,9 +16,17 @@ [123,123,123,123,123,123,123] [123,123,123,123,123,123,123,123] [123,123,123,123,123,123,123,123,123] +SELECT arrayMap(x -> x, range(number)) FROM system.numbers LIMIT 3; +[] +[0] +[0,1] +SELECT '---filter--'; ---filter-- +SELECT arrayFilter(x -> 0, emptyArrayUInt8()); [] +SELECT arrayFilter(x -> 0, [1, 2, 3]); [] +SELECT arrayFilter(x -> 0, range(number)) FROM system.numbers LIMIT 10; [] [] [] @@ -24,8 +37,11 @@ [] [] [] +SELECT arrayFilter(x -> 1, emptyArrayUInt8()); [] +SELECT arrayFilter(x -> 1, [1, 2, 3]); [1,2,3] +SELECT arrayFilter(x -> 1, range(number)) FROM system.numbers LIMIT 10; [] [0] [0,1] @@ -36,9 +52,20 @@ [0,1,2,3,4,5,6] [0,1,2,3,4,5,6,7] [0,1,2,3,4,5,6,7,8] +SELECT arrayFilter(x -> x > 1, [1, 2, 3]); +[2,3] +SELECT arrayFilter(x -> x > 2, [1, 2, 3]); +[3] +SELECT arrayFilter(x -> NULL, [1, 2, 3]); +[] +SELECT arrayFilter(x -> 'string', [1, 2, 3]); -- { serverError ILLEGAL_TYPE_OF_ARGUMENT } +SELECT '---count---'; ---count--- +SELECT arrayCount(x -> 0, emptyArrayUInt8()); 0 +SELECT arrayCount(x -> 0, [1, 2, 3]); 0 +SELECT arrayCount(x -> 0, range(number)) FROM system.numbers LIMIT 10; 0 0 0 @@ -49,8 +76,11 @@ 0 0 0 +SELECT arrayCount(x -> 1, emptyArrayUInt8()); 0 +SELECT arrayCount(x -> 1, [1, 2, 3]); 3 +SELECT arrayCount(x -> 1, range(number)) FROM system.numbers LIMIT 10; 0 1 2 @@ -61,9 +91,20 @@ 7 8 9 +SELECT arrayCount(x -> x > 0, [1, 2, 3]); +3 +SELECT arrayCount(x -> x > 1, [1, 2, 3]); +2 +SELECT arrayCount(x -> NULL, [1, 2, 3]); +0 +SELECT arrayCount(x -> 'string', [1, 2, 3]); -- { serverError ILLEGAL_TYPE_OF_ARGUMENT } +SELECT '---sum---'; ---sum--- +SELECT arraySum(x -> 0, emptyArrayUInt8()); 0 +SELECT arraySum(x -> 0, [1, 2, 3]); 0 +SELECT arraySum(x -> 0, range(number)) FROM system.numbers LIMIT 10; 0 0 0 @@ -74,8 +115,11 @@ 0 0 0 +SELECT arraySum(x -> 10, emptyArrayUInt8()); 0 +SELECT arraySum(x -> 10, [1, 2, 3]); 30 +SELECT arraySum(x -> 10, range(number)) FROM system.numbers LIMIT 10; 0 10 20 @@ -86,9 +130,13 @@ 70 80 90 +SELECT '---all---'; ---all--- +SELECT arrayAll(x -> 0, emptyArrayUInt8()); 1 +SELECT arrayAll(x -> 0, [1, 2, 3]); 0 +SELECT arrayAll(x -> 0, range(number)) FROM system.numbers LIMIT 10; 1 0 0 @@ -99,7 +147,11 @@ 0 0 0 +SELECT arrayAll(x -> 1, emptyArrayUInt8()); +1 +SELECT arrayAll(x -> 1, [1, 2, 3]); 1 +SELECT arrayAll(x -> 1, range(number)) FROM system.numbers LIMIT 10; 1 1 1 @@ -110,10 +162,22 @@ 1 1 1 +SELECT arrayAll(x -> x > 0, [1, 2, 3]); +1 +SELECT arrayAll(x -> x > 1, [1, 2, 3]); +0 +SELECT arrayAll(x -> x, [1, 2, 3]); 1 +SELECT arrayAll(x -> NULL, [1, 2, 3]); +0 +SELECT arrayAll(x -> 'string', [1, 2, 3]); -- { serverError ILLEGAL_TYPE_OF_ARGUMENT } +SELECT '---exists---'; ---exists--- +SELECT arrayExists(x -> 0, emptyArrayUInt8()); 0 +SELECT arrayExists(x -> 0, [1, 2, 3]); 0 +SELECT arrayExists(x -> 0, range(number)) FROM system.numbers LIMIT 10; 0 0 0 @@ -124,8 +188,11 @@ 0 0 0 +SELECT arrayExists(x -> 1, emptyArrayUInt8()); 0 +SELECT arrayExists(x -> 1, [1, 2, 3]); 1 +SELECT arrayExists(x -> 1, range(number)) FROM system.numbers LIMIT 10; 0 1 1 @@ -136,11 +203,29 @@ 1 1 1 +SELECT '---first---'; ---first--- +SELECT arrayFirst(x -> 0, emptyArrayUInt8()); +0 +SELECT arrayFirst(x -> 0, [1, 2, 3]); +0 +SELECT arrayFirst(x -> 0, range(number)) FROM system.numbers LIMIT 10; +0 +0 +0 +0 +0 +0 0 0 0 0 +SELECT arrayFirst(x -> 1, emptyArrayUInt8()); +0 +SELECT arrayFirst(x -> 1, [1, 2, 3]); +1 +SELECT arrayFirst(x -> 1, range(number)) FROM system.numbers LIMIT 10; +0 0 0 0 @@ -150,7 +235,23 @@ 0 0 0 +SELECT arrayFirst(x -> x > 1, [1, 2, 3]); +2 +SELECT arrayFirst(x -> x > 3, [1, 2, 3]); +0 +SELECT arrayFirst(x -> x, [1, 2, 3]); 1 +SELECT arrayFirst(x -> NULL, [1, 2, 3]); -- { serverError ILLEGAL_COLUMN } +SELECT arrayFirst(x -> 'string', [1, 2, 3]); -- { serverError ILLEGAL_COLUMN } +SELECT '---last---'; +---last--- +SELECT arrayLast(x -> 0, emptyArrayUInt8()); +0 +SELECT arrayLast(x -> 0, [1, 2, 3]); +0 +SELECT arrayLast(x -> 0, range(number)) FROM system.numbers LIMIT 10; +0 +0 0 0 0 @@ -159,11 +260,36 @@ 0 0 0 +SELECT arrayLast(x -> 1, emptyArrayUInt8()); +0 +SELECT arrayLast(x -> 1, [1, 2, 3]); +3 +SELECT arrayLast(x -> 1, range(number)) FROM system.numbers LIMIT 10; 0 0 +1 +2 +3 +4 +5 +6 +7 +8 +SELECT arrayLast(x -> x > 1, [1, 2, 3]); +3 +SELECT arrayLast(x -> x > 3, [1, 2, 3]); +0 +SELECT arrayLast(x -> x, [1, 2, 3]); +3 +SELECT arrayLast(x -> NULL, [1, 2, 3]); -- { serverError ILLEGAL_COLUMN } +SELECT arrayLast(x -> 'string', [1, 2, 3]); -- { serverError ILLEGAL_COLUMN } +SELECT '---first index---'; ---first index--- +SELECT arrayFirstIndex(x -> 0, emptyArrayUInt8()); 0 +SELECT arrayFirstIndex(x -> 0, [1, 2, 3]); 0 +SELECT arrayFirstIndex(x -> 0, range(number)) FROM system.numbers LIMIT 10; 0 0 0 @@ -174,8 +300,11 @@ 0 0 0 +SELECT arrayFirstIndex(x -> 1, emptyArrayUInt8()); 0 +SELECT arrayFirstIndex(x -> 1, [1, 2, 3]); 1 +SELECT arrayFirstIndex(x -> 1, range(number)) FROM system.numbers LIMIT 10; 0 1 1 @@ -186,9 +315,61 @@ 1 1 1 +SELECT arrayFirstIndex(x -> x > 1, [1, 2, 3]); +2 +SELECT arrayFirstIndex(x -> x > 3, [1, 2, 3]); +0 +SELECT arrayFirstIndex(x -> x, [1, 2, 3]); +1 +SELECT arrayFirstIndex(x -> NULL, [1, 2, 3]); -- { serverError ILLEGAL_COLUMN } +SELECT arrayFirstIndex(x -> 'string', [1, 2, 3]); -- { serverError ILLEGAL_COLUMN } +SELECT '---lastindex---'; +---lastindex--- +SELECT arrayLastIndex(x -> 0, emptyArrayUInt8()); +0 +SELECT arrayLastIndex(x -> 0, [1, 2, 3]); +0 +SELECT arrayLastIndex(x -> 0, range(number)) FROM system.numbers LIMIT 10; +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +SELECT arrayLastIndex(x -> 1, emptyArrayUInt8()); +0 +SELECT arrayLastIndex(x -> 1, [1, 2, 3]); +3 +SELECT arrayLastIndex(x -> 1, range(number)) FROM system.numbers LIMIT 10; +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +SELECT arrayLastIndex(x -> x > 1, [1, 2, 3]); +3 +SELECT arrayLastIndex(x -> x > 3, [1, 2, 3]); +0 +SELECT arrayLastIndex(x -> x, [1, 2, 3]); +3 +SELECT arrayLastIndex(x -> NULL, [1, 2, 3]); -- { serverError ILLEGAL_COLUMN } +SELECT arrayLastIndex(x -> 'string', [1, 2, 3]); -- { serverError ILLEGAL_COLUMN } +SELECT '---cumsum---'; ---cumsum--- +SELECT arrayCumSum(x -> 0, emptyArrayUInt8()); [] +SELECT arrayCumSum(x -> 0, [1, 2, 3]); [0,0,0] +SELECT arrayCumSum(x -> 0, range(number)) FROM system.numbers LIMIT 10; [] [0] [0,0] @@ -199,8 +380,11 @@ [0,0,0,0,0,0,0] [0,0,0,0,0,0,0,0] [0,0,0,0,0,0,0,0,0] +SELECT arrayCumSum(x -> 10, emptyArrayUInt8()); [] +SELECT arrayCumSum(x -> 10, [1, 2, 3]); [10,20,30] +SELECT arrayCumSum(x -> 10, range(number)) FROM system.numbers LIMIT 10; [] [10] [10,20] @@ -211,9 +395,13 @@ [10,20,30,40,50,60,70] [10,20,30,40,50,60,70,80] [10,20,30,40,50,60,70,80,90] +SELECT '---map--'; ---map-- +SELECT arrayMap(x -> materialize(123), emptyArrayUInt8()); [] +SELECT arrayMap(x -> materialize(123), [1, 2, 3]); [123,123,123] +SELECT arrayMap(x -> materialize(123), range(number)) FROM system.numbers LIMIT 10; [] [123] [123,123] @@ -224,9 +412,13 @@ [123,123,123,123,123,123,123] [123,123,123,123,123,123,123,123] [123,123,123,123,123,123,123,123,123] +SELECT '---filter--'; ---filter-- +SELECT arrayFilter(x -> materialize(0), emptyArrayUInt8()); [] +SELECT arrayFilter(x -> materialize(0), [1, 2, 3]); [] +SELECT arrayFilter(x -> materialize(0), range(number)) FROM system.numbers LIMIT 10; [] [] [] @@ -237,8 +429,11 @@ [] [] [] +SELECT arrayFilter(x -> materialize(1), emptyArrayUInt8()); [] +SELECT arrayFilter(x -> materialize(1), [1, 2, 3]); [1,2,3] +SELECT arrayFilter(x -> materialize(1), range(number)) FROM system.numbers LIMIT 10; [] [0] [0,1] @@ -249,9 +444,13 @@ [0,1,2,3,4,5,6] [0,1,2,3,4,5,6,7] [0,1,2,3,4,5,6,7,8] +SELECT '---count---'; ---count--- +SELECT arrayCount(x -> materialize(0), emptyArrayUInt8()); 0 +SELECT arrayCount(x -> materialize(0), [1, 2, 3]); 0 +SELECT arrayCount(x -> materialize(0), range(number)) FROM system.numbers LIMIT 10; 0 0 0 @@ -262,8 +461,11 @@ 0 0 0 +SELECT arrayCount(x -> materialize(1), emptyArrayUInt8()); 0 +SELECT arrayCount(x -> materialize(1), [1, 2, 3]); 3 +SELECT arrayCount(x -> materialize(1), range(number)) FROM system.numbers LIMIT 10; 0 1 2 @@ -274,9 +476,13 @@ 7 8 9 +SELECT '---sum---'; ---sum--- +SELECT arraySum(x -> materialize(0), emptyArrayUInt8()); 0 +SELECT arraySum(x -> materialize(0), [1, 2, 3]); 0 +SELECT arraySum(x -> materialize(0), range(number)) FROM system.numbers LIMIT 10; 0 0 0 @@ -287,8 +493,11 @@ 0 0 0 +SELECT arraySum(x -> materialize(10), emptyArrayUInt8()); 0 +SELECT arraySum(x -> materialize(10), [1, 2, 3]); 30 +SELECT arraySum(x -> materialize(10), range(number)) FROM system.numbers LIMIT 10; 0 10 20 @@ -299,9 +508,13 @@ 70 80 90 +SELECT '---all---'; ---all--- +SELECT arrayAll(x -> materialize(0), emptyArrayUInt8()); 1 +SELECT arrayAll(x -> materialize(0), [1, 2, 3]); 0 +SELECT arrayAll(x -> materialize(0), range(number)) FROM system.numbers LIMIT 10; 1 0 0 @@ -312,8 +525,11 @@ 0 0 0 +SELECT arrayAll(x -> materialize(1), emptyArrayUInt8()); 1 +SELECT arrayAll(x -> materialize(1), [1, 2, 3]); 1 +SELECT arrayAll(x -> materialize(1), range(number)) FROM system.numbers LIMIT 10; 1 1 1 @@ -324,9 +540,13 @@ 1 1 1 +SELECT '---exists---'; ---exists--- +SELECT arrayExists(x -> materialize(0), emptyArrayUInt8()); 0 +SELECT arrayExists(x -> materialize(0), [1, 2, 3]); 0 +SELECT arrayExists(x -> materialize(0), range(number)) FROM system.numbers LIMIT 10; 0 0 0 @@ -337,8 +557,11 @@ 0 0 0 +SELECT arrayExists(x -> materialize(1), emptyArrayUInt8()); 0 +SELECT arrayExists(x -> materialize(1), [1, 2, 3]); 1 +SELECT arrayExists(x -> materialize(1), range(number)) FROM system.numbers LIMIT 10; 0 1 1 @@ -349,9 +572,16 @@ 1 1 1 +SELECT arrayExists(x -> x, [1, 2, 3]); +1 +SELECT arrayExists(x -> 'string', [1, 2, 3]); -- { serverError ILLEGAL_TYPE_OF_ARGUMENT } +SELECT '---first---'; ---first--- +SELECT arrayFirst(x -> materialize(0), emptyArrayUInt8()); 0 +SELECT arrayFirst(x -> materialize(0), [1, 2, 3]); 0 +SELECT arrayFirst(x -> materialize(0), range(number)) FROM system.numbers LIMIT 10; 0 0 0 @@ -362,8 +592,11 @@ 0 0 0 +SELECT arrayFirst(x -> materialize(1), emptyArrayUInt8()); 0 +SELECT arrayFirst(x -> materialize(1), [1, 2, 3]); 1 +SELECT arrayFirst(x -> materialize(1), range(number)) FROM system.numbers LIMIT 10; 0 0 0 @@ -374,9 +607,13 @@ 0 0 0 +SELECT '---first index---'; ---first index--- +SELECT arrayFirstIndex(x -> materialize(0), emptyArrayUInt8()); 0 +SELECT arrayFirstIndex(x -> materialize(0), [1, 2, 3]); 0 +SELECT arrayFirstIndex(x -> materialize(0), range(number)) FROM system.numbers LIMIT 10; 0 0 0 @@ -387,8 +624,11 @@ 0 0 0 +SELECT arrayFirstIndex(x -> materialize(1), emptyArrayUInt8()); 0 +SELECT arrayFirstIndex(x -> materialize(1), [1, 2, 3]); 1 +SELECT arrayFirstIndex(x -> materialize(1), range(number)) FROM system.numbers LIMIT 10; 0 1 1 @@ -399,9 +639,13 @@ 1 1 1 +SELECT '--cumsum---'; --cumsum--- +SELECT arrayCumSum(x -> materialize(0), emptyArrayUInt8()); [] +SELECT arrayCumSum(x -> materialize(0), [1, 2, 3]); [0,0,0] +SELECT arrayCumSum(x -> materialize(0), range(number)) FROM system.numbers LIMIT 10; [] [0] [0,0] @@ -412,8 +656,11 @@ [0,0,0,0,0,0,0] [0,0,0,0,0,0,0,0] [0,0,0,0,0,0,0,0,0] +SELECT arrayCumSum(x -> materialize(10), emptyArrayUInt8()); [] +SELECT arrayCumSum(x -> materialize(10), [1, 2, 3]); [10,20,30] +SELECT arrayCumSum(x -> materialize(10), range(number)) FROM system.numbers LIMIT 10; [] [10] [10,20] @@ -424,9 +671,13 @@ [10,20,30,40,50,60,70] [10,20,30,40,50,60,70,80] [10,20,30,40,50,60,70,80,90] +SELECT '---map--'; ---map-- +SELECT arrayMap(x -> 123, emptyArrayString()); [] +SELECT arrayMap(x -> 123, arrayMap(x -> toString(x), [1, 2, 3])); [123,123,123] +SELECT arrayMap(x -> 123, arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; [] [123] [123,123] @@ -437,9 +688,13 @@ [123,123,123,123,123,123,123] [123,123,123,123,123,123,123,123] [123,123,123,123,123,123,123,123,123] +SELECT '---filter--'; ---filter-- +SELECT arrayFilter(x -> 0, emptyArrayString()); [] +SELECT arrayFilter(x -> 0, arrayMap(x -> toString(x), [1, 2, 3])); [] +SELECT arrayFilter(x -> 0, arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; [] [] [] @@ -450,8 +705,11 @@ [] [] [] +SELECT arrayFilter(x -> 1, emptyArrayString()); [] +SELECT arrayFilter(x -> 1, arrayMap(x -> toString(x), [1, 2, 3])); ['1','2','3'] +SELECT arrayFilter(x -> 1, arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; [] ['0'] ['0','1'] @@ -462,9 +720,13 @@ ['0','1','2','3','4','5','6'] ['0','1','2','3','4','5','6','7'] ['0','1','2','3','4','5','6','7','8'] +SELECT '---count---'; ---count--- +SELECT arrayCount(x -> 0, emptyArrayString()); 0 +SELECT arrayCount(x -> 0, arrayMap(x -> toString(x), [1, 2, 3])); 0 +SELECT arrayCount(x -> 0, arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; 0 0 0 @@ -475,8 +737,11 @@ 0 0 0 +SELECT arrayCount(x -> 1, emptyArrayString()); 0 +SELECT arrayCount(x -> 1, arrayMap(x -> toString(x), [1, 2, 3])); 3 +SELECT arrayCount(x -> 1, arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; 0 1 2 @@ -487,9 +752,13 @@ 7 8 9 +SELECT '---sum---'; ---sum--- +SELECT arraySum(x -> 0, emptyArrayString()); 0 +SELECT arraySum(x -> 0, arrayMap(x -> toString(x), [1, 2, 3])); 0 +SELECT arraySum(x -> 0, arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; 0 0 0 @@ -500,8 +769,11 @@ 0 0 0 +SELECT arraySum(x -> 10, emptyArrayString()); 0 +SELECT arraySum(x -> 10, arrayMap(x -> toString(x), [1, 2, 3])); 30 +SELECT arraySum(x -> 10, arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; 0 10 20 @@ -512,9 +784,13 @@ 70 80 90 +SELECT '---all---'; ---all--- +SELECT arrayAll(x -> 0, emptyArrayString()); 1 +SELECT arrayAll(x -> 0, arrayMap(x -> toString(x), [1, 2, 3])); 0 +SELECT arrayAll(x -> 0, arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; 1 0 0 @@ -525,8 +801,11 @@ 0 0 0 +SELECT arrayAll(x -> 1, emptyArrayString()); 1 +SELECT arrayAll(x -> 1, arrayMap(x -> toString(x), [1, 2, 3])); 1 +SELECT arrayAll(x -> 1, arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; 1 1 1 @@ -537,9 +816,13 @@ 1 1 1 +SELECT '---exists---'; ---exists--- +SELECT arrayExists(x -> 0, emptyArrayString()); 0 +SELECT arrayExists(x -> 0, arrayMap(x -> toString(x), [1, 2, 3])); 0 +SELECT arrayExists(x -> 0, arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; 0 0 0 @@ -550,8 +833,11 @@ 0 0 0 +SELECT arrayExists(x -> 1, emptyArrayString()); 0 +SELECT arrayExists(x -> 1, arrayMap(x -> toString(x), [1, 2, 3])); 1 +SELECT arrayExists(x -> 1, arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; 0 1 1 @@ -562,9 +848,13 @@ 1 1 1 +SELECT '---first---'; ---first--- +SELECT arrayFirst(x -> 0, emptyArrayString()); +SELECT arrayFirst(x -> 0, arrayMap(x -> toString(x), [1, 2, 3])); +SELECT arrayFirst(x -> 0, arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; @@ -575,8 +865,11 @@ +SELECT arrayFirst(x -> 1, emptyArrayString()); +SELECT arrayFirst(x -> 1, arrayMap(x -> toString(x), [1, 2, 3])); 1 +SELECT arrayFirst(x -> 1, arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; 0 0 @@ -587,9 +880,13 @@ 0 0 0 +SELECT '---first index---'; ---first index--- +SELECT arrayFirstIndex(x -> 0, emptyArrayString()); 0 +SELECT arrayFirstIndex(x -> 0, arrayMap(x -> toString(x), [1, 2, 3])); 0 +SELECT arrayFirstIndex(x -> 0, arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; 0 0 0 @@ -600,8 +897,11 @@ 0 0 0 +SELECT arrayFirstIndex(x -> 1, emptyArrayString()); 0 +SELECT arrayFirstIndex(x -> 1, arrayMap(x -> toString(x), [1, 2, 3])); 1 +SELECT arrayFirstIndex(x -> 1, arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; 0 1 1 @@ -612,9 +912,13 @@ 1 1 1 +SELECT '---cumsum---'; ---cumsum--- +SELECT arrayCumSum(x -> 0, emptyArrayString()); [] +SELECT arrayCumSum(x -> 0, arrayMap(x -> toString(x), [1, 2, 3])); [0,0,0] +SELECT arrayCumSum(x -> 0, arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; [] [0] [0,0] @@ -625,8 +929,11 @@ [0,0,0,0,0,0,0] [0,0,0,0,0,0,0,0] [0,0,0,0,0,0,0,0,0] +SELECT arrayCumSum(x -> 10, emptyArrayString()); [] +SELECT arrayCumSum(x -> 10, arrayMap(x -> toString(x), [1, 2, 3])); [10,20,30] +SELECT arrayCumSum(x -> 10, arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; [] [10] [10,20] @@ -637,9 +944,13 @@ [10,20,30,40,50,60,70] [10,20,30,40,50,60,70,80] [10,20,30,40,50,60,70,80,90] +SELECT '---map--'; ---map-- +SELECT arrayMap(x -> materialize(123), emptyArrayString()); [] +SELECT arrayMap(x -> materialize(123), arrayMap(x -> toString(x), [1, 2, 3])); [123,123,123] +SELECT arrayMap(x -> materialize(123), arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; [] [123] [123,123] @@ -650,9 +961,13 @@ [123,123,123,123,123,123,123] [123,123,123,123,123,123,123,123] [123,123,123,123,123,123,123,123,123] +SELECT '---filter--'; ---filter-- +SELECT arrayFilter(x -> materialize(0), emptyArrayString()); [] +SELECT arrayFilter(x -> materialize(0), arrayMap(x -> toString(x), [1, 2, 3])); [] +SELECT arrayFilter(x -> materialize(0), arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; [] [] [] @@ -663,8 +978,11 @@ [] [] [] +SELECT arrayFilter(x -> materialize(1), emptyArrayString()); [] +SELECT arrayFilter(x -> materialize(1), arrayMap(x -> toString(x), [1, 2, 3])); ['1','2','3'] +SELECT arrayFilter(x -> materialize(1), arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; [] ['0'] ['0','1'] @@ -675,9 +993,13 @@ ['0','1','2','3','4','5','6'] ['0','1','2','3','4','5','6','7'] ['0','1','2','3','4','5','6','7','8'] +SELECT '---count---'; ---count--- +SELECT arrayCount(x -> materialize(0), emptyArrayString()); 0 +SELECT arrayCount(x -> materialize(0), arrayMap(x -> toString(x), [1, 2, 3])); 0 +SELECT arrayCount(x -> materialize(0), arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; 0 0 0 @@ -688,8 +1010,11 @@ 0 0 0 +SELECT arrayCount(x -> materialize(1), emptyArrayString()); 0 +SELECT arrayCount(x -> materialize(1), arrayMap(x -> toString(x), [1, 2, 3])); 3 +SELECT arrayCount(x -> materialize(1), arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; 0 1 2 @@ -700,9 +1025,13 @@ 7 8 9 +SELECT '---sum---'; ---sum--- +SELECT arraySum(x -> materialize(0), emptyArrayString()); 0 +SELECT arraySum(x -> materialize(0), arrayMap(x -> toString(x), [1, 2, 3])); 0 +SELECT arraySum(x -> materialize(0), arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; 0 0 0 @@ -713,8 +1042,11 @@ 0 0 0 +SELECT arraySum(x -> materialize(10), emptyArrayString()); 0 +SELECT arraySum(x -> materialize(10), arrayMap(x -> toString(x), [1, 2, 3])); 30 +SELECT arraySum(x -> materialize(10), arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; 0 10 20 @@ -725,9 +1057,13 @@ 70 80 90 +SELECT '---all---'; ---all--- +SELECT arrayAll(x -> materialize(0), emptyArrayString()); 1 +SELECT arrayAll(x -> materialize(0), arrayMap(x -> toString(x), [1, 2, 3])); 0 +SELECT arrayAll(x -> materialize(0), arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; 1 0 0 @@ -738,8 +1074,11 @@ 0 0 0 +SELECT arrayAll(x -> materialize(1), emptyArrayString()); 1 +SELECT arrayAll(x -> materialize(1), arrayMap(x -> toString(x), [1, 2, 3])); 1 +SELECT arrayAll(x -> materialize(1), arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; 1 1 1 @@ -750,9 +1089,13 @@ 1 1 1 +SELECT '---exists---'; ---exists--- +SELECT arrayExists(x -> materialize(0), emptyArrayString()); 0 +SELECT arrayExists(x -> materialize(0), arrayMap(x -> toString(x), [1, 2, 3])); 0 +SELECT arrayExists(x -> materialize(0), arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; 0 0 0 @@ -763,8 +1106,11 @@ 0 0 0 +SELECT arrayExists(x -> materialize(1), emptyArrayString()); 0 +SELECT arrayExists(x -> materialize(1), arrayMap(x -> toString(x), [1, 2, 3])); 1 +SELECT arrayExists(x -> materialize(1), arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; 0 1 1 @@ -775,9 +1121,13 @@ 1 1 1 +SELECT '---first---'; ---first--- +SELECT arrayFirst(x -> materialize(0), emptyArrayString()); +SELECT arrayFirst(x -> materialize(0), arrayMap(x -> toString(x), [1, 2, 3])); +SELECT arrayFirst(x -> materialize(0), arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; @@ -788,8 +1138,11 @@ +SELECT arrayFirst(x -> materialize(1), emptyArrayString()); +SELECT arrayFirst(x -> materialize(1), arrayMap(x -> toString(x), [1, 2, 3])); 1 +SELECT arrayFirst(x -> materialize(1), arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; 0 0 @@ -800,9 +1153,13 @@ 0 0 0 +SELECT '---first index---'; ---first index--- +SELECT arrayFirstIndex(x -> materialize(0), emptyArrayString()); 0 +SELECT arrayFirstIndex(x -> materialize(0), arrayMap(x -> toString(x), [1, 2, 3])); 0 +SELECT arrayFirstIndex(x -> materialize(0), arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; 0 0 0 @@ -813,8 +1170,11 @@ 0 0 0 +SELECT arrayFirstIndex(x -> materialize(1), emptyArrayString()); 0 +SELECT arrayFirstIndex(x -> materialize(1), arrayMap(x -> toString(x), [1, 2, 3])); 1 +SELECT arrayFirstIndex(x -> materialize(1), arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; 0 1 1 @@ -825,9 +1185,13 @@ 1 1 1 +SELECT '---cumsum---'; ---cumsum--- +SELECT arrayCumSum(x -> materialize(0), emptyArrayString()); [] +SELECT arrayCumSum(x -> materialize(0), arrayMap(x -> toString(x), [1, 2, 3])); [0,0,0] +SELECT arrayCumSum(x -> materialize(0), arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; [] [0] [0,0] @@ -838,8 +1202,11 @@ [0,0,0,0,0,0,0] [0,0,0,0,0,0,0,0] [0,0,0,0,0,0,0,0,0] +SELECT arrayCumSum(x -> materialize(10), emptyArrayString()); [] +SELECT arrayCumSum(x -> materialize(10), arrayMap(x -> toString(x), [1, 2, 3])); [10,20,30] +SELECT arrayCumSum(x -> materialize(10), arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; [] [10] [10,20] @@ -850,7 +1217,9 @@ [10,20,30,40,50,60,70] [10,20,30,40,50,60,70,80] [10,20,30,40,50,60,70,80,90] +SELECT '--- ---'; --- --- +SELECT arrayMap(x -> number % 2, range(number)) FROM system.numbers LIMIT 10; [] [1] [0,0] @@ -861,6 +1230,7 @@ [1,1,1,1,1,1,1] [0,0,0,0,0,0,0,0] [1,1,1,1,1,1,1,1,1] +SELECT arrayFilter(x -> number % 2, range(number)) FROM system.numbers LIMIT 10; [] [0] [] @@ -871,6 +1241,7 @@ [0,1,2,3,4,5,6] [] [0,1,2,3,4,5,6,7,8] +SELECT arrayCount(x -> number % 2, range(number)) FROM system.numbers LIMIT 10; 0 1 0 @@ -881,6 +1252,7 @@ 7 0 9 +SELECT arraySum(x -> number % 2, range(number)) FROM system.numbers LIMIT 10; 0 1 0 @@ -891,6 +1263,7 @@ 7 0 9 +SELECT arrayAll(x -> number % 2, range(number)) FROM system.numbers LIMIT 10; 1 1 0 @@ -901,6 +1274,7 @@ 1 0 1 +SELECT arrayExists(x -> number % 2, range(number)) FROM system.numbers LIMIT 10; 0 1 0 @@ -911,6 +1285,7 @@ 1 0 1 +SELECT arrayFirst(x -> number % 2, range(number)) FROM system.numbers LIMIT 10; 0 0 0 @@ -921,6 +1296,7 @@ 0 0 0 +SELECT arrayFirstIndex(x -> number % 2, range(number)) FROM system.numbers LIMIT 10; 0 1 0 @@ -931,6 +1307,7 @@ 1 0 1 +SELECT arrayCumSum(x -> number % 2, range(number)) FROM system.numbers LIMIT 10; [] [1] [0,0] @@ -941,7 +1318,9 @@ [1,2,3,4,5,6,7] [0,0,0,0,0,0,0,0] [1,2,3,4,5,6,7,8,9] +SELECT '--- ---'; --- --- +SELECT arrayMap(x -> number % 2, arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; [] [1] [0,0] @@ -952,6 +1331,7 @@ [1,1,1,1,1,1,1] [0,0,0,0,0,0,0,0] [1,1,1,1,1,1,1,1,1] +SELECT arrayFilter(x -> number % 2, arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; [] ['0'] [] @@ -962,6 +1342,7 @@ ['0','1','2','3','4','5','6'] [] ['0','1','2','3','4','5','6','7','8'] +SELECT arrayCount(x -> number % 2, arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; 0 1 0 @@ -972,6 +1353,7 @@ 7 0 9 +SELECT arraySum(x -> number % 2, arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; 0 1 0 @@ -982,6 +1364,7 @@ 7 0 9 +SELECT arrayAll(x -> number % 2, arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; 1 1 0 @@ -992,6 +1375,7 @@ 1 0 1 +SELECT arrayExists(x -> number % 2, arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; 0 1 0 @@ -1002,6 +1386,7 @@ 1 0 1 +SELECT arrayFirst(x -> number % 2, arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; 0 @@ -1012,6 +1397,7 @@ 0 0 +SELECT arrayFirstIndex(x -> number % 2, arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; 0 1 0 @@ -1022,6 +1408,7 @@ 1 0 1 +SELECT arrayCumSum(x -> number % 2, arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; [] [1] [0,0] diff --git a/tests/queries/0_stateless/00182_functions_higher_order_and_consts.sql b/tests/queries/0_stateless/00182_functions_higher_order_and_consts.sql index 4f8772d807b..b22867c4150 100644 --- a/tests/queries/0_stateless/00182_functions_higher_order_and_consts.sql +++ b/tests/queries/0_stateless/00182_functions_higher_order_and_consts.sql @@ -1,7 +1,9 @@ +--{echoOn} SELECT '---map--'; SELECT arrayMap(x -> 123, emptyArrayUInt8()); SELECT arrayMap(x -> 123, [1, 2, 3]); SELECT arrayMap(x -> 123, range(number)) FROM system.numbers LIMIT 10; +SELECT arrayMap(x -> x, range(number)) FROM system.numbers LIMIT 3; SELECT '---filter--'; SELECT arrayFilter(x -> 0, emptyArrayUInt8()); SELECT arrayFilter(x -> 0, [1, 2, 3]); @@ -9,6 +11,10 @@ SELECT arrayFilter(x -> 0, range(number)) FROM system.numbers LIMIT 10; SELECT arrayFilter(x -> 1, emptyArrayUInt8()); SELECT arrayFilter(x -> 1, [1, 2, 3]); SELECT arrayFilter(x -> 1, range(number)) FROM system.numbers LIMIT 10; +SELECT arrayFilter(x -> x > 1, [1, 2, 3]); +SELECT arrayFilter(x -> x > 2, [1, 2, 3]); +SELECT arrayFilter(x -> NULL, [1, 2, 3]); +SELECT arrayFilter(x -> 'string', [1, 2, 3]); -- { serverError ILLEGAL_TYPE_OF_ARGUMENT } SELECT '---count---'; SELECT arrayCount(x -> 0, emptyArrayUInt8()); SELECT arrayCount(x -> 0, [1, 2, 3]); @@ -16,6 +22,10 @@ SELECT arrayCount(x -> 0, range(number)) FROM system.numbers LIMIT 10; SELECT arrayCount(x -> 1, emptyArrayUInt8()); SELECT arrayCount(x -> 1, [1, 2, 3]); SELECT arrayCount(x -> 1, range(number)) FROM system.numbers LIMIT 10; +SELECT arrayCount(x -> x > 0, [1, 2, 3]); +SELECT arrayCount(x -> x > 1, [1, 2, 3]); +SELECT arrayCount(x -> NULL, [1, 2, 3]); +SELECT arrayCount(x -> 'string', [1, 2, 3]); -- { serverError ILLEGAL_TYPE_OF_ARGUMENT } SELECT '---sum---'; SELECT arraySum(x -> 0, emptyArrayUInt8()); SELECT arraySum(x -> 0, [1, 2, 3]); @@ -30,6 +40,11 @@ SELECT arrayAll(x -> 0, range(number)) FROM system.numbers LIMIT 10; SELECT arrayAll(x -> 1, emptyArrayUInt8()); SELECT arrayAll(x -> 1, [1, 2, 3]); SELECT arrayAll(x -> 1, range(number)) FROM system.numbers LIMIT 10; +SELECT arrayAll(x -> x > 0, [1, 2, 3]); +SELECT arrayAll(x -> x > 1, [1, 2, 3]); +SELECT arrayAll(x -> x, [1, 2, 3]); +SELECT arrayAll(x -> NULL, [1, 2, 3]); +SELECT arrayAll(x -> 'string', [1, 2, 3]); -- { serverError ILLEGAL_TYPE_OF_ARGUMENT } SELECT '---exists---'; SELECT arrayExists(x -> 0, emptyArrayUInt8()); SELECT arrayExists(x -> 0, [1, 2, 3]); @@ -44,6 +59,23 @@ SELECT arrayFirst(x -> 0, range(number)) FROM system.numbers LIMIT 10; SELECT arrayFirst(x -> 1, emptyArrayUInt8()); SELECT arrayFirst(x -> 1, [1, 2, 3]); SELECT arrayFirst(x -> 1, range(number)) FROM system.numbers LIMIT 10; +SELECT arrayFirst(x -> x > 1, [1, 2, 3]); +SELECT arrayFirst(x -> x > 3, [1, 2, 3]); +SELECT arrayFirst(x -> x, [1, 2, 3]); +SELECT arrayFirst(x -> NULL, [1, 2, 3]); -- { serverError ILLEGAL_COLUMN } +SELECT arrayFirst(x -> 'string', [1, 2, 3]); -- { serverError ILLEGAL_COLUMN } +SELECT '---last---'; +SELECT arrayLast(x -> 0, emptyArrayUInt8()); +SELECT arrayLast(x -> 0, [1, 2, 3]); +SELECT arrayLast(x -> 0, range(number)) FROM system.numbers LIMIT 10; +SELECT arrayLast(x -> 1, emptyArrayUInt8()); +SELECT arrayLast(x -> 1, [1, 2, 3]); +SELECT arrayLast(x -> 1, range(number)) FROM system.numbers LIMIT 10; +SELECT arrayLast(x -> x > 1, [1, 2, 3]); +SELECT arrayLast(x -> x > 3, [1, 2, 3]); +SELECT arrayLast(x -> x, [1, 2, 3]); +SELECT arrayLast(x -> NULL, [1, 2, 3]); -- { serverError ILLEGAL_COLUMN } +SELECT arrayLast(x -> 'string', [1, 2, 3]); -- { serverError ILLEGAL_COLUMN } SELECT '---first index---'; SELECT arrayFirstIndex(x -> 0, emptyArrayUInt8()); SELECT arrayFirstIndex(x -> 0, [1, 2, 3]); @@ -51,6 +83,23 @@ SELECT arrayFirstIndex(x -> 0, range(number)) FROM system.numbers LIMIT 10; SELECT arrayFirstIndex(x -> 1, emptyArrayUInt8()); SELECT arrayFirstIndex(x -> 1, [1, 2, 3]); SELECT arrayFirstIndex(x -> 1, range(number)) FROM system.numbers LIMIT 10; +SELECT arrayFirstIndex(x -> x > 1, [1, 2, 3]); +SELECT arrayFirstIndex(x -> x > 3, [1, 2, 3]); +SELECT arrayFirstIndex(x -> x, [1, 2, 3]); +SELECT arrayFirstIndex(x -> NULL, [1, 2, 3]); -- { serverError ILLEGAL_COLUMN } +SELECT arrayFirstIndex(x -> 'string', [1, 2, 3]); -- { serverError ILLEGAL_COLUMN } +SELECT '---lastindex---'; +SELECT arrayLastIndex(x -> 0, emptyArrayUInt8()); +SELECT arrayLastIndex(x -> 0, [1, 2, 3]); +SELECT arrayLastIndex(x -> 0, range(number)) FROM system.numbers LIMIT 10; +SELECT arrayLastIndex(x -> 1, emptyArrayUInt8()); +SELECT arrayLastIndex(x -> 1, [1, 2, 3]); +SELECT arrayLastIndex(x -> 1, range(number)) FROM system.numbers LIMIT 10; +SELECT arrayLastIndex(x -> x > 1, [1, 2, 3]); +SELECT arrayLastIndex(x -> x > 3, [1, 2, 3]); +SELECT arrayLastIndex(x -> x, [1, 2, 3]); +SELECT arrayLastIndex(x -> NULL, [1, 2, 3]); -- { serverError ILLEGAL_COLUMN } +SELECT arrayLastIndex(x -> 'string', [1, 2, 3]); -- { serverError ILLEGAL_COLUMN } SELECT '---cumsum---'; SELECT arrayCumSum(x -> 0, emptyArrayUInt8()); SELECT arrayCumSum(x -> 0, [1, 2, 3]); @@ -98,6 +147,8 @@ SELECT arrayExists(x -> materialize(0), range(number)) FROM system.numbers LIMIT SELECT arrayExists(x -> materialize(1), emptyArrayUInt8()); SELECT arrayExists(x -> materialize(1), [1, 2, 3]); SELECT arrayExists(x -> materialize(1), range(number)) FROM system.numbers LIMIT 10; +SELECT arrayExists(x -> x, [1, 2, 3]); +SELECT arrayExists(x -> 'string', [1, 2, 3]); -- { serverError ILLEGAL_TYPE_OF_ARGUMENT } SELECT '---first---'; SELECT arrayFirst(x -> materialize(0), emptyArrayUInt8()); SELECT arrayFirst(x -> materialize(0), [1, 2, 3]); From ceb9c5d2d765414cbc18a1c6b431394b4e5f7e6d Mon Sep 17 00:00:00 2001 From: maxvostrikov Date: Thu, 19 Dec 2024 16:41:50 +0100 Subject: [PATCH 2/2] squash! Added some tests with meta-array functions Added some tests with meta-array functions, related to https://github.com/ClickHouse/ClickHouse/pull/70093 Also added tests for ArrayLast --- .../00182_functions_higher_order_and_consts.reference | 1 + .../0_stateless/00182_functions_higher_order_and_consts.sql | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/queries/0_stateless/00182_functions_higher_order_and_consts.reference b/tests/queries/0_stateless/00182_functions_higher_order_and_consts.reference index cccaabd394c..da8c457b9be 100644 --- a/tests/queries/0_stateless/00182_functions_higher_order_and_consts.reference +++ b/tests/queries/0_stateless/00182_functions_higher_order_and_consts.reference @@ -58,6 +58,7 @@ SELECT arrayFilter(x -> x > 2, [1, 2, 3]); [3] SELECT arrayFilter(x -> NULL, [1, 2, 3]); [] +SELECT arrayFilter(x -> 1.1, [1, 2, 3]); -- { serverError ILLEGAL_TYPE_OF_ARGUMENT } SELECT arrayFilter(x -> 'string', [1, 2, 3]); -- { serverError ILLEGAL_TYPE_OF_ARGUMENT } SELECT '---count---'; ---count--- diff --git a/tests/queries/0_stateless/00182_functions_higher_order_and_consts.sql b/tests/queries/0_stateless/00182_functions_higher_order_and_consts.sql index b22867c4150..9c9985c8940 100644 --- a/tests/queries/0_stateless/00182_functions_higher_order_and_consts.sql +++ b/tests/queries/0_stateless/00182_functions_higher_order_and_consts.sql @@ -14,6 +14,7 @@ SELECT arrayFilter(x -> 1, range(number)) FROM system.numbers LIMIT 10; SELECT arrayFilter(x -> x > 1, [1, 2, 3]); SELECT arrayFilter(x -> x > 2, [1, 2, 3]); SELECT arrayFilter(x -> NULL, [1, 2, 3]); +SELECT arrayFilter(x -> 1.1, [1, 2, 3]); -- { serverError ILLEGAL_TYPE_OF_ARGUMENT } SELECT arrayFilter(x -> 'string', [1, 2, 3]); -- { serverError ILLEGAL_TYPE_OF_ARGUMENT } SELECT '---count---'; SELECT arrayCount(x -> 0, emptyArrayUInt8());