Add support for ANY/ALL comparison operators with subqueries#110
Merged
kyleconroy merged 20 commits intomainfrom Jan 1, 2026
Merged
Add support for ANY/ALL comparison operators with subqueries#110kyleconroy merged 20 commits intomainfrom
kyleconroy merged 20 commits intomainfrom
Conversation
Implement proper handling of SQL standard quantified comparison operators (x op ANY (subquery) and x op ALL (subquery)) in the parser and explain module. - Parser now encodes both the comparison operator and modifier in the function name (e.g., anyEquals, allLess, anyGreaterOrEquals) - Explain module transforms these to ClickHouse's internal representation with appropriate aggregate functions (max/min/singleValueOrNull) - Fixed all 15 failing tests in 02007_test_any_all_operators
…rmatting - Add OFFSET output to explainSampleClause as second SampleRatio line - Update TableExpression children count to include OFFSET - Add sourceToFraction to use Literal.Source field for precision - Handle scientific notation (2e-2 -> 2/100) and decimal (0.40 -> 40/100) - Fixes all 15 failing statements in 00276_sample test
Map the <=> operator to isNotDistinctFrom function in OperatorToFunction. Fixes all 15 failing statements in 03611_null_safe_comparsion test.
…ements - Add Format field to CreateQuery, AlterQuery, and DropQuery AST nodes - Extract FORMAT from inner SelectQuery and move to CreateQuery for views - Add inCreateQueryContext flag to prevent FORMAT duplication in explain - Update explain output for AlterQuery to include FORMAT as child - Handle FORMAT Null in parser for ALTER TABLE statements This fixes 02006_test_positional_arguments_on_cluster and enables FORMAT clause handling for various statement types.
- Add parseSelectWithUnionOnly for parsing EXCEPT operands that may contain UNION/UNION ALL (since UNION has higher precedence than EXCEPT) - Add parseIntersectExceptWithFirstOperand to handle UNION followed by INTERSECT/EXCEPT creating proper SelectIntersectExceptQuery wrapper - Fix parsing of queries like: select 1 union all select 2 except select 3 which should parse as: (select 1 union all select 2) except (select 3) This fixes parse errors for complex queries mixing UNION and EXCEPT.
Parse dotted column names like n.y for ClickHouse nested columns. After parsing the initial identifier, the parser now continues to accumulate dot-separated parts into a single column name. This fixes ALTER TABLE ADD COLUMN statements with nested column references and enables many additional tests across multiple test files.
- Handle UnaryExpr (e.g., -100) in formatBinaryExprForType - Add escapeStringForTypeParam for proper double-escaping of special characters in type parameters (backslash, tab, quotes, etc.) - Type parameters in DataType need extra escaping since they're embedded inside another string literal in EXPLAIN output This fixes CAST to Enum types with negative values and escape sequences.
…rmat When an array literal with an alias contains function calls (e.g., [hex(number)] AS i), it should be rendered as "Function array" instead of "Literal Array_[...]". This aligns with ClickHouse's EXPLAIN AST output which expands array literals containing expressions. Added check for *ast.FunctionCall in explainAliasedExpr's array handling to trigger Function array format when arrays contain function calls. This fixes multiple tests including 00113_shard_group_array, 03447_window_functions_distinct, 03261_tuple_map_to_json_cast, and 03393_non_constant_second_argument_for_in.
Go 1.13+ supports parsing hex floats via strconv.ParseFloat. Updated the parser to properly parse hex float literals (e.g., 0x1.f7ced916872b0p-4) as Float64 values instead of storing them as strings. This fixes 01433_hex_float and 03747_float_parsing_subnormal tests.
For empty tuples with aliases like `() AS a`, output `ExpressionList` without the `(children 0)` suffix to match ClickHouse's EXPLAIN AST. This fixes 02891_empty_tuple test.
Add containsNonLiteralInNested helper that recursively checks nested arrays and tuples for identifiers and function calls, ensuring proper Function tuple/array output format instead of Literal format.
The parseParenthesizedSelect function was skipping parenthesized content when it didn't find SELECT or WITH immediately after the opening paren. Now it also allows LPAREN to trigger proper recursive parsing of nested parenthesized SELECT statements.
ClickHouse normalizes -0 to UInt64_0 since negative zero equals zero. This fix ensures the explain output matches for negate(-0) expressions.
When parsing type parameters like QBit(BFloat16, 3), BFloat16 needs to be recognized as a data type name so it's output as DataType instead of Identifier.
ClickHouse supports standalone UPDATE statements as syntactic sugar for ALTER TABLE ... UPDATE. This adds: - UpdateQuery AST node - Parser for UPDATE table SET col=expr WHERE condition - Explain output for UpdateQuery and Assignment nodes This fixes many lightweight UPDATE (lwu) tests.
Add explainExistsExprWithAlias function to handle EXISTS expressions that have an alias (e.g., EXISTS (SELECT 1) AS mycheck). The alias is now correctly included in the Function exists output.
Implements parsing and EXPLAIN output for the INTERPOLATE clause used with ORDER BY ... WITH FILL. The INTERPOLATE clause allows specifying how values should be filled for interpolated rows. Changes: - Add INTERPOLATE token to token.go - Add InterpolateElement struct to ast/ast.go - Add Interpolate field to SelectQuery - Add parseInterpolateList in parser.go - Add explainInterpolateElement and update explainSelectQuery
- Always create SelectIntersectExceptQuery for all EXCEPT/INTERSECT variants (including ALL modifier) - Handle ALL modifier in operator string storage - Use HasPrefix for detecting EXCEPT/INTERSECT variants in explain code This fixes EXCEPT ALL and INTERSECT ALL queries that were previously being parsed as UNION-style flattened queries instead of using the proper SelectIntersectExceptQuery wrapper.
Implement parsing and explain output for ALTER TABLE ... MODIFY COMMENT statements: - Add AlterModifyComment command type to AST - Add parser handling in MODIFY case for COMMENT token - Add explain output handling for MODIFY_COMMENT command type - Add child count handling for comment literal This fixes 14 statements across 4 tests: - 02111_modify_table_comment: stmt6, stmt10 - 02155_dictionary_comment: stmt13 - 02792_alter_table_modify_comment: stmt4, stmt9, stmt14, stmt19, stmt24, stmt29, stmt34, stmt39, stmt44, stmt49 - 03142_alter_comment_parameterized_view: stmt3
Previously, SAMPLE BY was only shown when it was a function (not an identifier) and when different from ORDER BY. ClickHouse's actual EXPLAIN AST output always shows SAMPLE BY when present. This fixes 27 statements across 19 tests including: - 02559_add_parts - 00578_merge_table_sampling - 02380_analyzer_join_sample - 03227_test_sample_n - And 15 more SAMPLE BY related tests
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.
Implement proper handling of SQL standard quantified comparison operators
(x op ANY (subquery) and x op ALL (subquery)) in the parser and explain
module.
function name (e.g., anyEquals, allLess, anyGreaterOrEquals)
with appropriate aggregate functions (max/min/singleValueOrNull)