Skip to content

Commit 00ce8b7

Browse files
committed
Add end-to-end tests for ClickHouse types and functions
Tests for type handling and built-in functions: array types, type casting, string/math functions, named parameters, DELETE/UPDATE statements, and advanced feature combinations. Includes test runner integration updates. Final comprehensive validation of ClickHouse engine support.
1 parent 01638c9 commit 00ce8b7

File tree

38 files changed

+1522
-1
lines changed

38 files changed

+1522
-1
lines changed

internal/endtoend/ddl_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ func TestValidSchema(t *testing.T) {
5454
local.PostgreSQL(t, schema)
5555
case config.EngineMySQL:
5656
local.MySQL(t, schema)
57+
case config.EngineClickHouse:
58+
local.ClickHouse(t, schema)
5759
}
5860
})
5961
}

internal/endtoend/endtoend_test.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func TestReplay(t *testing.T) {
112112
// t.Parallel()
113113
ctx := context.Background()
114114

115-
var mysqlURI, postgresURI string
115+
var mysqlURI, postgresURI, clickhouseURI string
116116
if err := docker.Installed(); err == nil {
117117
{
118118
host, err := docker.StartPostgreSQLServer(ctx)
@@ -128,6 +128,13 @@ func TestReplay(t *testing.T) {
128128
}
129129
mysqlURI = host
130130
}
131+
{
132+
host, err := docker.StartClickHouseServer(ctx)
133+
if err != nil {
134+
t.Fatalf("starting clickhouse failed: %s", err)
135+
}
136+
clickhouseURI = host
137+
}
131138
}
132139

133140
contexts := map[string]textContext{
@@ -150,6 +157,12 @@ func TestReplay(t *testing.T) {
150157
Engine: config.EngineMySQL,
151158
URI: mysqlURI,
152159
},
160+
161+
{
162+
Name: "clickhouse",
163+
Engine: config.EngineClickHouse,
164+
URI: clickhouseURI,
165+
},
153166
}
154167
for i := range c.SQL {
155168
switch c.SQL[i].Engine {
@@ -161,6 +174,10 @@ func TestReplay(t *testing.T) {
161174
c.SQL[i].Database = &config.Database{
162175
Managed: true,
163176
}
177+
case config.EngineClickHouse:
178+
c.SQL[i].Database = &config.Database{
179+
Managed: true,
180+
}
164181
case config.EngineSQLite:
165182
c.SQL[i].Database = &config.Database{
166183
Managed: true,

internal/endtoend/testdata/clickhouse_advanced/go/db.go

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/clickhouse_advanced/go/models.go

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/clickhouse_advanced/go/query.sql.go

Lines changed: 112 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
-- CASE expression
2+
-- name: GetTransactionClassification :many
3+
SELECT
4+
id,
5+
user_id,
6+
amount,
7+
CASE
8+
WHEN amount > 1000 THEN 'high'
9+
WHEN amount > 100 THEN 'medium'
10+
ELSE 'low'
11+
END as classification,
12+
category
13+
FROM transactions
14+
WHERE created_at >= ?
15+
ORDER BY amount DESC;
16+
17+
-- IN operator with subquery style
18+
-- name: GetTransactionsByCategory :many
19+
SELECT
20+
id,
21+
user_id,
22+
amount,
23+
category
24+
FROM transactions
25+
WHERE category IN ('groceries', 'utilities', 'transportation')
26+
ORDER BY created_at DESC;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
CREATE TABLE IF NOT EXISTS transactions
2+
(
3+
id UInt32,
4+
user_id UInt32,
5+
amount Float64,
6+
category String,
7+
created_at DateTime
8+
)
9+
ENGINE = MergeTree()
10+
ORDER BY (id, created_at);
11+
12+
CREATE TABLE IF NOT EXISTS activities
13+
(
14+
id UInt32,
15+
user_id UInt32,
16+
action String,
17+
timestamp DateTime
18+
)
19+
ENGINE = MergeTree()
20+
ORDER BY (id, timestamp);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"version": "2",
3+
"sql": [
4+
{
5+
"schema": "schema.sql",
6+
"queries": "query.sql",
7+
"engine": "clickhouse",
8+
"gen": {
9+
"go": {
10+
"out": "go",
11+
"package": "db"
12+
}
13+
}
14+
}
15+
]
16+
}

internal/endtoend/testdata/clickhouse_arrays/go/db.go

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/clickhouse_arrays/go/models.go

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)