-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathsnowflake_qualify_test.go
More file actions
58 lines (51 loc) · 1.44 KB
/
snowflake_qualify_test.go
File metadata and controls
58 lines (51 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright 2026 GoSQLX Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
package parser_test
import (
"testing"
"github.com/ajitpratap0/GoSQLX/pkg/gosqlx"
"github.com/ajitpratap0/GoSQLX/pkg/sql/ast"
"github.com/ajitpratap0/GoSQLX/pkg/sql/keywords"
)
// TestSnowflakeQualify verifies the Snowflake QUALIFY clause parses between
// HAVING and ORDER BY. Regression for #483.
func TestSnowflakeQualify(t *testing.T) {
queries := map[string]string{
"simple": `SELECT id, name, ROW_NUMBER() OVER (ORDER BY id) AS rn
FROM users
QUALIFY rn = 1`,
"with_where": `SELECT id, name
FROM users
WHERE active = true
QUALIFY ROW_NUMBER() OVER (PARTITION BY dept ORDER BY id) = 1`,
"with_group_having": `SELECT dept, COUNT(*) AS n
FROM users
GROUP BY dept
HAVING COUNT(*) > 5
QUALIFY RANK() OVER (ORDER BY n DESC) <= 10`,
"with_order_by": `SELECT id, RANK() OVER (ORDER BY score) AS r
FROM leaderboard
QUALIFY r <= 10
ORDER BY id`,
}
for name, q := range queries {
q := q
t.Run(name, func(t *testing.T) {
tree, err := gosqlx.ParseWithDialect(q, keywords.DialectSnowflake)
if err != nil {
t.Fatalf("parse failed: %v", err)
}
if len(tree.Statements) == 0 {
t.Fatal("no statements parsed")
}
ss, ok := tree.Statements[0].(*ast.SelectStatement)
if !ok {
t.Fatalf("expected SelectStatement, got %T", tree.Statements[0])
}
if ss.Qualify == nil {
t.Fatal("Qualify clause missing from AST")
}
})
}
}