Skip to content

Conversation

@kyleconroy
Copy link
Collaborator

  • Handle CAST(expr AS alias AS Type) and CAST(expr alias AS Type) patterns
  • Support aliases on both expression and type in comma-style CAST
  • Update SUBSTRING to handle aliases on all arguments in FROM/FOR and comma styles
  • Update TRIM to handle aliases on trimChars and FROM expression
  • Add trimBoth function name for BOTH modifier
  • Update wrapWithAlias to replace existing aliases instead of double-wrapping

This enables the parser to correctly handle ClickHouse's special operator
alias syntax where expressions inside function arguments can have aliases.

- Handle CAST(expr AS alias AS Type) and CAST(expr alias AS Type) patterns
- Support aliases on both expression and type in comma-style CAST
- Update SUBSTRING to handle aliases on all arguments in FROM/FOR and comma styles
- Update TRIM to handle aliases on trimChars and FROM expression
- Add trimBoth function name for BOTH modifier
- Update wrapWithAlias to replace existing aliases instead of double-wrapping

This enables the parser to correctly handle ClickHouse's special operator
alias syntax where expressions inside function arguments can have aliases.
…atements

The query.sql had an extra standalone `;` on line 384 that was throwing off
statement numbering and causing parse errors. Removing it fixes all 39
pending explain_todo statements for this test.
When a dictionary is created with a database-qualified name like
sqllt.dictionary, the explain output now correctly shows both the
database and table identifiers, matching ClickHouse's EXPLAIN AST output.
- Add APPLY token to lexer
- Add Apply field to ast.Asterisk struct
- Add parseAsteriskApply function for parsing APPLY(func) and APPLY func syntax
- Add APPLY to expression precedence for proper infix parsing
- Update explain code to output ColumnsApplyTransformer nodes

This fixes 01470_columns_transformers test and many other tests that use
APPLY column transformers.
…ET TRANSACTION SNAPSHOT)

- Add BEGIN, COMMIT, ROLLBACK, TRANSACTION, SNAPSHOT tokens to lexer
- Add TransactionControlQuery AST node
- Add parseTransactionControl function to parser
- Add explain output for ASTTransactionControl

This fixes 01173_transaction_control_queries test and several other transaction-related tests.
Rename the special COMMENT token (for line comments like -- and /* */)
to LINE_COMMENT to avoid collision with the COMMENT SQL keyword needed
for ALTER TABLE COMMENT COLUMN and similar statements.
- Add COMMENT case to parseAlterCommand for COMMENT COLUMN syntax
- Add Comment field to AlterCommand struct for storing column comments
- Update explainAlterQuery to output database and table as separate
  identifiers when database is present
- Update AlterCommentColumn explain output to include comment literal
- Fix various tests that now pass with COMMENT COLUMN support
- Add Cleanup flag to OptimizeQuery for OPTIMIZE TABLE ... FINAL CLEANUP
- Update explain output to append _cleanup to table name when Cleanup=true
- Add AllColumns flag to InsertQuery for INSERT INTO table (*) syntax
- Update explain output for INSERT with (*) to show Asterisk child
- Update parser to handle both new syntaxes
- Add INTERSECT as a proper keyword token (was being parsed as identifier
  which caused it to be treated as an alias for function calls)
- Update parser to use token.INTERSECT instead of identifier check
- Fix explainSelectIntersectExceptQuery to wrap first operand in
  SelectWithUnionQuery when EXCEPT is present (matches ClickHouse behavior)
- Update metadata.json files to reflect newly passing explain tests

This fixes 12 INTERSECT/EXCEPT explain tests. Remaining failures require
parser changes to handle INTERSECT/EXCEPT operator precedence properly.
- Parser: Skip leading semicolons in ParseStatements to handle empty
  statements (just ';') gracefully
- Test: Skip empty semicolon statements in splitStatements to match
  ClickHouse behavior which doesn't count empty statements

