Skip to content

Commit 4452b96

Browse files
authored
Fix window function explain for named window references (#59)
1 parent 2abbe5e commit 4452b96

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

internal/explain/functions.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ func explainFunctionCallWithAlias(sb *strings.Builder, n *ast.FunctionCall, alia
1616
if len(n.Parameters) > 0 {
1717
children++ // parameters ExpressionList
1818
}
19-
if n.Over != nil {
19+
// Only count WindowDefinition as a child for inline window specs (not named references)
20+
// When it's just a reference like "OVER w", it's shown in the SELECT's WINDOW clause instead
21+
// Inline specs include OVER () - empty window, and OVER (ORDER BY x) - window with spec
22+
// Named refs have n.Over.Name set and no inline definition
23+
hasInlineWindowSpec := n.Over != nil && n.Over.Name == ""
24+
if hasInlineWindowSpec {
2025
children++ // WindowDefinition for OVER clause
2126
}
2227
// Normalize function name
@@ -65,9 +70,10 @@ func explainFunctionCallWithAlias(sb *strings.Builder, n *ast.FunctionCall, alia
6570
Node(sb, p, depth+2)
6671
}
6772
}
68-
// Window definition (for window functions with OVER clause)
73+
// Window definition (for window functions with inline OVER clause)
6974
// WindowDefinition is a sibling to ExpressionList, so use the same indent
70-
if n.Over != nil {
75+
// Only output for inline specs, not named references like "OVER w"
76+
if hasInlineWindowSpec {
7177
explainWindowSpec(sb, n.Over, indent+" ", depth+1)
7278
}
7379
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"todo":true,"todo_format":true}
1+
{"todo_format":true}

0 commit comments

Comments
 (0)