fix(pull,drift): parse clauses past column list; treat derived primary key as clean#198
Merged
alvarogar4 merged 1 commit intoJul 20, 2026
Conversation
…ved primary key as clean Two related bugs on tables whose ORDER BY sits alongside a projection or a derived primary key. Both verified against live ClickHouse 26.3. #190 — chkit pull leaked the engine into orderBy/primaryKey. The clause parsers matched the first ENGINE/ORDER BY/PRIMARY KEY/PARTITION BY/TTL/ SETTINGS keyword anywhere in SHOW CREATE TABLE. A projection whose SELECT body contains ORDER BY (or a column-level TTL) sits in the column list, before the table-level clauses, so the parser matched the inner keyword and swallowed the engine into the clause. Table-level clauses are now parsed only from the portion after the column list. #194 — chkit drift always reported primary_key_mismatch for tables whose PRIMARY KEY is derived from ORDER BY. ClickHouse omits the derived key from SHOW CREATE, but the canonicalized schema carries it, so the two never matched. Drift now applies the same derivation to the live side; a genuine primary-key difference is still reported. The two compound: fixing #190 makes pull emit a valid ORDER BY-only schema, and #194 makes that schema read clean against its source table. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Biy2vG7iixRiBsBBsFg5Nu
alvarogar4
deleted the
alvaro/num-7479-drift-primary-key-and-pull-engine-clause
branch
July 20, 2026 10:29
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #190 and #194 — two compounding bugs on tables whose
ORDER BYis declared alongside a projection or a derived primary key. Both verified against live ClickHouse 26.3.#190 —
chkit pullleaked the engine intoorderBy/primaryKey. The clause parsers matched the firstENGINE/ORDER BY/PRIMARY KEY/PARTITION BY/TTL/SETTINGSkeyword anywhere inSHOW CREATE TABLE. A projection whoseSELECTbody containsORDER BY(the reporter's case) — or a column-levelTTL— sits in the column list, before the table-level clauses, so the parser matched the inner keyword and swallowed the engine string into the clause:Table-level clauses are now parsed only from the portion of the query after the column list.
#194 —
chkit driftalways reportedprimary_key_mismatchfor tables whosePRIMARY KEYis derived fromORDER BY. ClickHouse omits the derived key fromSHOW CREATE, but the canonicalized schema carries it (canonical.ts), so the live side ('') and schema side ((a, b)) never matched. Drift now applies the same derivation to the live side.The two compound: fixing #190 makes pull emit a valid
ORDER BY-only schema, and #194 makes that schema read clean against its source table.Test plan
typecheck+lintclean; touched packages green (core/clickhouse/plugin-pull/cli)SELECT ... ORDER BY, replicated engine with{cluster}/{replica}params) parses every clause correctly; plus a column-levelTTLcase — both query shapes confirmed against a live instance as what ClickHouse actually emitsprimary_key_mismatchpull(cleanorderBy/primaryKey, no engine text) →generate→driftreportsnoScope
Kept to #190 and #194. The related #196 (parser doesn't track backtick identifiers) and #197 (duplicated paren-stripping in plugin-pull) are untouched — #196 is a separate, rarer parse gap, and #197's helper backs key-clause parsing that this PR doesn't need to move.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Biy2vG7iixRiBsBBsFg5Nu