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..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 @@ -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,21 @@ [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 -> 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--- +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 +77,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 +92,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 +116,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 +131,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 +148,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 +163,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 +189,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 +204,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 +236,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 +261,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 +301,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 +316,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 +381,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 +396,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 +413,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 +430,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 +445,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 +462,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 +477,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 +494,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 +509,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 +526,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 +541,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 +558,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 +573,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 +593,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 +608,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 +625,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 +640,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 +657,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 +672,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 +689,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 +706,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 +721,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 +738,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 +753,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 +770,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 +785,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 +802,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 +817,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 +834,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 +849,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 +866,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 +881,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 +898,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 +913,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 +930,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 +945,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 +962,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 +979,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 +994,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 +1011,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 +1026,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 +1043,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 +1058,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 +1075,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 +1090,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 +1107,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 +1122,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 +1139,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 +1154,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 +1171,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 +1186,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 +1203,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 +1218,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 +1231,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 +1242,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 +1253,7 @@ 7 0 9 +SELECT arraySum(x -> number % 2, range(number)) FROM system.numbers LIMIT 10; 0 1 0 @@ -891,6 +1264,7 @@ 7 0 9 +SELECT arrayAll(x -> number % 2, range(number)) FROM system.numbers LIMIT 10; 1 1 0 @@ -901,6 +1275,7 @@ 1 0 1 +SELECT arrayExists(x -> number % 2, range(number)) FROM system.numbers LIMIT 10; 0 1 0 @@ -911,6 +1286,7 @@ 1 0 1 +SELECT arrayFirst(x -> number % 2, range(number)) FROM system.numbers LIMIT 10; 0 0 0 @@ -921,6 +1297,7 @@ 0 0 0 +SELECT arrayFirstIndex(x -> number % 2, range(number)) FROM system.numbers LIMIT 10; 0 1 0 @@ -931,6 +1308,7 @@ 1 0 1 +SELECT arrayCumSum(x -> number % 2, range(number)) FROM system.numbers LIMIT 10; [] [1] [0,0] @@ -941,7 +1319,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 +1332,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 +1343,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 +1354,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 +1365,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 +1376,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 +1387,7 @@ 1 0 1 +SELECT arrayFirst(x -> number % 2, arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; 0 @@ -1012,6 +1398,7 @@ 0 0 +SELECT arrayFirstIndex(x -> number % 2, arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; 0 1 0 @@ -1022,6 +1409,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..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 @@ -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,11 @@ 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 -> 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()); SELECT arrayCount(x -> 0, [1, 2, 3]); @@ -16,6 +23,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 +41,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 +60,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 +84,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 +148,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]);