Skip to content

Commit 1c30c30

Browse files
authored
Regenerate all explain files with ClickHouse 25.8 (#77)
1 parent 31f17b3 commit 1c30c30

8,981 files changed

Lines changed: 44705 additions & 3340 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.

cmd/regenerate-explain/main.go

Lines changed: 78 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ import (
1212
"os"
1313
"os/exec"
1414
"path/filepath"
15+
"runtime"
1516
"strconv"
1617
"strings"
18+
"sync"
1719
"syscall"
1820
"time"
1921
)
@@ -40,6 +42,7 @@ func main() {
4042
dryRun := flag.Bool("dry-run", false, "Print statements without executing")
4143
serverOnly := flag.Bool("server", false, "Only ensure server is running, don't regenerate")
4244
stopServer := flag.Bool("stop", false, "Stop the ClickHouse server")
45+
parallel := flag.Int("j", runtime.NumCPU(), "Number of parallel workers (default: number of CPUs)")
4346
flag.Parse()
4447

4548
// Handle stop command
@@ -85,19 +88,68 @@ func main() {
8588
os.Exit(1)
8689
}
8790

88-
var errors []string
89-
var processed, skipped int
91+
// Collect test directories
92+
var testDirs []string
9093
for _, entry := range entries {
9194
if !entry.IsDir() {
9295
continue
9396
}
94-
testDir := filepath.Join(testdataDir, entry.Name())
95-
if err := processTest(testDir, *dryRun); err != nil {
96-
if strings.Contains(err.Error(), "no statements found") {
97-
skipped++
98-
continue
97+
testDirs = append(testDirs, filepath.Join(testdataDir, entry.Name()))
98+
}
99+
100+
// Process tests in parallel
101+
type result struct {
102+
name string
103+
err error
104+
skipped bool
105+
}
106+
107+
numWorkers := *parallel
108+
if numWorkers < 1 {
109+
numWorkers = 1
110+
}
111+
fmt.Printf("Processing %d tests with %d workers...\n", len(testDirs), numWorkers)
112+
113+
jobs := make(chan string, len(testDirs))
114+
results := make(chan result, len(testDirs))
115+
116+
// Start workers
117+
var wg sync.WaitGroup
118+
for w := 0; w < numWorkers; w++ {
119+
wg.Add(1)
120+
go func() {
121+
defer wg.Done()
122+
for testDir := range jobs {
123+
err := processTest(testDir, *dryRun)
124+
skipped := err != nil && strings.Contains(err.Error(), "no statements found")
125+
if skipped {
126+
err = nil
127+
}
128+
results <- result{name: filepath.Base(testDir), err: err, skipped: skipped}
99129
}
100-
errors = append(errors, fmt.Sprintf("%s: %v", entry.Name(), err))
130+
}()
131+
}
132+
133+
// Send jobs
134+
for _, testDir := range testDirs {
135+
jobs <- testDir
136+
}
137+
close(jobs)
138+
139+
// Wait for workers and close results
140+
go func() {
141+
wg.Wait()
142+
close(results)
143+
}()
144+
145+
// Collect results
146+
var errors []string
147+
var processed, skipped int
148+
for r := range results {
149+
if r.skipped {
150+
skipped++
151+
} else if r.err != nil {
152+
errors = append(errors, fmt.Sprintf("%s: %v", r.name, r.err))
101153
} else {
102154
processed++
103155
}
@@ -524,21 +576,23 @@ func processTest(testDir string, dryRun bool) error {
524576
return fmt.Errorf("no statements found")
525577
}
526578

527-
fmt.Printf("Processing %s (%d statements)\n", filepath.Base(testDir), len(statements))
579+
testName := filepath.Base(testDir)
528580

529-
// Generate version header comment
530-
versionHeader := fmt.Sprintf("-- Generated by ClickHouse %s\n", requiredVersion)
581+
if dryRun {
582+
fmt.Printf("Processing %s (%d statements)\n", testName, len(statements))
583+
for i, stmt := range statements {
584+
fmt.Printf(" [%d] %s\n", i+1, truncate(stmt, 80))
585+
}
586+
return nil
587+
}
531588

589+
var stmtErrors []string
532590
for i, stmt := range statements {
533591
stmtNum := i + 1 // 1-indexed
534-
if dryRun {
535-
fmt.Printf(" [%d] %s\n", stmtNum, truncate(stmt, 80))
536-
continue
537-
}
538592

539593
explain, err := explainAST(stmt)
540594
if err != nil {
541-
fmt.Printf(" [%d] ERROR: %v\n", stmtNum, err)
595+
stmtErrors = append(stmtErrors, fmt.Sprintf("stmt %d: %v", stmtNum, err))
542596
// Skip statements that fail - they might be intentionally invalid
543597
continue
544598
}
@@ -551,12 +605,17 @@ func processTest(testDir string, dryRun bool) error {
551605
outputPath = filepath.Join(testDir, fmt.Sprintf("explain_%d.txt", stmtNum))
552606
}
553607

554-
// Write with version header
555-
content := versionHeader + explain + "\n"
608+
content := explain + "\n"
556609
if err := os.WriteFile(outputPath, []byte(content), 0644); err != nil {
557610
return fmt.Errorf("writing %s: %w", outputPath, err)
558611
}
559-
fmt.Printf(" [%d] -> %s\n", stmtNum, filepath.Base(outputPath))
612+
}
613+
614+
// Print summary
615+
if len(stmtErrors) > 0 {
616+
fmt.Printf("%s: %d stmts, %d errors\n", testName, len(statements), len(stmtErrors))
617+
} else {
618+
fmt.Printf("%s: %d stmts OK\n", testName, len(statements))
560619
}
561620

562621
return nil

parser/parser_test.go

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -268,98 +268,6 @@ func TestParser(t *testing.T) {
268268
}
269269
}
270270

271-
// TestExplainVersionConsistency ensures all explain*.txt files have the same ClickHouse version header.
272-
// This test:
273-
// - Scans all explain*.txt files in testdata/
274-
// - Checks each file for a "-- Generated by ClickHouse X.X.X.X" header
275-
// - Reports files without version headers
276-
// - Reports if multiple different versions are found
277-
// - Passes only when all files have the same version header
278-
func TestExplainVersionConsistency(t *testing.T) {
279-
testdataDir := "testdata"
280-
281-
// Find all explain*.txt files
282-
var explainFiles []string
283-
err := filepath.Walk(testdataDir, func(path string, info os.FileInfo, err error) error {
284-
if err != nil {
285-
return err
286-
}
287-
if !info.IsDir() && strings.HasPrefix(info.Name(), "explain") && strings.HasSuffix(info.Name(), ".txt") {
288-
explainFiles = append(explainFiles, path)
289-
}
290-
return nil
291-
})
292-
if err != nil {
293-
t.Fatalf("Failed to walk testdata directory: %v", err)
294-
}
295-
296-
if len(explainFiles) == 0 {
297-
t.Skip("No explain*.txt files found")
298-
}
299-
300-
// Track versions and files without headers
301-
versionToFiles := make(map[string][]string)
302-
var filesWithoutHeaders []string
303-
304-
versionPattern := "-- Generated by ClickHouse "
305-
306-
for _, path := range explainFiles {
307-
content, err := os.ReadFile(path)
308-
if err != nil {
309-
t.Errorf("Failed to read %s: %v", path, err)
310-
continue
311-
}
312-
313-
lines := strings.Split(string(content), "\n")
314-
if len(lines) == 0 {
315-
filesWithoutHeaders = append(filesWithoutHeaders, path)
316-
continue
317-
}
318-
319-
firstLine := lines[0]
320-
if !strings.HasPrefix(firstLine, versionPattern) {
321-
filesWithoutHeaders = append(filesWithoutHeaders, path)
322-
continue
323-
}
324-
325-
// Extract version from "-- Generated by ClickHouse X.X.X.X"
326-
version := strings.TrimPrefix(firstLine, versionPattern)
327-
versionToFiles[version] = append(versionToFiles[version], path)
328-
}
329-
330-
// Report findings
331-
if len(filesWithoutHeaders) > 0 {
332-
t.Errorf("Found %d files without version headers:", len(filesWithoutHeaders))
333-
// Show first 10 files as examples
334-
limit := 10
335-
if len(filesWithoutHeaders) < limit {
336-
limit = len(filesWithoutHeaders)
337-
}
338-
for _, path := range filesWithoutHeaders[:limit] {
339-
t.Errorf(" - %s", path)
340-
}
341-
if len(filesWithoutHeaders) > 10 {
342-
t.Errorf(" ... and %d more", len(filesWithoutHeaders)-10)
343-
}
344-
}
345-
346-
if len(versionToFiles) > 1 {
347-
t.Errorf("Found %d different ClickHouse versions:", len(versionToFiles))
348-
for version, files := range versionToFiles {
349-
t.Errorf(" Version %q: %d files", version, len(files))
350-
}
351-
}
352-
353-
if len(filesWithoutHeaders) > 0 || len(versionToFiles) != 1 {
354-
t.FailNow()
355-
}
356-
357-
// Log the consistent version
358-
for version := range versionToFiles {
359-
t.Logf("All %d explain files have consistent version: %s", len(explainFiles), version)
360-
}
361-
}
362-
363271
// BenchmarkParser benchmarks the parser performance using a complex query
364272
func BenchmarkParser(b *testing.B) {
365273
query := `

parser/testdata/00001_select_1/explain.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
-- Generated by ClickHouse 25.8.13.73
21
SelectWithUnionQuery (children 1)
32
ExpressionList (children 1)
43
SelectQuery (children 1)

parser/testdata/00011_array_join_alias/explain.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,3 @@ SelectWithUnionQuery (children 1)
1919
TablesInSelectQueryElement (children 1)
2020
ArrayJoin (children 1)
2121
ExpressionList
22-
The query succeeded but the server error '42' was expected (query: EXPLAIN AST SELECT x, a FROM (SELECT arrayJoin(['Hello', 'Goodbye']) AS x, [1, 2, 3] AS arr) ARRAY JOIN; -- { serverError NUMBER_OF_ARGUMENTS_DOESNT_MATCH }).
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
InsertQuery (children 1)
2+
Identifier arrays_test
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
InsertQuery (children 1)
2+
Identifier nested_test
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
InsertQuery (children 1)
2+
Identifier alter_test
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
InsertQuery (children 1)
2+
Identifier array_element_test
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
InsertQuery (children 1)
2+
Identifier array_element_test
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
InsertQuery (children 1)
2+
Identifier array_element_test

0 commit comments

Comments
 (0)