Skip to content

Commit 3874d91

Browse files
committed
fix: preserve OVER clause during window function rewriting
Two fixes for window function execution: 1. Parser fix: Fixed "order by order by" duplication in WindowSpec.Format() - The OrderBy.Format() method adds its own "order by" prefix - WindowSpec.Format() was also adding "order by" before calling OrderBy - Changed to iterate OrderBy items directly without the prefix 2. Execution layer fix: Preserve OVER clause during AST function rewriting - Added node.Over = newNode.Over in 5 astvisit files: - query_rewriting.go - from_rewrite.go - fragment_rewriting.go - internally_routable_typing.go - provider_string_extract.go - Without this, window functions lost their OVER clause during rewriting
1 parent 5fd98aa commit 3874d91

File tree

7 files changed

+756
-745
lines changed

7 files changed

+756
-745
lines changed

internal/stackql-parser-fork/go/vt/sqlparser/ast.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1987,7 +1987,13 @@ func (node *WindowSpec) Format(buf *TrackedBuffer) {
19871987
if needsSpace {
19881988
buf.WriteString(" ")
19891989
}
1990-
buf.astPrintf(node, "order by %v", node.OrderBy)
1990+
// Don't use %v for OrderBy as OrderBy.Format adds its own "order by" prefix
1991+
buf.WriteString("order by ")
1992+
prefix := ""
1993+
for _, n := range node.OrderBy {
1994+
buf.astPrintf(node, "%s%v", prefix, n)
1995+
prefix = ", "
1996+
}
19911997
needsSpace = true
19921998
}
19931999
if node.Frame != nil {

0 commit comments

Comments
 (0)