Skip to content

Remove kql_array_sort_asc and kql_array_sort_desc - #108101

Merged
Algunenano merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/remove-kql-array-sort-asc-desc
Jun 22, 2026
Merged

Algunenano merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/remove-kql-array-sort-asc-desc

Conversation

@groeneai

@groeneai groeneai commented Jun 22, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • Backward Incompatible Change

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Removed the experimental KQL (Kusto) functions array_sort_asc and array_sort_desc, and their SQL backends kql_array_sort_asc and kql_array_sort_desc. These functions were experimental, implemented with low quality, and the source of correctness and parser bugs. Queries using these names now return UNKNOWN_FUNCTION.

Description

Per maintainer request (#107634), this removes kql_array_sort_asc / kql_array_sort_desc and the KQL array_sort_asc / array_sort_desc that map to them, with all associated complications.

These functions returned Tuple(Array, ...), which required two special cases that are also removed here:

Also fixes #101259 (the null_last=false per-row bug) by removing the affected functions.

Removed: src/Functions/Kusto/KqlArraySort.cpp (the whole Functions/Kusto directory had no other sources) and its CMake registration; the ArraySortAsc / ArraySortDesc KQL parser classes, enum values and factory entries; the subscript-rewrite special case; the array_sort alias handling; affected tests, fuzzer dictionary entries, and KQL conformance sub-cases.

Verified locally (debug build): the SQL and KQL names now produce UNKNOWN_FUNCTION; all 22 KQL stateless tests pass; the rest of KQL is unaffected.

Version info

  • Merged into: 26.6.1.1135

Remove the KQL compatibility functions array_sort_asc / array_sort_desc
and their SQL backends kql_array_sort_asc / kql_array_sort_desc entirely,
together with all associated complications.

These functions are experimental (KQL / Kusto dialect) and were implemented
with low quality. They returned Tuple(Array, ...), which forced two special
cases elsewhere:

* a subscript-rewrite hack in ParserExpressionImpl (ExpressionListParsers.cpp)
  that turned arrayElement into tupleElement on their results. This was the
  source of the inconsistent AST formatting bug STID 1941-1bfa.
* tuple-aware alias handling in ParserKQLQuery (the array_sort-only [1] suffix
  and the multi-alias "(a, b) = ..." branch).

Removed:
* src/Functions/Kusto/KqlArraySort.cpp (the whole Functions/Kusto directory,
  it had no other sources) and its CMake registration.
* The ArraySortAsc / ArraySortDesc KQL parser classes, their enum values, and
  factory entries.
* The subscript-rewrite special case in ExpressionListParsers.cpp.
* The array_sort-specific alias handling in ParserKQLQuery.cpp.
* Tests, fuzzer dictionary entries, and KQL conformance sub-cases that used
  these functions.

An unknown function name now produces a normal UNKNOWN_FUNCTION error in both
the SQL and KQL dialects, and the rest of KQL is unaffected.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate

# Question Answer
a Deterministic repro? Yes. This is a directive-driven removal, not a flaky-test fix. The functions to remove are deterministic: SELECT kql_array_sort_asc([3,1,2]) and the KQL print array_sort_asc(...) both ran on demand before this change.
b Root cause explained? The two functions are experimental, low-quality, and return Tuple(Array, ...), which forced two parser special cases: the arrayElement to tupleElement subscript rewrite in ExpressionListParsers.cpp (the source of the inconsistent-AST LOGICAL_ERROR, #106850 / STID 1941-1bfa) and the array_sort-only alias handling in ParserKQLQuery.cpp. The per-row null_last=false bug is #101259. Removing the functions removes both bug classes and both special cases.
c Fix matches root cause? Yes. Rather than patching each downstream complication, the functions and all associated complications are removed entirely, per the maintainer directive on #107634.
d Test intent preserved / new tests added? No test coverage is weakened for surviving behavior. Tests that existed only to exercise the removed functions are deleted; KQL conformance sub-cases that used array_sort_asc only to stabilize non-deterministic make_set output are removed (no KQL array-sort alternative remains). All other KQL test assertions are preserved unchanged.
e Both directions demonstrated? Before: the functions existed and kql_array_sort_desc(...)[1] triggered the AST round-trip bug. After (this build): kql_array_sort_asc/kql_array_sort_desc return UNKNOWN_FUNCTION (SQL), array_sort_asc/array_sort_desc return "not a supported kusto function" (KQL), and formatQuerySingleLine('SELECT kql_array_sort_desc([3,1,2])[1]') round-trips cleanly. All 22 KQL stateless tests pass.
f Fix is general, not a narrow patch? Yes. All traces are removed: SQL backend (Functions/Kusto/KqlArraySort.cpp + the whole directory and its CMake registration), KQL parser classes/enum/factory entries, the subscript-rewrite special case, the alias handling, fuzzer dictionary entries, and tests/conformance cases. `grep -rniE 'kql_array_sort

Session id: cron:clickhouse-worker-slot-4:20260622-035600

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @alexey-milovidov @yakov-olkhovskiy could you review this? It removes the experimental KQL functions array_sort_asc/array_sort_desc and their SQL backends kql_array_sort_asc/kql_array_sort_desc entirely, along with the two parser special cases they required (the arrayElement->tupleElement subscript rewrite in ExpressionListParsers.cpp and the array_sort-only alias handling in ParserKQLQuery.cpp). Removing them also closes #106850 and #101259.

@clickhouse-gh

clickhouse-gh Bot commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f130bf5]

Summary: ✅


AI Review

Summary

This PR removes the experimental KQL array_sort_asc / array_sort_desc functions and their SQL backends kql_array_sort_asc / kql_array_sort_desc, along with the parser special cases that existed only for those functions. The current head also adds focused regression coverage for the new UNKNOWN_FUNCTION behavior and the formatter round-trip case from #106850. I did not find any remaining correctness issues that need inline review comments.

Missing context / blind spots
  • ⚠️ I could not run the stateless test locally because this checkout has no build directory or clickhouse / clickhouse-local binary. The direct Praktika report URL from the robot comment currently returned zero test rows; a completed CI run would close this gap.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-backward-incompatible Pull request with backwards incompatible changes label Jun 22, 2026
Covers the post-removal behavior of removing kql_array_sort_asc /
kql_array_sort_desc and the KQL array_sort_asc / array_sort_desc names:

- SELECT kql_array_sort_asc/desc([1]) now reports UNKNOWN_FUNCTION.
- KQL print array_sort_asc/desc(dynamic([1])) is rejected by the parser
  (clientError UNKNOWN_FUNCTION).
- The ClickHouse#106850 repro round-trips: with the arrayElement -> tupleElement
  subscript rewrite gone, formatQuerySingleLine is idempotent for both
  the trailing-subscript and the subscript-followed-by-operator forms.
  On master the latter was not idempotent (the format1 != format2
  mismatch aborted executeQueryImpl with an inconsistent-AST
  LOGICAL_ERROR).

The backward-incompatible removal and the parser-hack cleanup are now
covered so they cannot regress silently.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Jun 22, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate (HEAD f130bf5, regression test for the KQL array_sort removal)

# Question Answer
a Deterministic repro? Yes. On master HEAD: SELECT kql_array_sort_asc([1]) returns ([1]) (no throw), KQL print array_sort_asc(dynamic([1])) throws ILLEGAL_TYPE_OF_ARGUMENT (not UNKNOWN_FUNCTION), and formatQuerySingleLine(formatQuerySingleLine('SELECT kql_array_sort_desc([3,1,2])[1] - 1')) = formatQuerySingleLine(...) returns 0. All three diverge from the post-removal contract on demand.
b Root cause explained? The PR removes the functions and the arrayElement -> tupleElement subscript rewrite (ExpressionListParsers.cpp). That rewrite only fired when the subscript was the last operator, so kql_array_sort_desc(...)[1] formatted as .1 but ...[1] - 1 kept [1]; re-parsing the latter produced .1, so format1 != format2 and executeQueryImpl aborted with an inconsistent-AST LOGICAL_ERROR (#106850). With the rewrite and functions gone, both forms format stably and the names resolve to UNKNOWN_FUNCTION.
c Fix matches root cause? This change is the committed test for the removal already in this PR; it asserts exactly the three behaviors the removal produces (UNKNOWN_FUNCTION for SQL + KQL names, idempotent formatting of the #106850 subscript forms).
d Test intent preserved / new tests added? New negative regression test 04402_kql_array_sort_removed.sql added; replaces the deleted positive coverage with assertions on the new contract. Parallel-safe (pure query/error assertions, no files, no no-parallel).
e Both directions demonstrated? Yes. Passes 20/20 with randomization on the PR branch; every assertion fails on master HEAD (function exists / wrong error class / idempotence returns 0).
f Fix is general, not a narrow patch? Covers both _asc and _desc, both surface syntaxes (SQL backend name and KQL name), and both #106850 subscript forms (trailing subscript and subscript-then-operator). No code change in this commit; it is test-only coverage for the removal.

Session id: cron:clickhouse-worker-slot-1:20260622-064100

@Algunenano Algunenano removed the manual approve Manual approve required to run CI label Jun 22, 2026
@Algunenano Algunenano self-assigned this Jun 22, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.20% 85.30% +0.10%
Functions 92.50% 92.60% +0.10%
Branches 77.50% 77.50% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 23/25 (92.00%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 6 line(s) · Uncovered code

Full report · Diff report

@Algunenano
Algunenano added this pull request to the merge queue Jun 22, 2026
Merged via the queue into ClickHouse:master with commit be3417e Jun 22, 2026
329 of 330 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-backward-incompatible Pull request with backwards incompatible changes pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

kql_array_sort null_last=false uses only first row's NULL index for all rows

4 participants