@@ -16,6 +16,9 @@ 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 {
20+ children ++ // WindowDefinition for OVER clause
21+ }
1922 // Normalize function name
2023 fnName := NormalizeFunctionName (n .Name )
2124 if alias != "" {
@@ -39,6 +42,11 @@ func explainFunctionCallWithAlias(sb *strings.Builder, n *ast.FunctionCall, alia
3942 Node (sb , p , depth + 2 )
4043 }
4144 }
45+ // Window definition (for window functions with OVER clause)
46+ // WindowDefinition is a sibling to ExpressionList, so use the same indent
47+ if n .Over != nil {
48+ explainWindowSpec (sb , n .Over , indent + " " , depth + 1 )
49+ }
4250}
4351
4452func explainLambda (sb * strings.Builder , n * ast.Lambda , indent string , depth int ) {
@@ -237,3 +245,42 @@ func explainExtractExpr(sb *strings.Builder, n *ast.ExtractExpr, indent string,
237245 fmt .Fprintf (sb , "%s ExpressionList (children %d)\n " , indent , 1 )
238246 Node (sb , n .From , depth + 2 )
239247}
248+
249+ func explainWindowSpec (sb * strings.Builder , n * ast.WindowSpec , indent string , depth int ) {
250+ // Window spec is represented as WindowDefinition
251+ // For simple cases like OVER (), just output WindowDefinition without children
252+ children := 0
253+ if n .Name != "" {
254+ children ++
255+ }
256+ if len (n .PartitionBy ) > 0 {
257+ children ++
258+ }
259+ if len (n .OrderBy ) > 0 {
260+ children ++
261+ }
262+ if n .Frame != nil {
263+ children ++
264+ }
265+ if children > 0 {
266+ fmt .Fprintf (sb , "%sWindowDefinition (children %d)\n " , indent , children )
267+ if n .Name != "" {
268+ fmt .Fprintf (sb , "%s Identifier %s\n " , indent , n .Name )
269+ }
270+ if len (n .PartitionBy ) > 0 {
271+ fmt .Fprintf (sb , "%s ExpressionList (children %d)\n " , indent , len (n .PartitionBy ))
272+ for _ , e := range n .PartitionBy {
273+ Node (sb , e , depth + 2 )
274+ }
275+ }
276+ if len (n .OrderBy ) > 0 {
277+ fmt .Fprintf (sb , "%s ExpressionList (children %d)\n " , indent , len (n .OrderBy ))
278+ for _ , o := range n .OrderBy {
279+ Node (sb , o .Expression , depth + 2 )
280+ }
281+ }
282+ // Frame handling would go here if needed
283+ } else {
284+ fmt .Fprintf (sb , "%sWindowDefinition\n " , indent )
285+ }
286+ }
0 commit comments