Skip to content

Failure: clickhouse-head-x86-with-analyzer-keeper / window_functions / window_functions - AssertionError: snapshot mismatch in aggregate_funcs over rows frame (topK / topKWeighted) #74

@CarlosFelipeOR

Description

@CarlosFelipeOR

Version: 25.12.1.229 (Head)


Description

Window Functions tests involving topK() and topKWeighted() began failing on ClickHouse >= 25.12.
The failure was caused by a change in the internal ordering of values returned by these aggregate functions when used inside window frames.

The set of returned values and their frequency ordering remain correct, but the ordering of values with equal frequency is no longer stable, unlike previous ClickHouse versions.
This breaks snapshot comparisons and also affects ORDER BY func semantics, since arrays are compared lexicographically.

According to the ClickHouse documentation, this new behavior is valid:

“The resulting array is sorted in descending order of approximate frequency of values (not by the values themselves).”

Previous versions happened to produce a deterministic value order, but this was not guaranteed.

Resolution

  • Added version-specific snapshots for topK() and topKWeighted() when running on ClickHouse >= 25.12.
  • Updated the test logic to automatically select the correct snapshot based on the ClickHouse version.
  • No upstream issue is required since the new behavior complies with the documented semantics of topK().
  • The regression suite now supports both older and newer ClickHouse versions without false failures.
  • Commits:

Failure Description:

1) Non-distributed – topK(salary)

Test path

/window functions/tests/non distributed/aggregate funcs/aggregate funcs over rows frame/func='topK(salary)'

Query

SELECT topK(salary) OVER (
    ORDER BY salary, empno
    ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
) AS func
FROM empsalary
ORDER BY func DESC

Error

AssertionError: Oops! Assertion failed

SnapshotError:
  filename: window_functions/tests/snapshots/common.py.tests.x86_64.snapshot
  name: _window_functions_tests_aggregate_funcs_aggregate_funcs_over_rows_frame_func__topK_salary__

snapshot_value:
    [5200,4800,5000,6000]
    [4800,5200,5000,6000]
    [4800,5200,4500,5000,6000]
    [4800,5200,4200,4500,5000,6000]
    [4800,5200,3900,4200,4500,5000,6000]
    [4800,5200,3500,3900,4200,4500,5000,6000]

actual_value:
    [5200,4800,6000,5000]
    [5200,4800,4200,5000,6000,4500]
    [5200,4800,3900,5000,6000,4200,4500]
    [5200,4800,3500,5000,6000,4200,3900,4500]
    [4800,5200,6000,5000]
    [4800,5200,4500,6000,5000]

2) Non-distributed – topKWeighted(salary, 1)

Test path

/window functions/tests/non distributed/aggregate funcs/aggregate funcs over rows frame/func='topKWeighted(salary, 1)'

Query

SELECT topKWeighted(salary, 1) OVER (
    ORDER BY salary, empno
    ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
) AS func
FROM empsalary
ORDER BY func DESC

Error

AssertionError: Oops! Assertion failed

SnapshotError:
  filename: window_functions/tests/snapshots/common.py.tests.x86_64.snapshot
  name: _window_functions_tests_aggregate_funcs_aggregate_funcs_over_rows_frame_func__topKWeighted_salary__1__

snapshot_value:
    [5200,4800,5000,6000]
    [4800,5200,5000,6000]
    [4800,5200,4500,5000,6000]
    [4800,5200,4200,4500,5000,6000]
    [4800,5200,3900,4200,4500,5000,6000]
    [4800,5200,3500,3900,4200,4500,5000,6000]

actual_value:
    [5200,4800,6000,5000]
    [5200,4800,4200,5000,6000,4500]
    [5200,4800,3900,5000,6000,4200,4500]
    [5200,4800,3500,5000,6000,4200,3900,4500]
    [4800,5200,6000,5000]
    [4800,5200,4500,6000,5000]

3) Distributed – topK(salary)

Test path

/window functions/tests/distributed/aggregate funcs/aggregate funcs over rows frame/func='topK(salary)'

Query

SELECT topK(salary) OVER (
    ORDER BY salary, empno
    ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
) AS func
FROM empsalary
ORDER BY func DESC

Error

AssertionError: Oops! Assertion failed (SnapshotError)

snapshot_value:
    [5200,4800,5000,6000]
    [4800,5200,5000,6000]
    [4800,5200,4500,5000,6000]
    [4800,5200,4200,4500,5000,6000]
    [4800,5200,3900,4200,4500,5000,6000]
    [4800,5200,3500,3900,4200,4500,5000,6000]

actual_value:
    [5200,4800,6000,5000]
    [5200,4800,4200,5000,6000,4500]
    [5200,4800,3900,5000,6000,4200,4500]
    [5200,4800,3500,5000,6000,4200,3900,4500]
    [4800,5200,6000,5000]
    [4800,5200,4500,6000,5000]

4) Distributed – topKWeighted(salary, 1)

Test path

/window functions/tests/distributed/aggregate funcs/aggregate funcs over rows frame/func='topKWeighted(salary, 1)'

Query

SELECT topKWeighted(salary, 1) OVER (
    ORDER BY salary, empno
    ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
) AS func
FROM empsalary
ORDER BY func DESC

Error

AssertionError: Oops! Assertion failed (SnapshotError)

snapshot_value:
    [5200,4800,5000,6000]
    [4800,5200,5000,6000]
    [4800,5200,4500,5000,6000]
    [4800,5200,4200,4500,5000,6000]
    [4800,5200,3900,4200,4500,5000,6000]
    [4800,5200,3500,3900,4200,4500,5000,6000]

actual_value:
    [5200,4800,6000,5000]
    [5200,4800,4200,5000,6000,4500]
    [5200,4800,3900,5000,6000,4200,4500]
    [5200,4800,3500,5000,6000,4200,3900,4500]
    [4800,5200,6000,5000]
    [4800,5200,4500,6000,5000]

CI Run

https://github.com/Altinity/clickhouse-regression/actions/runs/19776301887/job/56669336548

Artifacts and Reports

Artifacts will be uploaded to https://altinity-internal-test-reports.s3.amazonaws.com/index.html#clickhouse/25.12.1.229/19776301887/testflows/x86_64/with_analyzer/zookeeper/without_thread_fuzzer/window_functions/
Review report at https://altinity-internal-test-reports.s3.amazonaws.com/clickhouse/25.12.1.229/19776301887/testflows/x86_64/with_analyzer/zookeeper/without_thread_fuzzer/window_functions/report.html
Review new fails (nice) at https://altinity-internal-test-reports.s3.amazonaws.com/clickhouse/25.12.1.229/19776301887/testflows/x86_64/with_analyzer/zookeeper/without_thread_fuzzer/window_functions/nice-new-fails.log.txt


Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions