mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-21 01:00:48 +00:00
Update the implementaion of nth_value
Make nth_value for nullable values for out of frame rows, as the same fashion as lagInFrame just does.
This commit is contained in:
parent
94d4fb9dfc
commit
4d36d54c81
@ -1631,16 +1631,9 @@ struct WindowFunctionNthValue final : public WindowFunction
|
||||
else
|
||||
{
|
||||
// Offset is inside the frame.
|
||||
auto srcColumnPtr = transform->blockAt(target_row).input_columns[workspace.argument_column_indices[0]];
|
||||
// If the original column type is Nullable(from DDL)
|
||||
if (srcColumnPtr->getDataType() == TypeIndex::Nullable)
|
||||
{
|
||||
to.insertFrom(*srcColumnPtr, target_row.row);
|
||||
}
|
||||
else
|
||||
{
|
||||
assert_cast<ColumnNullable&>(to).insertFromNotNullable(*srcColumnPtr, target_row.row);
|
||||
}
|
||||
to.insertFrom(*transform->blockAt(target_row).input_columns[
|
||||
workspace.argument_column_indices[0]],
|
||||
target_row.row);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -1106,9 +1106,9 @@ from numbers(10)
|
||||
window w as (order by number)
|
||||
order by number
|
||||
;
|
||||
0 0 \N \N \N
|
||||
1 0 1 \N \N
|
||||
2 0 1 2 \N
|
||||
0 0 0 0 0
|
||||
1 0 1 0 0
|
||||
2 0 1 2 0
|
||||
3 0 1 2 3
|
||||
4 0 1 2 3
|
||||
5 0 1 2 3
|
||||
@ -1127,16 +1127,30 @@ from numbers(10)
|
||||
window w as (order by number range between 1 preceding and 1 following)
|
||||
order by number
|
||||
;
|
||||
0 0 1 \N \N
|
||||
1 0 1 2 \N
|
||||
2 1 2 3 \N
|
||||
3 2 3 4 \N
|
||||
4 3 4 5 \N
|
||||
5 4 5 6 \N
|
||||
6 5 6 7 \N
|
||||
7 6 7 8 \N
|
||||
8 7 8 9 \N
|
||||
9 8 9 \N \N
|
||||
0 0 1 0 0
|
||||
1 0 1 2 0
|
||||
2 1 2 3 0
|
||||
3 2 3 4 0
|
||||
4 3 4 5 0
|
||||
5 4 5 6 0
|
||||
6 5 6 7 0
|
||||
7 6 7 8 0
|
||||
8 7 8 9 0
|
||||
9 8 9 0 0
|
||||
-- to make nth_value return null for out-of-frame rows, cast the argument to
|
||||
-- Nullable; otherwise, it returns default values.
|
||||
SELECT
|
||||
number,
|
||||
nth_value(toNullable(number), 1) OVER w as firstValue,
|
||||
nth_value(toNullable(number), 3) OVER w as thridValue
|
||||
FROM numbers(5)
|
||||
WINDOW w AS (ORDER BY number ASC)
|
||||
;
|
||||
0 0 \N
|
||||
1 0 \N
|
||||
2 0 2
|
||||
3 0 2
|
||||
4 0 2
|
||||
-- In this case, we had a problem with PartialSortingTransform returning zero-row
|
||||
-- chunks for input chunks w/o columns.
|
||||
select count() over () from numbers(4) where number < 2;
|
||||
|
@ -427,6 +427,16 @@ window w as (order by number range between 1 preceding and 1 following)
|
||||
order by number
|
||||
;
|
||||
|
||||
-- to make nth_value return null for out-of-frame rows, cast the argument to
|
||||
-- Nullable; otherwise, it returns default values.
|
||||
SELECT
|
||||
number,
|
||||
nth_value(toNullable(number), 1) OVER w as firstValue,
|
||||
nth_value(toNullable(number), 3) OVER w as thridValue
|
||||
FROM numbers(5)
|
||||
WINDOW w AS (ORDER BY number ASC)
|
||||
;
|
||||
|
||||
-- In this case, we had a problem with PartialSortingTransform returning zero-row
|
||||
-- chunks for input chunks w/o columns.
|
||||
select count() over () from numbers(4) where number < 2;
|
||||
|
Loading…
Reference in New Issue
Block a user