Skip to content

Fixed keyword escaping for "TOP" - #106817

Draft
EilRoviSoft wants to merge 1 commit into
ClickHouse:masterfrom
EilRoviSoft:dev/mdb-45169
Draft

EilRoviSoft wants to merge 1 commit into
ClickHouse:masterfrom
EilRoviSoft:dev/mdb-45169

Conversation

@EilRoviSoft

@EilRoviSoft EilRoviSoft commented Jun 9, 2026 •

Copy link
Copy Markdown

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fixed bad escaping for column's name if reserved keyword TOP is used for it.

@EilRoviSoft

Copy link
Copy Markdown
Author

This is reproducable on current head with:

create table test_3 (TOP String) engine = MergeTree() order by TOP;

create view test_4 (c String) as with A as (select `TOP` AS c from test_3)  select c from A;

show create test_4;

Output:

Received exception from server (version 26.6.1):
Code: 62. DB::Exception: Received from localhost:9000. DB::Exception: Syntax error (in file store/38e/38efbf7e-17a6-40d9-a310-d1392812ae57/test_4.sql): failed at position 116 (AS) (line 7, col 20): AS c
        FROM default.test_3
    )
SELECT c
FROM
A
. Expected one of: token, OpeningRoundBracket, number. (SYNTAX_ERROR)
(query: show create test_4;)

@EilRoviSoft

Copy link
Copy Markdown
Author

But I don't how to fix column's name escaping in general if keyword is used for it.

@nikitamikhaylov nikitamikhaylov added the can be tested Allows running workflows for external contributors label Jun 9, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4db00b5]

Summary: ❌

job_name test_name status info comment
Finish Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/new_tests_check.py FAIL

AI Review

Summary

This PR changes ParserSelectQuery so a leading TOP token is treated as the TOP N clause only when a numeric length follows; otherwise parsing rolls back and the select list can treat TOP as an identifier. The approach is narrow and matches the reported SHOW CREATE failure, but the bug-fix contract is not proven because there is no regression test for the persisted view round trip.

Missing context / blind spots
  • ⚠️ I could not run a focused local stateless test because this checkout has no ClickHouse build directory; a regression test in the PR would close this gap.
Tests
  • ⚠️ src/Parsers/ParserSelectQuery.cpp:199 The PR fixes a user-visible parser/formatter round-trip bug but adds no focused stateless test. Please add the reported repro shape: create a table with column TOP, create a view selecting `TOP` AS c through a CTE, then run SHOW CREATE VIEW and verify it succeeds.
Final Verdict

Status: ⚠️ Request changes

Minimum required action: add the focused regression test for the TOP column view SHOW CREATE round trip.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jun 9, 2026
else
{
pos = pos_before_top;
expected = expected_before_top;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bug fix needs focused regression coverage. The change is a speculative parser rollback for TOP, but the PR does not add a stateless test for the reported persisted-view round trip, so a future formatter/parser change can reintroduce invalid SHOW CREATE output without failing CI. Please add a small test using the repro shape: create a table with column TOP, create a view that selects `TOP` AS c through a CTE, then run SHOW CREATE VIEW and verify it succeeds.

@clickhouse-gh

clickhouse-gh Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.60% 84.60% +0.00%
Functions 92.30% 92.30% +0.00%
Branches 77.20% 77.30% +0.10%

Changed lines: Changed C/C++ lines covered by tests: 15/21 (71.43%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 1 line(s) · Uncovered code

Full report · Diff report

@clickhouse-gh

clickhouse-gh Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Dear @EilRoviSoft, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message.

@abashkeev abashkeev added the comp-sql-syntax SQL/grammar parsing, AST nodes, syntax-level features. label Sep 4, 2026
@maxknv maxknv added the external Author is not a member of the ClickHouse organization label Nov 2, 2026

This branch has not been deployed

No deployments
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 comp-sql-syntax SQL/grammar parsing, AST nodes, syntax-level features. external Author is not a member of the ClickHouse organization pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants