-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathsnowflake_ilike_pivot_test.go
More file actions
74 lines (66 loc) · 2.37 KB
/
snowflake_ilike_pivot_test.go
File metadata and controls
74 lines (66 loc) · 2.37 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright 2026 GoSQLX Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
package parser_test
import (
"strings"
"testing"
"github.com/ajitpratap0/GoSQLX/pkg/gosqlx"
"github.com/ajitpratap0/GoSQLX/pkg/sql/keywords"
)
// TestSnowflakeILIKE verifies that ILIKE is accepted in the Snowflake dialect.
// Snowflake natively supports ILIKE; the parser previously rejected it with a
// "PostgreSQL-specific" error. Regression for #483.
func TestSnowflakeILIKE(t *testing.T) {
queries := []string{
`SELECT * FROM users WHERE name ILIKE 'alice%'`,
`SELECT * FROM users WHERE name NOT ILIKE 'alice%'`,
}
for _, q := range queries {
t.Run(q, func(t *testing.T) {
if _, err := gosqlx.ParseWithDialect(q, keywords.DialectSnowflake); err != nil {
t.Fatalf("ParseWithDialect(Snowflake) failed: %v", err)
}
})
}
}
// TestClickHouseILIKE verifies ILIKE is accepted in the ClickHouse dialect.
func TestClickHouseILIKE(t *testing.T) {
q := `SELECT * FROM events WHERE message ILIKE '%error%'`
if _, err := gosqlx.ParseWithDialect(q, keywords.DialectClickHouse); err != nil {
t.Fatalf("ParseWithDialect(ClickHouse) failed: %v", err)
}
}
// TestMySQLILIKERejected verifies ILIKE is still rejected in dialects that
// do not natively support it.
func TestMySQLILIKERejected(t *testing.T) {
q := `SELECT * FROM users WHERE name ILIKE 'alice%'`
_, err := gosqlx.ParseWithDialect(q, keywords.DialectMySQL)
if err == nil {
t.Fatal("expected MySQL ILIKE to be rejected")
}
if !strings.Contains(err.Error(), "ILIKE is not supported") {
t.Fatalf("unexpected error message: %v", err)
}
}
// TestSnowflakePivot verifies PIVOT is parsed in the Snowflake dialect, where
// it was previously gated to SQL Server / Oracle only. Regression for #483.
func TestSnowflakePivot(t *testing.T) {
q := `SELECT *
FROM monthly_sales
PIVOT (SUM(amount) FOR month IN ('JAN', 'FEB', 'MAR'))
AS p`
if _, err := gosqlx.ParseWithDialect(q, keywords.DialectSnowflake); err != nil {
t.Fatalf("Snowflake PIVOT parse failed: %v", err)
}
}
// TestSnowflakeUnpivot verifies UNPIVOT is parsed in the Snowflake dialect.
func TestSnowflakeUnpivot(t *testing.T) {
q := `SELECT *
FROM monthly_sales
UNPIVOT (amount FOR month IN (jan, feb, mar))
AS u`
if _, err := gosqlx.ParseWithDialect(q, keywords.DialectSnowflake); err != nil {
t.Fatalf("Snowflake UNPIVOT parse failed: %v", err)
}
}