Skip to content

Commit 180460d

Browse files
committed
Add WITH clause support in projection definitions (#116)
Parse and explain WITH clause in ProjectionSelectQuery for CREATE TABLE statements with projections.
1 parent 1ad9fac commit 180460d

4 files changed

Lines changed: 18 additions & 6 deletions

File tree

ast/ast.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,7 @@ func (p *Projection) End() token.Position { return p.Position }
637637
// ProjectionSelectQuery represents the SELECT part of a projection.
638638
type ProjectionSelectQuery struct {
639639
Position token.Position `json:"-"`
640+
With []Expression `json:"with,omitempty"` // WITH clause expressions
640641
Columns []Expression `json:"columns"`
641642
GroupBy []Expression `json:"group_by,omitempty"`
642643
OrderBy []Expression `json:"order_by,omitempty"` // ORDER BY columns

internal/explain/statements.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1914,6 +1914,9 @@ func explainProjection(sb *strings.Builder, p *ast.Projection, indent string, de
19141914

19151915
func explainProjectionSelectQuery(sb *strings.Builder, q *ast.ProjectionSelectQuery, indent string, depth int) {
19161916
children := 0
1917+
if len(q.With) > 0 {
1918+
children++
1919+
}
19171920
if len(q.Columns) > 0 {
19181921
children++
19191922
}
@@ -1924,6 +1927,13 @@ func explainProjectionSelectQuery(sb *strings.Builder, q *ast.ProjectionSelectQu
19241927
children++
19251928
}
19261929
fmt.Fprintf(sb, "%sProjectionSelectQuery (children %d)\n", indent, children)
1930+
// Output WITH clause first
1931+
if len(q.With) > 0 {
1932+
fmt.Fprintf(sb, "%s ExpressionList (children %d)\n", indent, len(q.With))
1933+
for _, w := range q.With {
1934+
Node(sb, w, depth+2)
1935+
}
1936+
}
19271937
if len(q.Columns) > 0 {
19281938
fmt.Fprintf(sb, "%s ExpressionList (children %d)\n", indent, len(q.Columns))
19291939
for _, col := range q.Columns {

parser/parser.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7785,6 +7785,12 @@ func (p *Parser) parseProjection() *ast.Projection {
77857785
Position: p.current.Pos,
77867786
}
77877787

7788+
// Parse WITH clause if present
7789+
if p.currentIs(token.WITH) {
7790+
p.nextToken() // skip WITH
7791+
proj.Select.With = p.parseWithClause()
7792+
}
7793+
77887794
// Parse SELECT keyword (optional in projection)
77897795
if p.currentIs(token.SELECT) {
77907796
p.nextToken()
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt1": true,
4-
"stmt4": true
5-
}
6-
}
1+
{}

0 commit comments

Comments
 (0)