Skip to content

Commit 1eefa49

Browse files
authored
Remove ast.json files and skip tests when explain: false in metadata (#9)
1 parent d709d82 commit 1eefa49

File tree

6,826 files changed

+26
-185381
lines changed

Some content is hidden

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

6,826 files changed

+26
-185381
lines changed

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: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,19 @@ 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"`
20+
Skip bool `json:"skip,omitempty"`
3721
}
3822

3923
// TestParser tests the parser using test cases from the testdata directory.
4024
// Each subdirectory in testdata represents a test case with:
4125
// - query.sql: The SQL query to parse
42-
// - ast.json: Expected AST from ClickHouse EXPLAIN AST
4326
// - metadata.json (optional): Metadata including:
4427
// - todo: true if the test is not yet expected to pass
28+
// - explain: false to skip the test (e.g., when ClickHouse couldn't parse it)
29+
// - skip: true to skip the test entirely (e.g., causes infinite loop)
4530
func TestParser(t *testing.T) {
4631
testdataDir := "testdata"
4732

@@ -64,13 +49,13 @@ func TestParser(t *testing.T) {
6449
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
6550
defer cancel()
6651

67-
// Read the query (only first line, as ast.json was generated from first statement)
52+
// Read the query (only first line)
6853
queryPath := filepath.Join(testDir, "query.sql")
6954
queryBytes, err := os.ReadFile(queryPath)
7055
if err != nil {
7156
t.Fatalf("Failed to read query.sql: %v", err)
7257
}
73-
// Get first line only (ast.json contains AST for first statement)
58+
// Get first line only
7459
lines := strings.SplitN(string(queryBytes), "\n", 2)
7560
query := strings.TrimSpace(lines[0])
7661

@@ -83,18 +68,14 @@ func TestParser(t *testing.T) {
8368
}
8469
}
8570

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-
}
71+
// Skip tests marked with skip: true
72+
if metadata.Skip {
73+
t.Skip("Skipping: skip is true in metadata")
9374
}
9475

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")
76+
// Skip tests where explain is explicitly false (e.g., ClickHouse couldn't parse it)
77+
if metadata.Explain != nil && !*metadata.Explain {
78+
t.Skipf("Skipping: explain is false in metadata")
9879
return
9980
}
10081

@@ -125,8 +106,6 @@ func TestParser(t *testing.T) {
125106
}
126107
t.Fatalf("JSON marshal error: %v\nQuery: %s", jsonErr, query)
127108
}
128-
129-
// TODO: Compare parsed AST against expectedAST.Data
130109
})
131110
}
132111
}

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)