Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
4811371
Nested JSON array paths, quoted ^ path parts, unicode minus operator
claude Dec 1, 2026
cfb5e5c
BETWEEN aliases, datepart, kql passthrough, hex/bin literal padding, …
claude Dec 1, 2026
b70cc2c
Geometry/Interval type names, empty storage after dropped settings, o…
claude Dec 1, 2026
0014be3
INTERPOLATE after LIMIT/SETTINGS, merged lambda params in substring, …
claude Dec 1, 2026
6798ebc
CASE END no longer takes an alias itself, one-element tuples inside t…
claude Dec 1, 2026
6718e92
DISTINCT ON prints in the LIMIT BY position, non-plain :: operands pr…
claude Dec 1, 2026
cae9bf1
Constraints print before projections in column definitions
claude Dec 1, 2026
fed91ae
SETTINGS after a parenthesized CREATE AS query are query-level settings
claude Dec 1, 2026
ace3b16
INTERSECT chains nest left-associatively, FORMAT found inside INTERSE…
claude Dec 1, 2026
c5e1ad3
FROM-first queries reuse the SELECT parser, pipe INTERSECT/EXCEPT, se…
claude Dec 1, 2026
fd6a3a9
EXPLAIN WHATIF, cluster/alias as implicit aliases, quoted skip in JSO…
claude Dec 1, 2026
5d0230c
APPLY with parenthesized lambdas, OFFSET ... WITH TIES, view() with a…
claude Dec 1, 2026
8e72057
SYSTEM RESTORE REPLICA/LOAD PRIMARY KEY repeat qualified names, SHOW …
claude Dec 1, 2026
4e83620
Scalar EXPLAIN subqueries print as viewExplain, drop the INSERT trail…
claude Dec 1, 2026
c4ed4c9
Object storage and queue engines drop query-level settings except for…
claude Dec 1, 2026
15bf427
Invalid UTF-8 bytes in identifiers print raw, NUL escapes once
claude Dec 1, 2026
6dd52c6
Test harness: error hints without an explain file skip like clientError
claude Dec 1, 2026
7c882d4
Encryption secrets inside scalar subqueries are hidden
claude Dec 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ type SelectQuery struct {
Window []*WindowDefinition `json:"window,omitempty"`
OrderBy []*OrderByElement `json:"order_by,omitempty"`
Interpolate []*InterpolateElement `json:"interpolate,omitempty"`
HasInterpolate bool `json:"has_interpolate,omitempty"` // INTERPOLATE clause present, possibly empty
Limit Expression `json:"limit,omitempty"`
LimitBy []Expression `json:"limit_by,omitempty"`
LimitByLimit Expression `json:"limit_by_limit,omitempty"` // LIMIT value before BY (e.g., LIMIT 1 BY x LIMIT 3)
Expand Down Expand Up @@ -341,7 +342,7 @@ type CreateQuery struct {
AlterUser bool `json:"alter_user,omitempty"`
HasAuthenticationData bool `json:"has_authentication_data,omitempty"`
AuthenticationValues []string `json:"authentication_values,omitempty"` // Password/hash values from IDENTIFIED BY
AuthValidUntil map[int]Expression `json:"auth_valid_until,omitempty"` // VALID UNTIL per AuthenticationValues index
AuthValidUntil map[int]Expression `json:"auth_valid_until,omitempty"` // VALID UNTIL per AuthenticationValues index
UserValidUntil Expression `json:"user_valid_until,omitempty"` // VALID UNTIL not attached to an auth method
SSHKeyCount int `json:"ssh_key_count,omitempty"` // Number of SSH keys for ssh_key auth
CreateDictionary bool `json:"create_dictionary,omitempty"`
Expand Down Expand Up @@ -371,7 +372,7 @@ type ColumnDeclaration struct {
TTL Expression `json:"ttl,omitempty"`
PrimaryKey bool `json:"primary_key,omitempty"` // PRIMARY KEY constraint
Comment string `json:"comment,omitempty"`
Settings []*SettingExpr `json:"settings,omitempty"` // Column-level SETTINGS
Settings []*SettingExpr `json:"settings,omitempty"` // Column-level SETTINGS
Collation string `json:"collation,omitempty"` // COLLATE name
}

Expand Down Expand Up @@ -974,6 +975,7 @@ const (
ExplainPipeline ExplainType = "PIPELINE"
ExplainEstimate ExplainType = "ESTIMATE"
ExplainAnalyze ExplainType = "ANALYZE"
ExplainWhatIf ExplainType = "WHATIF"
ExplainQueryTree ExplainType = "QUERY TREE"
ExplainCurrentTransaction ExplainType = "CURRENT TRANSACTION"
)
Expand Down Expand Up @@ -1919,7 +1921,7 @@ func (e *ExecuteAsQuery) statementNode() {}

// ShowAccessEntitiesQuery represents SHOW USERS, SHOW ROLES, SHOW [ROW] POLICIES, etc.
type ShowAccessEntitiesQuery struct {
Position token.Position `json:"-"`
Position token.Position `json:"-"`
Keyword string `json:"keyword"` // e.g. "USERS", "ROW POLICIES"
Format string `json:"format,omitempty"`
OutFile string `json:"out_file,omitempty"`
Expand Down
51 changes: 2 additions & 49 deletions internal/explain/explain.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,56 +55,9 @@ func ExplainStatements(stmts []ast.Statement) string {
setParamSubstitution(stmts[0])
var sb strings.Builder
Node(&sb, stmts[0], 0)

// If the first statement is an INSERT and there are subsequent SELECT statements
// with simple literals, append those literal values (matching ClickHouse's behavior)
if _, isInsert := stmts[0].(*ast.InsertQuery); isInsert {
for i := 1; i < len(stmts); i++ {
if result := getSimpleSelectResult(stmts[i]); result != "" {
sb.WriteString(result)
sb.WriteString("\n")
}
}
}

return sb.String()
}

// getSimpleSelectResult extracts the literal value from a simple SELECT statement
// like "SELECT 11111" and returns it as a string. Returns empty string if not a simple SELECT.
func getSimpleSelectResult(stmt ast.Statement) string {
// Check if it's a SelectWithUnionQuery
selectUnion, ok := stmt.(*ast.SelectWithUnionQuery)
if !ok {
return ""
}

// Must have exactly one select query
if len(selectUnion.Selects) != 1 {
return ""
}

// Get the inner select query
selectQuery, ok := selectUnion.Selects[0].(*ast.SelectQuery)
if !ok {
return ""
}

// Must have exactly one expression in the select list
if len(selectQuery.Columns) != 1 {
return ""
}

// Must be a literal
literal, ok := selectQuery.Columns[0].(*ast.Literal)
if !ok {
return ""
}

// Format the literal value
return formatLiteralValue(literal)
}

// formatLiteralValue formats a literal value as it would appear in query results
func formatLiteralValue(lit *ast.Literal) string {
switch v := lit.Value.(type) {
Expand Down Expand Up @@ -528,7 +481,7 @@ func Column(sb *strings.Builder, col *ast.ColumnDeclaration, depth int) {
children++
}
if children > 0 {
fmt.Fprintf(sb, "%sColumnDeclaration %s (children %d)\n", indent, sanitizeUTF8(col.Name), children)
fmt.Fprintf(sb, "%sColumnDeclaration %s (children %d)\n", indent, strings.ReplaceAll(sanitizeUTF8(col.Name), "'", "\\'"), children)
} else {
fmt.Fprintf(sb, "%sColumnDeclaration %s\n", indent, sanitizeUTF8(col.Name))
}
Expand Down Expand Up @@ -632,7 +585,7 @@ func Index(sb *strings.Builder, idx *ast.IndexDefinition, depth int) {
if idx.Expression != nil {
// Expression is typically an identifier
if ident, ok := idx.Expression.(*ast.Identifier); ok {
fmt.Fprintf(sb, "%s Identifier %s\n", indent, ident.Name())
fmt.Fprintf(sb, "%s Identifier %s\n", indent, formatIdentifierName(ident))
} else {
Node(sb, idx.Expression, depth+1)
}
Expand Down
Loading
Loading