This fixes the statement numbering mismatch that caused
03036_join_filter_push_down_equivalent_sets to fail, and also
fixes 02155_multiple_inserts_for_formats_with_suffix.
- Add OptionsString field to ExplainQuery to capture EXPLAIN options
- Update parser to capture options like "actions = 1" as strings
- Update explainViewExplain to output proper SELECT * FROM viewExplain() structure
- This matches ClickHouse's internal transformation of EXPLAIN as table source

Updates metadata for many passing explain tests.
- Add Source field to ast.Literal to store original source text
- Set Source field when parsing decimal float literals
- Use Source field in formatExprAsString for CAST operator syntax
- This preserves "0.0" instead of outputting "0" for zero floats

Fixes iceberg_bucket and other tests with float casting.
- Stop command parsing when encountering IDENT followed by DOT
- This allows qualified table names like sqllt.table to be parsed properly
- SYSTEM STOP MERGES sqllt.table now correctly shows children
- Only show explicit EXPLAIN type when it's not AST or PLAN (default)
- EXPLAIN SYNTAX correctly outputs 'EXPLAIN SYNTAX'
- EXPLAIN or EXPLAIN PLAN outputs just 'EXPLAIN'

Fixes many tests with EXPLAIN subqueries (comma_join, window functions, etc.)
- Add end-of-statement check to identify table names vs command parts
- Handle FAILPOINT and FOR contexts where following identifier is part of command
- Expand recognized SYSTEM command keywords (DICTIONARIES, REPLICAS, etc.)
- This allows commands like "SYSTEM STOP REPLICATED SENDS table" to properly
  capture "table" as a child identifier while keeping "SYSTEM DROP MARK CACHE"
  as a single command without children
- Detect qualified COLUMNS patterns when parsing dotted identifiers
- Parse test_table.COLUMNS(id) as QualifiedColumnsListMatcher
- Parse test_table.COLUMNS('pattern') as QualifiedColumnsRegexpMatcher
- Add parseQualifiedColumnsMatcher function to handle these cases
ClickHouse canonicalizes trim() to trimBoth() in EXPLAIN AST output.
This fixes many text/token index tests that use trim().
- Add AuthenticationValues field to CreateQuery for storing password/hash values
- Update parseCreateUser and parseAlterUser to capture BY 'value' expressions
- Update explain output to show AuthenticationData with literal children
- Use token.BY and token.WITH keywords instead of IDENT checks

Fixes authentication data capture in EXPLAIN AST output for CREATE USER and
ALTER USER statements with IDENTIFIED WITH method BY 'value' syntax.
- Add ArrayJoin field to TablesInSelectQueryElement struct
- Handle ARRAY JOIN and LEFT ARRAY JOIN in parseTableElementWithJoin
- Include token.ARRAY in isJoinKeyword check
- Update explain output to handle ArrayJoin in table elements

This enables parsing of queries like:
  FROM table ARRAY JOIN col INNER JOIN other_table USING (...)

where ARRAY JOIN is followed by regular JOINs.
- Add LimitByLimit field to store the limit value before BY when
  there's a second LIMIT after BY (e.g., LIMIT 1 BY x LIMIT 3)
- Add LimitByLimit to children count for SelectQuery
- Handle BY after OFFSET for syntax like LIMIT 2 OFFSET 1 BY ALL
- Update explain output to correctly order LimitByLimit, LimitBy, Limit

This resolves 03570_limit_by_all and many other LIMIT BY related tests.
- DETACH_PARTITION is normalized to DROP_PARTITION in EXPLAIN AST
  (matching ClickHouse behavior)
- PARTITION ALL is output as Partition_ID (empty) instead of
  Partition with Identifier ALL

This resolves 00753_alter_attach and many other alter partition tests.
@kyleconroy kyleconroy merged commit 918155d into main Dec 31, 2025
1 check passed
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.

3 participants