Skip to content

fix(parser): track backtick identifiers; unify quote-aware SQL scanning#200

Open
alvarogar4 wants to merge 1 commit into
mainfrom
alvaro/num-7479-consolidate-quote-aware-sql-scanning
Open

fix(parser): track backtick identifiers; unify quote-aware SQL scanning#200
alvarogar4 wants to merge 1 commit into
mainfrom
alvaro/num-7479-consolidate-quote-aware-sql-scanning

Conversation

@alvarogar4

Copy link
Copy Markdown
Member

Summary

Fixes #196 and #197 together, since #197 (the duplication) is the root cause of #196 (the bug).

#196chkit pull silently dropped projections on tables with a paren in a backtick column name. chkit's create-table body scanner tracked ' and " but not backtick identifiers, so a column named `weird)name` had its ) counted as structure, truncating the parsed column list. The table's projections (and a mangled ORDER BY/PRIMARY KEY) followed — the same silent failure as #183. Verified live: ClickHouse accepts such a column, and the projection is now captured (was []).

#197 — four copies of "scan SQL, ignore quoted regions", already diverged. splitTopLevelComma and the projection stripper tracked all three quote kinds; plugin-pull's normalizeWrappedTuple tracked none; the clickhouse body finder missed backticks. They now share one primitive — nextQuote in @chkit/core — plus shared stripWrappingParens and findMatchingParen. plugin-pull's divergent copy is deleted. The rule lives in one place and can't drift again.

Test plan

  • New sql-scan.test.ts locks in quote/backtick behavior for all three shared helpers
  • Parser regression tests: a backtick column name with a paren keeps its projection; backtick identifiers survive inside key clauses
  • Mutation-checked — removing backtick tracking from nextQuote fails 4 tests across the helpers and the parser (one fix point, enforced everywhere)
  • Behavior-preserving refactor: full suites green for core (303), clickhouse (33), plugin-pull (26), cli (262), plugin-obsessiondb (149); typecheck/lint/build clean
  • Live e2e: created a table with a `weird)name` column on ClickHouse 26.3 → listTableDetails now returns the projection (empty before)

Notes

This consolidates the quote-state machine only; it does not change ClickHouse's expression formatting reconciliation, which is the separate, larger #195.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Biy2vG7iixRiBsBBsFg5Nu

chkit pull dropped a table's projections and mangled its ORDER BY/PRIMARY
KEY when a column had a backtick-quoted name containing a paren, e.g.
`weird)name` (#196): the create-table body scanner counted that paren as
structure and truncated the parse.

Root cause was four separate copies of "scan SQL ignoring quoted regions"
that had drifted apart — plugin-pull's tracked no quotes, the clickhouse
body finder missed backticks (#197). They now share one quote-aware
primitive, nextQuote, in @chkit/core, plus shared stripWrappingParens and
findMatchingParen. splitTopLevelComma, the projection index normalizer, the
pull key-clause parser, and the create-table body finder all handle '...',
"...", and `...` identically, so the rule can't diverge again.

Closes #196
Closes #197

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Biy2vG7iixRiBsBBsFg5Nu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: create-table parser does not track backtick identifiers, silently dropping projections on tables with parens in a column name

1 participant