Skip to content

Commit ff082bd

Browse files
committed
docs(tests): add ClickHouse installation instructions and fix test context
- Update CLAUDE.md with ClickHouse installation instructions using official repository (Ubuntu packages have incompatible old version) - Add ClickHouse test context to endtoend_test.go with schema migration support - Import clickhouse-go v2 driver and database/sql for test context - Add test filtering to only run ClickHouse tests under clickhouse context - Add generated test output files for clickhouse_authors test case 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent f953029 commit ff082bd

File tree

5 files changed

+199
-3
lines changed

5 files changed

+199
-3
lines changed

CLAUDE.md

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,45 @@ Test the connection:
8787
mysql -h 127.0.0.1 -u root -pmysecretpassword -e "SELECT VERSION();"
8888
```
8989

90-
### Step 4: Run End-to-End Tests
90+
### Step 4: Install ClickHouse (Optional - for ClickHouse tests)
9191

92-
With both databases running, the test framework automatically detects them:
92+
ClickHouse is required for ClickHouse engine tests. The ClickHouse feature is experimental and requires the `SQLCEXPERIMENT=clickhouse` flag.
93+
94+
**Important:** Use the official ClickHouse repository, not the Ubuntu package (which has an old incompatible version).
95+
96+
```bash
97+
# Add ClickHouse official repository key and source
98+
curl -fsSL https://packages.clickhouse.com/rpm/lts/repodata/repomd.xml.key | sudo gpg --dearmor -o /usr/share/keyrings/clickhouse-keyring.gpg
99+
ARCH=$(dpkg --print-architecture)
100+
echo "deb [signed-by=/usr/share/keyrings/clickhouse-keyring.gpg arch=${ARCH}] https://packages.clickhouse.com/deb stable main" | sudo tee /etc/apt/sources.list.d/clickhouse.list
101+
102+
# Install ClickHouse from official repo
103+
sudo apt-get update
104+
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y clickhouse-server clickhouse-client
105+
106+
# Start ClickHouse server
107+
sudo clickhouse start
108+
```
109+
110+
Test the connection:
111+
112+
```bash
113+
clickhouse-client --query "SELECT version()"
114+
```
115+
116+
The native database support automatically detects ClickHouse and uses:
117+
- URI: `clickhouse://default:@localhost:9000/default`
118+
- User: `default` (no password)
119+
- Port: 9000
120+
121+
**Note:** ClickHouse tests require setting the experiment flag:
122+
```bash
123+
SQLCEXPERIMENT=clickhouse go test ./internal/endtoend -run "TestReplay/clickhouse" -v
124+
```
125+
126+
### Step 5: Run End-to-End Tests
127+
128+
With the databases running, the test framework automatically detects them:
93129

94130
```bash
95131
# Run all end-to-end tests
@@ -103,11 +139,12 @@ go test --tags=examples -timeout 20m ./...
103139
```
104140

105141
The native database support (in `internal/sqltest/native/`) automatically:
106-
- Detects running PostgreSQL and MySQL instances
142+
- Detects running PostgreSQL, MySQL, and ClickHouse instances
107143
- Starts services if installed but not running
108144
- Uses standard connection URIs:
109145
- PostgreSQL: `postgres://postgres:[email protected]:5432/postgres?sslmode=disable`
110146
- MySQL: `root:mysecretpassword@tcp(127.0.0.1:3306)/mysql`
147+
- ClickHouse: `clickhouse://default:@localhost:9000/default`
111148

112149
### Running Tests
113150

@@ -193,6 +230,11 @@ The `docker-compose.yml` provides test databases:
193230
- Password: `mysecretpassword`
194231
- Database: `dinotest`
195232

233+
- **ClickHouse** - Port 9000 (experimental, requires `SQLCEXPERIMENT=clickhouse`)
234+
- User: `default`
235+
- Password: (none)
236+
- Database: `default`
237+
196238
### Managing Databases
197239

198240
```bash
@@ -291,6 +333,7 @@ POSTGRESQL_SERVER_URI="postgres://postgres:mysecretpassword@localhost:5432/postg
291333
- `/postgresql/` - PostgreSQL parser and converter
292334
- `/dolphin/` - MySQL parser (uses TiDB parser)
293335
- `/sqlite/` - SQLite parser
336+
- `/clickhouse/` - ClickHouse parser (uses doubleclick parser, experimental)
294337
- `/internal/compiler/` - Query compilation logic
295338
- `/internal/codegen/` - Code generation for different languages
296339
- `/internal/config/` - Configuration file parsing

internal/endtoend/endtoend_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"bytes"
55
"context"
6+
"database/sql"
67
"os"
78
osexec "os/exec"
89
"path/filepath"
@@ -11,6 +12,7 @@ import (
1112
"strings"
1213
"testing"
1314

15+
_ "github.com/ClickHouse/clickhouse-go/v2" // ClickHouse driver
1416
"github.com/google/go-cmp/cmp"
1517
"github.com/google/go-cmp/cmp/cmpopts"
1618

@@ -238,6 +240,39 @@ func TestReplay(t *testing.T) {
238240
c.SQL[i].Database = &config.Database{
239241
URI: clickhouseURI,
240242
}
243+
// Apply schema migrations to ClickHouse
244+
for _, schemaPath := range c.SQL[i].Schema {
245+
fullPath := filepath.Join(path, schemaPath)
246+
schemaSQL, err := os.ReadFile(fullPath)
247+
if err != nil {
248+
t.Logf("Failed to read schema %s: %v", fullPath, err)
249+
continue
250+
}
251+
db, err := sql.Open("clickhouse", clickhouseURI)
252+
if err != nil {
253+
t.Logf("Failed to connect to ClickHouse: %v", err)
254+
continue
255+
}
256+
// Execute each statement separately
257+
for _, stmt := range strings.Split(string(schemaSQL), ";") {
258+
stmt = strings.TrimSpace(stmt)
259+
if stmt == "" {
260+
continue
261+
}
262+
// Drop table first if this is a CREATE TABLE statement
263+
if strings.HasPrefix(strings.ToUpper(stmt), "CREATE TABLE") {
264+
parts := strings.Fields(stmt)
265+
if len(parts) >= 3 {
266+
tableName := strings.TrimSuffix(parts[2], "(")
267+
db.Exec("DROP TABLE IF EXISTS " + tableName)
268+
}
269+
}
270+
if _, err := db.Exec(stmt); err != nil {
271+
t.Logf("Failed to apply schema: %v", err)
272+
}
273+
}
274+
db.Close()
275+
}
241276
}
242277
}
243278
}
@@ -281,6 +316,12 @@ func TestReplay(t *testing.T) {
281316
if !slices.Contains(args.Contexts, name) {
282317
t.Skipf("unsupported context: %s", name)
283318
}
319+
} else if name == "clickhouse" {
320+
// For clickhouse context, only run tests that explicitly include it
321+
// or that have ClickHouse engine (checked by having "clickhouse" in path)
322+
if !strings.Contains(tc.Name, "clickhouse") {
323+
t.Skipf("clickhouse context: skipping non-clickhouse test")
324+
}
284325
}
285326

286327
if len(args.OS) > 0 {

internal/endtoend/testdata/clickhouse_authors/clickhouse/stdlib/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_authors/clickhouse/stdlib/go/models.go

Lines changed: 5 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_authors/clickhouse/stdlib/go/query.sql.go

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