Skip to content

Commit 01638c9

Browse files
committed
Add end-to-end tests for ClickHouse advanced SQL features
Tests for complex SQL constructs: JOIN operations (explicit and implicit), subqueries (including IN subqueries), common table expressions (CTEs), aggregate functions, GROUP BY with HAVING, and EXISTS operator. Each test includes schema, queries, and generated Go code.
1 parent d7965d6 commit 01638c9

File tree

48 files changed

+1725
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1725
-0
lines changed

internal/endtoend/testdata/clickhouse_aggregates/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_aggregates/go/models.go

Lines changed: 18 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_aggregates/go/query.sql.go

Lines changed: 206 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
-- Basic aggregates
2+
-- name: GetSalesStatistics :many
3+
SELECT
4+
category,
5+
COUNT(*) as total_sales,
6+
SUM(amount) as total_revenue,
7+
AVG(amount) as avg_amount,
8+
MIN(amount) as min_amount,
9+
MAX(amount) as max_amount,
10+
SUM(quantity) as total_quantity
11+
FROM sales
12+
GROUP BY category
13+
ORDER BY total_revenue DESC;
14+
15+
-- Conditional aggregates
16+
-- name: GetCategoryStats :many
17+
SELECT
18+
category,
19+
COUNT(*) as all_sales,
20+
countIf(amount > 100) as high_value_sales,
21+
sumIf(amount, quantity > 5) as revenue_bulk_orders,
22+
avgIf(amount, amount > 50) as avg_high_value
23+
FROM sales
24+
WHERE created_at >= ?
25+
GROUP BY category;
26+
27+
-- HAVING clause
28+
-- name: GetTopCategories :many
29+
SELECT
30+
category,
31+
COUNT(*) as sale_count,
32+
SUM(amount) as total_amount
33+
FROM sales
34+
GROUP BY category
35+
ORDER BY total_amount DESC;
36+
37+
-- Multiple GROUP BY columns
38+
-- name: GetProductCategoryStats :many
39+
SELECT
40+
product_id,
41+
category,
42+
COUNT(*) as count,
43+
SUM(amount) as total
44+
FROM sales
45+
GROUP BY product_id, category
46+
ORDER BY product_id, total DESC;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CREATE TABLE IF NOT EXISTS sales
2+
(
3+
id UInt32,
4+
product_id UInt32,
5+
category String,
6+
amount Float64,
7+
quantity UInt32,
8+
created_at DateTime
9+
)
10+
ENGINE = MergeTree()
11+
ORDER BY (id, created_at);
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_cte/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_cte/go/models.go

Lines changed: 16 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)