Skip to content

Fix contextual keyword parsing - #327

Open
git-hulk wants to merge 1 commit into
masterfrom
codex/fix-contextual-keyword-parsing
Open

git-hulk wants to merge 1 commit into
masterfrom
codex/fix-contextual-keyword-parsing

Conversation

@git-hulk

@git-hulk git-hulk commented Sep 14, 2026

Copy link
Copy Markdown
Member

Fix DATE and TIMESTAMP literals by consuming the type keyword before parsing the following string. Disambiguate projection EXCEPT modifiers from EXCEPT set operations using SELECT lookahead, without changing the AST or global keyword rules.

Before applying this PR:

  • SELECT DATE '2024-01-01' and SELECT TIMESTAMP '2024-01-01 00:00:00' failed because the type keyword was still current when the string was parsed.
  • SELECT 1 EXCEPT SELECT 2 failed because EXCEPT was treated as a projection modifier and expected modifier arguments.

After this PR:

  • Typed date literals, keyword identifiers and aliases, projection modifiers, and EXCEPT set operations parse in their production-specific contexts.
  • Invalid forms such as SELECT * EXCEPT FROM t and SELECT 1 EXCEPT 2 remain rejected.

Add focused parser tests and golden fixtures for the supported forms.

Verification: make test; pinned golangci-lint v1.53.3; ClickHouse local syntax checks for positive and negative cases.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 14, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-14T10:10:18.902536Z 6942660 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6942660361

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread parser/parser_column.go
Comment on lines +583 to +587
literalPos := p.Pos()
savedState := p.lexer.saveState()
_ = p.lexer.consumeToken()
if p.matchTokenKind(TokenKindString) {
return p.parseString(literalPos)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve the DATE and TIMESTAMP literal type

When a caller parses and formats a typed literal such as SELECT DATE '2024-01-01', this returns a plain StringLiteral after consuming the type keyword, so formatting produces SELECT '2024-01-01' (as the new golden file demonstrates). That changes the expression from a typed Date/Timestamp literal into a String and can alter comparisons, overload resolution, and result schemas; the AST must retain and re-emit the consumed literal type.

Useful? React with 👍 / 👎.

Comment thread parser/parser_column.go
modifiers := make([]*FunctionExpr, 0)
for {
if p.matchKeyword(KeywordExcept) || p.matchKeyword(KeywordApply) || p.matchKeyword(KeywordReplace) {
if (p.matchKeyword(KeywordExcept) && !p.peekKeyword(KeywordSelect)) || p.matchKeyword(KeywordApply) || p.matchKeyword(KeywordReplace) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Recognize parenthesized EXCEPT query operands

When the right operand is parenthesized, as in SELECT 1 EXCEPT (SELECT 2), the next token is ( rather than SELECT, so this branch consumes EXCEPT as a select-item modifier. The parser consequently leaves SelectQuery.Except nil and formats the statement as SELECT 1 EXCEPT(SELECT 2) instead of representing the set operation, even though parseSelectQuery explicitly supports parenthesized operands; the modifier/set-operation disambiguation must account for this form.

Useful? React with 👍 / 👎.

Fix DATE and TIMESTAMP literals by consuming the type keyword before parsing the following string. Disambiguate projection EXCEPT modifiers from EXCEPT set operations using SELECT lookahead, without changing the AST or global keyword rules.

Before applying this PR:

- SELECT DATE '2024-01-01' and SELECT TIMESTAMP '2024-01-01 00:00:00' failed because the type keyword was still current when the string was parsed.
- SELECT 1 EXCEPT SELECT 2 failed because EXCEPT was treated as a projection modifier and expected modifier arguments.

After this PR:

- Typed date literals, keyword identifiers and aliases, projection modifiers, and EXCEPT set operations parse in their production-specific contexts.
- Invalid forms such as SELECT * EXCEPT FROM t and SELECT 1 EXCEPT 2 remain rejected.

Add focused parser tests and golden fixtures for the supported forms.

Verification: make test; pinned golangci-lint v1.53.3; ClickHouse local syntax checks for positive and negative cases.
@git-hulk
git-hulk force-pushed the codex/fix-contextual-keyword-parsing branch from 6942660 to 4027b79 Compare September 14, 2026 10:19
@git-hulk git-hulk changed the title codex/fix contextual keyword parsing Fix contextual keyword parsing Sep 14, 2026
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.

1 participant