Skip to content

Commit 7861eef

Browse files
committed
Fix regenerate-explain to preserve existing explain.txt files
Update the regenerate-explain tool to only generate explain_N.txt files for statements 2+, preserving the existing explain.txt files for the first statement. This prevents version-specific differences in ClickHouse EXPLAIN AST output from modifying the golden files.
1 parent d149200 commit 7861eef

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

cmd/regenerate-explain/main.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,31 +85,34 @@ func processTest(testDir, clickhouseBin string, dryRun bool) error {
8585

8686
fmt.Printf("Processing %s (%d statements)\n", filepath.Base(testDir), len(statements))
8787

88+
// Only process statements 2+ (skip first statement, keep existing explain.txt)
8889
for i, stmt := range statements {
90+
stmtNum := i + 1 // 1-indexed
8991
if dryRun {
90-
fmt.Printf(" [%d] %s\n", i+1, truncate(stmt, 80))
92+
fmt.Printf(" [%d] %s\n", stmtNum, truncate(stmt, 80))
93+
continue
94+
}
95+
96+
// Skip the first statement - don't touch explain.txt
97+
if i == 0 {
98+
fmt.Printf(" [%d] (skipped - keeping existing explain.txt)\n", stmtNum)
9199
continue
92100
}
93101

94102
explain, err := explainAST(clickhouseBin, stmt)
95103
if err != nil {
96-
fmt.Printf(" [%d] ERROR: %v\n", i+1, err)
104+
fmt.Printf(" [%d] ERROR: %v\n", stmtNum, err)
97105
// Skip statements that fail - they might be intentionally invalid
98106
continue
99107
}
100108

101-
// Determine output filename
102-
var outputPath string
103-
if i == 0 {
104-
outputPath = filepath.Join(testDir, "explain.txt")
105-
} else {
106-
outputPath = filepath.Join(testDir, fmt.Sprintf("explain_%d.txt", i+1))
107-
}
109+
// Output filename: explain_N.txt for N >= 2
110+
outputPath := filepath.Join(testDir, fmt.Sprintf("explain_%d.txt", stmtNum))
108111

109112
if err := os.WriteFile(outputPath, []byte(explain+"\n"), 0644); err != nil {
110113
return fmt.Errorf("writing %s: %w", outputPath, err)
111114
}
112-
fmt.Printf(" [%d] -> %s\n", i+1, filepath.Base(outputPath))
115+
fmt.Printf(" [%d] -> %s\n", stmtNum, filepath.Base(outputPath))
113116
}
114117

115118
return nil

0 commit comments

Comments
 (0)