Fix crash with DISTINCT and window functions

This commit is contained in:
Igor Nikonov 2024-06-03 20:52:23 +00:00
parent c45ebafc70
commit f8e6614b80
3 changed files with 31 additions and 2 deletions

View File

@ -172,10 +172,14 @@ namespace
}
if (typeid_cast<const WindowStep *>(current_step))
{
/// it can be empty in case of 2 WindowSteps following one another
if (!dag_stack.empty())
{
actions_chain.push_back(std::move(dag_stack));
dag_stack.clear();
}
}
if (const auto * const expr = typeid_cast<const ExpressionStep *>(current_step); expr)
dag_stack.push_back(expr->getExpression());

View File

@ -0,0 +1,25 @@
DROP TABLE IF EXISTS atable;
CREATE TABLE atable
(
cdu_date Int16,
loanx_id String,
rating_sp String
)
ENGINE = MergeTree
ORDER BY tuple();
SELECT DISTINCT
loanx_id,
rating_sp,
cdu_date,
row_number() OVER (PARTITION BY cdu_date) AS row_number,
last_value(cdu_date) OVER (PARTITION BY loanx_id ORDER BY cdu_date ASC) AS last_cdu_date
FROM atable
GROUP BY
cdu_date,
loanx_id,
rating_sp
SETTINGS query_plan_remove_redundant_distinct = 1;
DROP TABLE atable;