Skip to content

Commit 7ab27d7

Browse files
committed
Remove ast.json files and skip tests when explain: false in metadata
- Remove all 6823 ast.json files from testdata directories - Add Explain *bool field to testMetadata struct (pointer to distinguish between missing and explicit false) - Skip tests when explain is explicitly false in metadata - Add CLAUDE.md with test timeout guidance
1 parent d709d82 commit 7ab27d7

6,825 files changed

Lines changed: 20 additions & 185382 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.

parser/CLAUDE.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Parser Development Notes
2+
3+
## Running Tests
4+
5+
Always run parser tests with a 5 second timeout:
6+
7+
```bash
8+
go test ./parser/... -timeout 5s
9+
```
10+
11+
The tests are very fast. If a test is timing out, it indicates a bug (likely an infinite loop in the parser).

parser/parser_test.go

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,17 @@ import (
1414

1515
// testMetadata holds optional metadata for a test case
1616
type testMetadata struct {
17-
Todo bool `json:"todo,omitempty"`
18-
Source string `json:"source,omitempty"`
19-
}
20-
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"`
17+
Todo bool `json:"todo,omitempty"`
18+
Source string `json:"source,omitempty"`
19+
Explain *bool `json:"explain,omitempty"`
3720
}
3821

3922
// TestParser tests the parser using test cases from the testdata directory.
4023
// Each subdirectory in testdata represents a test case with:
4124
// - query.sql: The SQL query to parse
42-
// - ast.json: Expected AST from ClickHouse EXPLAIN AST
4325
// - metadata.json (optional): Metadata including:
4426
// - todo: true if the test is not yet expected to pass
27+
// - explain: false to skip the test (e.g., when ClickHouse couldn't parse it)
4528
func TestParser(t *testing.T) {
4629
testdataDir := "testdata"
4730

@@ -64,13 +47,13 @@ func TestParser(t *testing.T) {
6447
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
6548
defer cancel()
6649

67-
// Read the query (only first line, as ast.json was generated from first statement)
50+
// Read the query (only first line)
6851
queryPath := filepath.Join(testDir, "query.sql")
6952
queryBytes, err := os.ReadFile(queryPath)
7053
if err != nil {
7154
t.Fatalf("Failed to read query.sql: %v", err)
7255
}
73-
// Get first line only (ast.json contains AST for first statement)
56+
// Get first line only
7457
lines := strings.SplitN(string(queryBytes), "\n", 2)
7558
query := strings.TrimSpace(lines[0])
7659

@@ -83,18 +66,9 @@ func TestParser(t *testing.T) {
8366
}
8467
}
8568

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")
69+
// Skip tests where explain is explicitly false (e.g., ClickHouse couldn't parse it)
70+
if metadata.Explain != nil && !*metadata.Explain {
71+
t.Skipf("Skipping: explain is false in metadata")
9872
return
9973
}
10074

@@ -125,8 +99,6 @@ func TestParser(t *testing.T) {
12599
}
126100
t.Fatalf("JSON marshal error: %v\nQuery: %s", jsonErr, query)
127101
}
128-
129-
// TODO: Compare parsed AST against expectedAST.Data
130102
})
131103
}
132104
}

parser/testdata/00001_count_hits/ast.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

parser/testdata/00001_select_1/ast.json

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

parser/testdata/00002_count_visits/ast.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

parser/testdata/00002_system_numbers/ast.json

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

parser/testdata/00003_reinterpret_as_string/ast.json

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

parser/testdata/00004_shard_format_ast_and_remote_table/ast.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

parser/testdata/00004_top_counters/ast.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

parser/testdata/00005_filtering/ast.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)