Merge pull request #68262 from bigo-sg/fix_68162

Fix crash in lag/lead
This commit is contained in:
Yakov Olkhovskiy 2024-08-15 06:58:18 +00:00 committed by GitHub
commit f0845eeacb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 37 additions and 2 deletions

View File

@ -1157,8 +1157,7 @@ void WindowTransform::appendChunk(Chunk & chunk)
// Initialize output columns.
for (auto & ws : workspaces)
{
if (ws.window_function_impl)
block.casted_columns.push_back(ws.window_function_impl->castColumn(block.input_columns, ws.argument_column_indices));
block.casted_columns.push_back(ws.window_function_impl ? ws.window_function_impl->castColumn(block.input_columns, ws.argument_column_indices) : nullptr);
block.output_columns.push_back(ws.aggregate_function->getResultType()
->createColumn());

View File

@ -38,3 +38,19 @@
7
8
9
15 \N 3 15 15 15 15
14 \N 2 10 10 10 154
13 \N 2 10 10 10 143
12 \N 2 10 10 10 14
11 \N 2 10 10 10 12
10 \N 2 10 10 10 10
9 \N 1 5 5 5 99
8 \N 1 5 5 5 88
7 \N 1 5 5 5 9
6 \N 1 5 5 5 7
5 \N 1 5 5 5 5
4 \N 0 0 0 0 44
3 \N 0 0 0 0 33
2 \N 0 0 0 0 4
1 \N 0 0 0 0 2
0 \N 0 0 0 0 0

View File

@ -2,3 +2,23 @@ SELECT lagInFrame(2::UInt128, 2, number) OVER w FROM numbers(10) WINDOW w AS (OR
SELECT leadInFrame(2::UInt128, 2, number) OVER w FROM numbers(10) WINDOW w AS (ORDER BY number);
SELECT lagInFrame(2::UInt64, 2, number) OVER w FROM numbers(10) WINDOW w AS (ORDER BY number);
SELECT leadInFrame(2::UInt64, 2, number) OVER w FROM numbers(10) WINDOW w AS (ORDER BY number);
SELECT
number,
YYYYMMDDToDate(1, toLowCardinality(11), max(YYYYMMDDToDate(YYYYMMDDToDate(toLowCardinality(1), 11, materialize(NULL), 19700101.1, 1, 27, 7, materialize(toUInt256(37)), 9, 19, 9), 1, toUInt128(11), NULL, 19700101.1, 1, 27, 7, 37, 9, 19, 9), toUInt256(30)) IGNORE NULLS OVER w, NULL, 19700101.1, toNullable(1), 27, materialize(7), 37, 9, 19, 9),
p,
pp,
lagInFrame(number, number - pp) OVER w AS lag2,
lagInFrame(number, number - pp, number * 11) OVER w AS lag,
leadInFrame(number, number - pp, number * 11) OVER w AS lead
FROM
(
SELECT
number,
intDiv(number, 5) AS p,
p * 5 AS pp
FROM numbers(16)
)
WHERE toLowCardinality(1)
WINDOW w AS (PARTITION BY p ORDER BY number ASC NULLS FIRST ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)
ORDER BY number DESC NULLS LAST;