Repository navigation
Reject arguments for RANK and DENSE_RANK window functions - #104324
alexey-milovidov merged 1 commit into
Conversation
Pre-PR validation gate
Session: cron:clickhouse-ci-task-worker:20260507-194500 |
|
cc @novikd @KochetovNicolai — could you review this? It rejects arguments for |
|
Workflow [PR], commit [08bc397] Summary: ✅ AI ReviewSummaryThis PR changes Final Verdict
|
|
@groeneai resolve conflicts. |
e82ff96 to
bcbd1bb
Compare
|
@nikitamikhaylov rebased onto current master HEAD The original PR HEAD New HEAD: Session: cron:clickhouse-ci-task-worker:20260508-1445 |
The `RANK` and `DENSE_RANK` window functions take zero arguments per SQL standard — they rank rows based solely on the `OVER (ORDER BY ...)` window. ClickHouse historically accepted and silently ignored arbitrary arguments, which led to user confusion: queries such as `DENSE_RANK(PRT) OVER (ORDER BY id)` appeared to rank by `PRT`, but the argument was ignored and the ranking actually followed `id`. Reject any arguments by default and throw `NUMBER_OF_ARGUMENTS_DOESNT_MATCH`. The legacy lenient behavior is gated behind a new compatibility setting `allow_rank_dense_rank_arguments`. Set it to `1` to restore the pre-26.5 silent-ignore behavior for queries that relied on it. Closes ClickHouse#49526
bcbd1bb to
08bc397
Compare
|
@nikitamikhaylov rebased again onto current master HEAD
Verified locally on the rebased binary:
New HEAD: Session: cron:clickhouse-ci-task-worker:20260519-031500 |
LLVM Coverage Report
Changed lines: 100.00% (44/44) | lost baseline coverage: 3 line(s) · Uncovered code |
…ease notes The 26.6 Cloud release notes were missing several backward incompatible changes that ship in that version: * UUID parsing now rejects same-length non-hexadecimal strings (ClickHouse#104370). * The obsolete Arrow-based Parquet reader and writer were removed (ClickHouse#100949). * `RANK` and `DENSE_RANK` reject arguments (ClickHouse#104324). * `Dynamic`/`Variant` types are validated in window `PARTITION BY` (ClickHouse#105450).
Motivation
Per SQL standard, the
RANKandDENSE_RANKwindow functions take zero arguments — they rank rows based solely on theOVER (ORDER BY ...)window.ClickHouse historically accepted and silently ignored arbitrary arguments, leading to user confusion:
After this change, such queries throw
NUMBER_OF_ARGUMENTS_DOESNT_MATCHwith a message that points users at either the standard formDENSE_RANK() OVER (ORDER BY PRT)or, for backward compatibility, the newallow_rank_dense_rank_argumentssetting that restores the legacy silent-ignore behavior.Approach
WindowTransform.cpp: validateargument_types.empty()in the registration lambdas of bothrankanddenseRank. If non-empty ANDallow_rank_dense_rank_arguments = 0(default), throwNUMBER_OF_ARGUMENTS_DOESNT_MATCH. The error message references the compatibility setting.Settings.cpp: declare the newallow_rank_dense_rank_arguments(Bool, defaultfalse).SettingsChangesHistory.cpp: record the behavior change in the 26.5 entry (previous_value = true,new_value = false).experimental_settings_ignore.txt: whitelist the setting (it is a backward-compat setting, not experimental).04209_rank_dense_rank_no_arguments_49526.sql: new regression test covering all 6 reproducer queries from the issue + the compatibility setting flow + zero-argument forms still working + both analyzers.02478_window_frame_type_groups.sql: replace incidentaldense_rank(1)withdense_rank(). The test's actual purpose is verifyingGROUPS BETWEEN ...frame-type rejection — the1argument was incidental and would now mask the intendedNOT_IMPLEMENTEDcheck.Pre-PR validation
a) Deterministic repro —
SELECT DENSE_RANK(x) OVER (ORDER BY x) FROM (SELECT 1 AS x);deterministically throws.b) Root cause — registration lambdas in
WindowTransform.cppdid not validate argument count; both functions accepted any arity and discarded the values silently.c) Fix matches root cause — adds the missing validation directly at the registration site, with the legacy behavior gated behind a compatibility setting per the follow-up directive.
d) Test intent preserved — new dedicated test added; existing
02478test updated to keep itsGROUPS BETWEEN ...purpose without depending on the old lenient behavior.e) Both directions demonstrated — verified manually that the original reproducer from the issue throws by default and works under
SETTINGS allow_rank_dense_rank_arguments = 1. New test passes 30/30 with randomized settings; 12 existing window function tests pass.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The window functions
RANKandDENSE_RANKnow reject arguments and throwNUMBER_OF_ARGUMENTS_DOESNT_MATCH, in line with the SQL standard. Previously, queries such asRANK(x) OVER (ORDER BY id)were silently accepted with the argument ignored, which was a frequent source of user confusion. To restore the previous lenient behavior, setallow_rank_dense_rank_arguments = 1. Closes #49526.Documentation entry for user-facing changes
The new
allow_rank_dense_rank_argumentssetting is documented inline insrc/Core/Settings.cpp, which feeds the setting documentation page.Closes #49526
Session: cron:clickhouse-ci-task-worker:20260507-194500
Version info
26.5.1.837