88 "testing"
99
1010 "github.com/ajitpratap0/GoSQLX/pkg/gosqlx"
11+ "github.com/ajitpratap0/GoSQLX/pkg/sql/ast"
1112 "github.com/ajitpratap0/GoSQLX/pkg/sql/keywords"
1213)
1314
@@ -29,3 +30,45 @@ func TestClickHouseParametricAggregates(t *testing.T) {
2930 })
3031 }
3132}
33+
34+ // TestClickHouseParametricAggregates_ASTShape verifies that the Parameters
35+ // field is populated and reachable via the visitor pattern.
36+ func TestClickHouseParametricAggregates_ASTShape (t * testing.T ) {
37+ q := `SELECT quantileTDigest(0.95)(value) FROM events`
38+ tree , err := gosqlx .ParseWithDialect (q , keywords .DialectClickHouse )
39+ if err != nil {
40+ t .Fatalf ("parse failed: %v" , err )
41+ }
42+ // Walk the tree until we find a FunctionCall node and verify both
43+ // Parameters and Arguments are populated, and Children() exposes both.
44+ var found bool
45+ var visit func (n ast.Node )
46+ visit = func (n ast.Node ) {
47+ if n == nil || found {
48+ return
49+ }
50+ if fc , ok := n .(* ast.FunctionCall ); ok && fc .Name == "quantileTDigest" {
51+ if len (fc .Parameters ) != 1 {
52+ t .Fatalf ("Parameters: want 1, got %d" , len (fc .Parameters ))
53+ }
54+ if len (fc .Arguments ) != 1 {
55+ t .Fatalf ("Arguments: want 1, got %d" , len (fc .Arguments ))
56+ }
57+ // Children() must include both the argument and the parameter.
58+ if len (fc .Children ()) < 2 {
59+ t .Fatalf ("Children(): want >=2 (args + params), got %d" , len (fc .Children ()))
60+ }
61+ found = true
62+ return
63+ }
64+ for _ , c := range n .Children () {
65+ visit (c )
66+ }
67+ }
68+ for _ , stmt := range tree .Statements {
69+ visit (stmt )
70+ }
71+ if ! found {
72+ t .Fatal ("did not find quantileTDigest FunctionCall in AST" )
73+ }
74+ }
0 commit comments