You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Window function MAX/MIN wrong results when calculated column is part of grouping #57321
comp-window-functionsWindow function execution + frame handling (ROW_NUMBER/RANK/LAG/LEAD, frames, partitions, order).unexpected behaviourResult is unexpected, but not entirely wrong at the same time.
suppose 2 rows with integer column ver
#1: ver=1
#2: ver=2
group by ver + get ver_max as overall max for all records
expectation:
ver | ver_max
1, 2
2, 2
Tests
NOT OK sample
SELECT
ver,
max(ver) OVER() as ver_max
FROM (
SELECT 1 ver
UNION ALL
SELECT 2 ver
)
GROUP BY ver
result =>
ver | ver_max
1, 1
2, 2
OK sample if removing external group
SELECT
ver,
max(ver) OVER() as ver_max
FROM (
SELECT 1 ver
UNION ALL
SELECT 2 ver
)
result =>
ver | ver_max
1, 2
2, 2
Workaround to get result while keeping group
in real query external grouping is required
(idea is get all columns + aggregated results from last load only where ver >= ver_max)
currently can keep external grouping and normal results if adding some dummy calculation e.g. multiple on 1
SELECT
ver,
max(ver * 1) OVER() ver_max
FROM (
SELECT 1 ver
UNION ALL
SELECT 2 ver
)
GROUP BY ver;
result =>
ver | ver_max
1, 2
2, 2
set allow_experimental_analyzer=1;
SELECT
ver,
max(ver) OVER () AS ver_max
FROM
(
SELECT1AS ver
UNION ALLSELECT2AS ver
)
GROUP BY ver
┌─ver─┬─ver_max─┐
│ 1 │ 2 │
│ 2 │ 2 │
└─────┴─────────┘
comp-window-functionsWindow function execution + frame handling (ROW_NUMBER/RANK/LAG/LEAD, frames, partitions, order).unexpected behaviourResult is unexpected, but not entirely wrong at the same time.
Activity
den-crane commentedon Nov 28, 2023
works with analyzer
https://fiddle.clickhouse.com/1a36f47c-7e77-48ac-806d-0f1ebdac0635
Close: #57321