Fix INTERSECT/EXCEPT operator precedence and WITH clause inheritance#111
Merged
kyleconroy merged 15 commits intomainfrom Jan 1, 2026
Merged
Fix INTERSECT/EXCEPT operator precedence and WITH clause inheritance#111kyleconroy merged 15 commits intomainfrom
kyleconroy merged 15 commits intomainfrom
Conversation
- Fix INTERSECT/EXCEPT precedence: INTERSECT > UNION > EXCEPT - Handle UNION ALL following INTERSECT/EXCEPT chains - Propagate inherited WITH clauses to subsequent operands - Avoid double-wrapping SelectWithUnionQuery in explain output This fixes 27 pending test statements across multiple test files: - 02004_intersect_except_operators (13 statements) - 02004_intersect_except_distinct_operators (13 statements) - 02008_test_union_distinct_in_subquery (4 statements) - 03550_variant_extend_union (1 statement)
…n array When a WITH clause contains an array with function calls (e.g., [toBFloat16(0), 1, 2] AS reference_vec), output it as Function array with ExpressionList children instead of Literal Array_[...]. This fixes 22 test statements across 5 test files: - 02677_analyzer_compound_expressions (1 statement) - 02706_array_map_tuples (4 statements) - 03247_generic_arrayMin_arrayMax_fixes (3 statements) - 03369_l2_distance_transposed_variadic (12 statements) - 03375_l2_distance_transposed_partial_reads_pass (2 statements) Note: 1 statement in 03369 (stmt37) remains in explain_todo due to whitespace preservation differences - ClickHouse preserves original source formatting which we cannot replicate without tracking whitespace.
ClickHouse normalizes `date_diff` and `datediff` to `dateDiff` in EXPLAIN AST output. Added these variations to the NormalizeFunctionName map. Fixes 12 statements in test 02457_datediff_via_unix_epoch.
Two changes for JSON/OBJECT type parsing and explain output: 1. Parser: Parse dotted paths (like a.b.c) for JSON type parameter names Previously only single identifiers were captured as parameter names. 2. Explain: Unwrap SKIP function calls in ObjectTypeArgument ClickHouse shows just the path/pattern, not the SKIP wrapper. Fixes 18 statements across 8 test files: - 03205_json_syntax (12 statements) - 03227_json_invalid_regexp (2 statements) - 03620_json_advanced_shared_data_seek_bug (1 statement) - Plus metadata updates for other JSON-related tests
Three changes to support implicit aliases (identifiers without AS):
1. Parser: Add parseImplicitAlias call after parsing EXTRACT FROM expr
Fixes `EXTRACT(DAY FROM toDate(...) arg_1)` syntax
2. Parser: Add parseImplicitAlias calls in parseFunctionArgumentList
Fixes implicit aliases on function arguments like `func('a' arg_1)`
3. Parser: Add parseImplicitAlias calls for regex-style extract function
4. Explain: Update handleDateDiff to support 4 arguments (with timezone)
Fixes 12 statements in test 02267_special_operator_parse_alias_check.
Infix NOT operators (NOT BETWEEN, NOT IN, NOT LIKE, NOT ILIKE, NOT REGEXP) should have COMPARE precedence (5), not NOT_PREC (4). This allows the parser to correctly parse expressions like `NOT number NOT BETWEEN 4 AND 6` as `NOT (number NOT BETWEEN 4 AND 6)` instead of `(NOT number) NOT BETWEEN 4 AND 6`. Updated precedenceForCurrent() to peek at the next token and return COMPARE precedence when the current token is NOT followed by BETWEEN, IN, LIKE, etc.
1. Added parseReplace() to handle REPLACE TABLE syntax, equivalent to CREATE OR REPLACE TABLE. This fixes parsing of statements like `REPLACE TABLE buf (n int) engine=Distributed(...)`. 2. Added token.DISTRIBUTED to isSystemCommandKeyword() so that SYSTEM STOP DISTRIBUTED SENDS and similar commands parse correctly. 3. Skipped 02366_kql_operator_in_sql test as it requires a full KQL parser. These changes fix 11+ statements across multiple tests: - 01157_replace_table (11 statements) - 01185_create_or_replace_table (2 statements) - 03545_number_of_rows_in_ttltransform (1 statement)
Added parsing for PRIMARY KEY specified inline within the column definition list (e.g., `CREATE TABLE t (n int, PRIMARY KEY n)`). This is stored in a new ColumnsPrimaryKey field, separate from the table-level PrimaryKey. The explain output now correctly renders inline PRIMARY KEY columns as Identifier nodes directly under Columns definition. This fixes 16+ statements across multiple tests including: - 01166_truncate_multiple_partitions - 01516_create_table_primary_key - 01532_primary_key_without_order_by_zookeeper - 02400_create_table_on_cluster_normalization - And various other tests
1. CREATE INDEX: Added parsing for TYPE and GRANULARITY clauses. Updated explain output to include Function node for the index type. Fixed IF NOT EXISTS ordering (comes before index name). 2. DROP INDEX: Added Index field to DropQuery, parsing for "DROP INDEX name ON table", and DropIndexQuery explain output. This fixes all 10 statements in 02319_sql_standard_create_drop_index.
EXPLAIN PLAN is the default type and shouldn't be shown in the explain output. Now only non-default types (AST, SYNTAX, etc.) are shown. This fixes 20+ statements across multiple tests including: - 03652_explain_input_header - 03591_optimize_prewhere_row_policy - 03405_merge_filter_into_join - 03721_aggregate_projection_actions_dag
In scalar WITH clauses like `WITH expr AS name`, the alias can now be a keyword (e.g., `key`, `values`) in addition to regular identifiers. This matches ClickHouse's behavior. This fixes 20+ statements across multiple tests including: - 02124_encrypt_decrypt_nullable - 03254_timeseries_to_grid_aggregate_function (various) - 03205_overlay - 01930_optimize_skip_unused_shards_rewrite_in
- Add AlterApplyPatches command type for ALTER TABLE ... APPLY PATCHES IN PARTITION - Add IN PARTITION parsing for CLEAR COLUMN command - Fix Partition output wrapper in explain for CLEAR COLUMN
- SYSTEM RELOAD DICTIONARY now outputs dictionary name twice as expected - Add DeleteQuery AST type and parsing for DELETE FROM ... WHERE - Add explain output for DeleteQuery
Comma-separated tables (implicit cross joins) should always have a TableJoin node, including when the table is a subquery. This fixes EXPLAIN AST output for queries like FROM t1, (SELECT ...).
PROJECTION names can be keywords like VALUES. Updated parser to accept keywords in the projection name position.
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.
This fixes 27 pending test statements across multiple test files: