Skip to content

Implement separate KQL parser, tokenizer, lexer - #62668

Closed
kashwy wants to merge 5 commits into
ClickHouse:masterfrom
kashwy:implement-separate-kql-tokenizer
Closed

kashwy wants to merge 5 commits into
ClickHouse:masterfrom
kashwy:implement-separate-kql-tokenizer

Conversation

@kashwy

@kashwy kashwy commented Apr 15, 2024

Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • Improvement

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

Separate the KQL parser from the SQL parser by using a dedicated parser, tokenizer, lexer for KQL, This will prevent interference between SQL and KQL

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Apr 15, 2024
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-improvement Pull request with some product improvements label Apr 15, 2024
@robot-ch-test-poll1

robot-ch-test-poll1 commented Apr 15, 2024 •

Copy link
Copy Markdown
Contributor

This is an automated comment for commit 6b905ba with description of existing statuses. It's updated for the latest CI running

❌ Click here to open a full report in a separate page

Check nameDescriptionStatus
CI runningA meta-check that indicates the running CI. Normally, it's in success or pending state. The failed status indicates some problems with the PR⏳ pending
Integration testsThe integration tests report. In parenthesis the package type is given, and in square brackets are the optional part/total tests❌ failure
Performance ComparisonMeasure changes in query performance. The performance test report is described in detail here. In square brackets are the optional part/total tests❌ failure
Stress testRuns stateless functional tests concurrently from several clients to detect concurrency-related errors❌ failure
Successful checks
Check nameDescriptionStatus
A SyncThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
AST fuzzerRuns randomly generated queries to catch program errors. The build type is optionally given in parenthesis. If it fails, ask a maintainer for help✅ success
ClickBenchRuns [ClickBench](https://github.com/ClickHouse/ClickBench/) with instant-attach table✅ success
ClickHouse build checkBuilds ClickHouse in various configurations for use in further steps. You have to fix the builds that fail. Build logs often has enough information to fix the error, but you might have to reproduce the failure locally. The cmake options can be found in the build log, grepping for cmake. Use these options and follow the general build process✅ success
Compatibility checkChecks that clickhouse binary runs on distributions with old libc versions. If it fails, ask a maintainer for help✅ success
Docker keeper imageThe check to build and optionally push the mentioned image to docker hub✅ success
Docker server imageThe check to build and optionally push the mentioned image to docker hub✅ success
Docs checkBuilds and tests the documentation✅ success
Fast testNormally this is the first check that is ran for a PR. It builds ClickHouse and runs most of stateless functional tests, omitting some. If it fails, further checks are not started until it is fixed. Look at the report to see which tests fail, then reproduce the failure locally as described here✅ success
Flaky testsChecks if new added or modified tests are flaky by running them repeatedly, in parallel, with more randomization. Functional tests are run 100 times with address sanitizer, and additional randomization of thread scheduling. Integrational tests are run up to 10 times. If at least once a new test has failed, or was too long, this check will be red. We don't allow flaky tests, read the doc✅ success
Install packagesChecks that the built packages are installable in a clear environment✅ success
Mergeable CheckChecks if all other necessary checks are successful✅ success
PR CheckThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
Stateful testsRuns stateful functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc✅ success
Stateless testsRuns stateless functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc✅ success
Style checkRuns a set of checks to keep the code style clean. If some of tests failed, see the related log from the report✅ success
Unit testsRuns the unit tests for different release types✅ success
Upgrade checkRuns stress tests on server version from last release and then tries to upgrade it to the version from the PR. It checks if the new server can successfully startup without any errors, crashes or sanitizer asserts✅ success

@yakov-olkhovskiy yakov-olkhovskiy self-assigned this May 7, 2024
@clickhouse-gh

clickhouse-gh Bot commented Jun 25, 2024

Copy link
Copy Markdown
Contributor

Dear @yakov-olkhovskiy, this PR hasn't been updated for a while. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@clickhouse-gh

clickhouse-gh Bot commented Jul 30, 2024

Copy link
Copy Markdown
Contributor

Dear @yakov-olkhovskiy, this PR hasn't been updated for a while. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@clickhouse-gh

clickhouse-gh Bot commented Jun 8, 2025 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3aad414]

@alexey-milovidov

Copy link
Copy Markdown
Member

The implementation here wasn't as intended. Instead of implementing a separate Lexer and Parser, it copy-pasted most of the code, so it would be difficult to maintain.

@alexey-milovidov alexey-milovidov self-assigned this Jun 16, 2026
pull Bot pushed a commit to Mu-L/ClickHouse that referenced this pull request Aug 29, 2026
The dialect was contributed in 2022 and abandoned by its authors; the
rewrite they promised in ClickHouse#62668 was closed unmerged.  Since then it has
been emergency-disabled once (ClickHouse#59305) and gated behind
`allow_experimental_kusto_dialect` (ClickHouse#74224), and issue ClickHouse#61742 ("Remove
KQL support if this code will not be fixed") has stayed open.

The implementation translated a KQL token stream directly into
ClickHouse SQL *text* and re-parsed it.  Everything below follows from
that:

  - KQL string literals were spliced into generated SQL unescaped, so
    `T | where s contains "x') OR 1 = 1 OR ilike(s, 'y"` injected
    arbitrary expressions -- and `contains '50%'` matched `'50x'`
    because LIKE metacharacters passed through.
  - No types were available while translating, so 14 sites emitted
    runtime `toTypeName()` dispatch and datetimes were modelled as
    strings truncated to 27 characters.
  - Arguments were SQL text, so a dozen sites called `std::stoi` on it;
    `format_timespan(col, 'hh:mm')` failed with "stoi: no conversion".
  - 28 of the 237 registered functions were stubs that returned the raw
    KQL name into the generated SQL, including every `series_*`.
  - `let` bindings lived in a `static thread_local` map that, by its own
    comment, leaked between unrelated queries.

This commit removes the implementation and every trace of it: the
parser, the `kusto` dialect and its experimental setting, the `kusto`
value of `interval_output_format` and the interval serialization it
drove, the client/server call sites, the fuzzer and style-check
carve-outs, and the tests.  A correct implementation is added next.

Two notes on what was deliberately kept.  `ASTSelectQuery::normalize
ChildrenOrder` stays -- several other parsers use it -- with its comment
generalized.  `04305_parser_error_message_oob_101143.sh` stays as a
regression test for the error-formatter buffer overflow; its rationale
is rewritten, since the parser it originally exercised is now gone.

Release history in CHANGELOG.md, docs/changelogs/ and
SettingsChangesHistory.cpp is left untouched.
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-improvement Pull request with some product improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants