Skip to content

Commit f484682

Browse files
authored
Replace test cases with all 6823 queries from ClickHouse stateless tests (#7)
1 parent 9725070 commit f484682

21,448 files changed

Lines changed: 419585 additions & 6680 deletions

File tree

Some content is hidden

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

ast/explain.go

Lines changed: 0 additions & 1735 deletions
This file was deleted.

ast/explain_test.go

Lines changed: 0 additions & 86 deletions
This file was deleted.

parser/parser_test.go

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,30 @@ type testMetadata struct {
1818
Source string `json:"source,omitempty"`
1919
}
2020

21+
// astJSON represents the structure of ast.json from ClickHouse EXPLAIN AST
22+
type astJSON struct {
23+
Meta []struct {
24+
Name string `json:"name"`
25+
Type string `json:"type"`
26+
} `json:"meta"`
27+
Data []struct {
28+
Explain string `json:"explain"`
29+
} `json:"data"`
30+
Rows int `json:"rows"`
31+
Statistics struct {
32+
Elapsed float64 `json:"elapsed"`
33+
RowsRead int `json:"rows_read"`
34+
BytesRead int `json:"bytes_read"`
35+
} `json:"statistics"`
36+
Error bool `json:"error,omitempty"`
37+
}
38+
2139
// TestParser tests the parser using test cases from the testdata directory.
2240
// Each subdirectory in testdata represents a test case with:
2341
// - query.sql: The SQL query to parse
42+
// - ast.json: Expected AST from ClickHouse EXPLAIN AST
2443
// - metadata.json (optional): Metadata including:
2544
// - todo: true if the test is not yet expected to pass
26-
// - source: URL to the source file in ClickHouse repository
2745
func TestParser(t *testing.T) {
2846
testdataDir := "testdata"
2947

@@ -37,21 +55,24 @@ func TestParser(t *testing.T) {
3755
continue
3856
}
3957

40-
testName := entry.Name()
41-
testDir := filepath.Join(testdataDir, testName)
58+
testDir := filepath.Join(testdataDir, entry.Name())
59+
60+
t.Run(entry.Name(), func(t *testing.T) {
61+
t.Parallel()
4262

43-
t.Run(testName, func(t *testing.T) {
4463
// Create context with 1 second timeout
4564
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
4665
defer cancel()
4766

48-
// Read the query
67+
// Read the query (only first line, as ast.json was generated from first statement)
4968
queryPath := filepath.Join(testDir, "query.sql")
5069
queryBytes, err := os.ReadFile(queryPath)
5170
if err != nil {
5271
t.Fatalf("Failed to read query.sql: %v", err)
5372
}
54-
query := strings.TrimSpace(string(queryBytes))
73+
// Get first line only (ast.json contains AST for first statement)
74+
lines := strings.SplitN(string(queryBytes), "\n", 2)
75+
query := strings.TrimSpace(lines[0])
5576

5677
// Read optional metadata
5778
var metadata testMetadata
@@ -62,9 +83,19 @@ func TestParser(t *testing.T) {
6283
}
6384
}
6485

65-
// Log source if available
66-
if metadata.Source != "" {
67-
t.Logf("Source: %s", metadata.Source)
86+
// Read expected AST from ClickHouse
87+
var expectedAST astJSON
88+
astPath := filepath.Join(testDir, "ast.json")
89+
if astBytes, err := os.ReadFile(astPath); err == nil {
90+
if err := json.Unmarshal(astBytes, &expectedAST); err != nil {
91+
t.Fatalf("Failed to parse ast.json: %v", err)
92+
}
93+
}
94+
95+
// Skip tests where ClickHouse also couldn't parse the query
96+
if expectedAST.Error {
97+
t.Skipf("ClickHouse also failed to parse this query")
98+
return
6899
}
69100

70101
// Parse the query
@@ -94,6 +125,8 @@ func TestParser(t *testing.T) {
94125
}
95126
t.Fatalf("JSON marshal error: %v\nQuery: %s", jsonErr, query)
96127
}
128+
129+
// TODO: Compare parsed AST against expectedAST.Data
97130
})
98131
}
99132
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"error": true}
File renamed without changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- Tags: stateful
2+
SELECT count() FROM test.hits
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"meta":
3+
[
4+
{
5+
"name": "explain",
6+
"type": "String"
7+
}
8+
],
9+
10+
"data":
11+
[
12+
{
13+
"explain": "SelectWithUnionQuery (children 1)"
14+
},
15+
{
16+
"explain": " ExpressionList (children 1)"
17+
},
18+
{
19+
"explain": " SelectQuery (children 1)"
20+
},
21+
{
22+
"explain": " ExpressionList (children 1)"
23+
},
24+
{
25+
"explain": " Literal UInt64_1"
26+
}
27+
],
28+
29+
"rows": 5,
30+
31+
"statistics":
32+
{
33+
"elapsed": 0.001936758,
34+
"rows_read": 5,
35+
"bytes_read": 177
36+
}
37+
}
File renamed without changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"error": true}

0 commit comments

Comments
 (0)