Expand Explain function to handle more AST types#11
Merged
kyleconroy merged 9 commits intomainfrom Dec 13, 2025
Merged
Conversation
This significantly improves test coverage by adding explain output handling for: - CastExpr (CAST and :: operator) - InExpr (IN and NOT IN expressions) - TernaryExpr (ternary conditional) - ArrayAccess (array element access) - TupleAccess (tuple element access) - DropQuery (DROP TABLE/VIEW/DATABASE) - LikeExpr (LIKE/ILIKE expressions) - BetweenExpr (BETWEEN expressions) - IsNullExpr (IS NULL/IS NOT NULL) - CaseExpr (CASE WHEN expressions) - IntervalExpr (INTERVAL expressions) - ExistsExpr (EXISTS subqueries) - ExtractExpr (EXTRACT function) - CreateQuery (CREATE TABLE/VIEW/DATABASE) - SystemQuery (SYSTEM commands) - ExplainQuery (EXPLAIN statements) - ShowQuery (SHOW statements) - UseQuery (USE database) - DescribeQuery (DESCRIBE/DESC) - TableJoin (JOIN clauses) - DataType (type expressions) - Parameter (query parameters) Also fixes: - ARRAY JOIN placement in TablesInSelectQuery - Subquery alias handling in TableExpression - SETTINGS clause output as Set - Tuple literals with complex expressions rendered as Function tuple Tests improved from ~50% to ~73% passing (4998 of 6824).
- Handle empty tuples (nil arguments) as Function tuple with empty ExpressionList - Add array handling for complex expressions (renders as Function array) - Normalize function names (ltrim -> trimLeft, etc.) - Fix ShowQuery capitalization - Fix SystemQuery format to "SYSTEM query" Tests improved from ~73% to ~74% passing (5057 of 6824).
Reorganize the explain functionality into a dedicated internal package with separate files for each category of AST types: - internal/explain/explain.go - main Explain function and core dispatcher - internal/explain/select.go - SelectQuery and related types - internal/explain/expressions.go - expressions (Literal, BinaryExpr, etc.) - internal/explain/functions.go - FunctionCall, Lambda, CAST, IN, etc. - internal/explain/tables.go - table-related types - internal/explain/statements.go - DDL statements (Create, Drop, etc.) - internal/explain/format.go - formatting and normalization functions The parser package now delegates to the internal package. No functional changes - all 5057 tests still pass.
Add support for rendering empty arrays as Function array with empty ExpressionList, matching ClickHouse's EXPLAIN AST format. Tests improved from ~74% to ~74.3% passing (5072 of 6824).
When an engine has parentheses (like MergeTree()), output it with children count and empty ExpressionList, matching ClickHouse's format. Tests improved to 5090 passing (~74.6% of 6824).
- Add DROP USER support with proper 'DROP USER query' output format - Add SHOW FUNCTIONS type handling with 'ShowFunctions' output - Fix cast shorthand (::) to output expression as string literal - Escape backslashes in string literals for proper output - Add ENGINE function parameters output in CREATE TABLE - Add SETTINGS output (Set) in CREATE TABLE storage definition - Remove Subquery wrapper for AS SELECT in CREATE TABLE Tests passing: 5128 (up from 5090)
- Change NULL literal output from 'Null' to 'NULL' (uppercase) - Fix DataType with complex parameters (like Enum) to output as children with ExpressionList instead of formatted string - Update Column function to use Node() for type output Tests passing: 5179 (up from 5128)
- Check if any SelectQuery in the union has a Format field - Output Format Identifier at SelectWithUnionQuery level (matches ClickHouse) - Update child count accordingly Tests passing: 5197 (up from 5179)
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 significantly improves test coverage by adding explain output handling for:
Also fixes:
Tests improved from ~50% to ~73% passing (4998 of 6824).