2023-12-17 11:16:05 +00:00
|
|
|
SELECT '-- Negative tests';
|
2024-05-07 14:10:21 +00:00
|
|
|
SELECT arrayFold(); -- { serverError TOO_FEW_ARGUMENTS_FOR_FUNCTION }
|
|
|
|
SELECT arrayFold(1); -- { serverError TOO_FEW_ARGUMENTS_FOR_FUNCTION }
|
|
|
|
SELECT arrayFold(1, toUInt64(0)); -- { serverError TOO_FEW_ARGUMENTS_FOR_FUNCTION }
|
2023-12-14 09:52:29 +00:00
|
|
|
SELECT arrayFold(1, emptyArrayUInt64(), toUInt64(0)); -- { serverError ILLEGAL_TYPE_OF_ARGUMENT }
|
|
|
|
SELECT arrayFold( acc,x -> x, emptyArrayString(), toInt8(0)); -- { serverError TYPE_MISMATCH }
|
2024-05-07 14:10:21 +00:00
|
|
|
SELECT arrayFold( acc,x -> x, 'not an array', toUInt8(0)); -- { serverError I02718_array_foldLLEGAL_TYPE_OF_ARGUMENT }
|
2023-12-14 09:52:29 +00:00
|
|
|
SELECT arrayFold( acc,x,y -> x, [0, 1], 'not an array', toUInt8(0)); -- { serverError ILLEGAL_TYPE_OF_ARGUMENT }
|
|
|
|
SELECT arrayFold( acc,x -> x, [0, 1], [2, 3], toUInt8(0)); -- { serverError ILLEGAL_TYPE_OF_ARGUMENT }
|
|
|
|
SELECT arrayFold( acc,x,y -> x, [0, 1], [2, 3, 4], toUInt8(0)); -- { serverError SIZES_OF_ARRAYS_DONT_MATCH }
|
|
|
|
|
2023-12-17 11:16:05 +00:00
|
|
|
SELECT '-- Const arrays';
|
2023-12-14 09:52:29 +00:00
|
|
|
SELECT arrayFold( acc,x -> acc+x*2, [1, 2, 3, 4], toInt64(3));
|
|
|
|
SELECT arrayFold( acc,x -> acc+x*2, emptyArrayInt64(), toInt64(3));
|
|
|
|
SELECT arrayFold( acc,x,y -> acc+x*2+y*3, [1, 2, 3, 4], [5, 6, 7, 8], toInt64(3));
|
|
|
|
SELECT arrayFold( acc,x -> arrayPushBack(acc, x), [1, 2, 3, 4], emptyArrayInt64());
|
|
|
|
SELECT arrayFold( acc,x -> arrayPushFront(acc, x), [1, 2, 3, 4], emptyArrayInt64());
|
|
|
|
SELECT arrayFold( acc,x -> (arrayPushFront(acc.1, x),arrayPushBack(acc.2, x)), [1, 2, 3, 4], (emptyArrayInt64(), emptyArrayInt64()));
|
|
|
|
SELECT arrayFold( acc,x -> x%2 ? (arrayPushBack(acc.1, x), acc.2): (acc.1, arrayPushBack(acc.2, x)), [1, 2, 3, 4, 5, 6], (emptyArrayInt64(), emptyArrayInt64()));
|
|
|
|
|
2023-12-17 11:16:05 +00:00
|
|
|
SELECT '-- Non-const arrays';
|
2023-12-14 09:52:29 +00:00
|
|
|
SELECT arrayFold( acc,x -> acc+x, range(number), number) FROM system.numbers LIMIT 5;
|
|
|
|
SELECT arrayFold( acc,x -> arrayPushFront(acc,x), range(number), emptyArrayUInt64()) FROM system.numbers LIMIT 5;
|
|
|
|
SELECT arrayFold( acc,x -> x%2 ? arrayPushFront(acc,x) : arrayPushBack(acc,x), range(number), emptyArrayUInt64()) FROM system.numbers LIMIT 5;
|
2023-12-14 20:12:55 +00:00
|
|
|
|
2023-12-17 11:16:05 +00:00
|
|
|
SELECT '-- Bug 57458';
|
2023-12-14 20:12:55 +00:00
|
|
|
|
|
|
|
DROP TABLE IF EXISTS tab;
|
2023-12-17 11:16:05 +00:00
|
|
|
|
2023-12-14 20:12:55 +00:00
|
|
|
CREATE TABLE tab (line String, patterns Array(String)) ENGINE = MergeTree ORDER BY line;
|
|
|
|
INSERT INTO tab VALUES ('abcdef', ['c']), ('ghijkl', ['h', 'k']), ('mnopqr', ['n']);
|
2023-12-17 11:16:05 +00:00
|
|
|
|
2023-12-14 20:12:55 +00:00
|
|
|
SELECT
|
|
|
|
line,
|
|
|
|
patterns,
|
|
|
|
arrayFold(acc, pat -> position(line, pat), patterns, 0::UInt64)
|
2023-12-17 11:16:05 +00:00
|
|
|
FROM tab
|
2023-12-14 20:12:55 +00:00
|
|
|
ORDER BY line;
|
|
|
|
|
|
|
|
DROP TABLE tab;
|
2023-12-17 11:16:05 +00:00
|
|
|
|
2023-12-14 20:12:55 +00:00
|
|
|
CREATE TABLE tab (line String) ENGINE = Memory();
|
|
|
|
INSERT INTO tab VALUES ('xxx..yyy..'), ('..........'), ('..xx..yyy.'), ('..........'), ('xxx.......');
|
2023-12-17 11:16:05 +00:00
|
|
|
|
2023-12-14 20:12:55 +00:00
|
|
|
SELECT
|
|
|
|
line,
|
|
|
|
splitByNonAlpha(line),
|
|
|
|
arrayFold(
|
|
|
|
(acc, str) -> position(line, str),
|
|
|
|
splitByNonAlpha(line),
|
|
|
|
0::UInt64
|
|
|
|
)
|
|
|
|
FROM
|
|
|
|
tab;
|
|
|
|
|
2023-12-17 11:16:05 +00:00
|
|
|
DROP TABLE tab;
|
|
|
|
|
|
|
|
SELECT ' -- Bug 57816';
|
2023-12-14 20:12:55 +00:00
|
|
|
|
2023-12-17 11:16:05 +00:00
|
|
|
SELECT arrayFold(acc, x -> arrayIntersect(acc, x), [['qwe', 'asd'], ['qwe','asde']], []);
|