Skip to content

Commit 89eff0e

Browse files
committed
cli/debug: strip comments in statement bundle env.sql file
SQL comments in statement bundle `env.sql` files are now ignored with the `cockroach debug sb recreate` command. Release note: None
1 parent 90ae675 commit 89eff0e

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

pkg/cli/statement_bundle.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"os"
1717
"path/filepath"
1818
"regexp"
19+
"slices"
1920
"sort"
2021
"strconv"
2122
"strings"
@@ -54,8 +55,11 @@ and stats in an unzipped statement bundle directory.
5455
Args: cobra.ExactArgs(1),
5556
}
5657

57-
var placeholderPairs []string
58-
var explainPrefix string
58+
var (
59+
placeholderPairs []string
60+
explainPrefix string
61+
commentPattern = regexp.MustCompile(`^\s*--`)
62+
)
5963

6064
func init() {
6165
statementBundleRecreateCmd.RunE = clierrorplus.MaybeDecorateError(runBundleRecreate)
@@ -169,8 +173,10 @@ func runBundleRecreate(cmd *cobra.Command, args []string) (resErr error) {
169173
return runDemoInternal(cmd, nil /* gen */, func(ctx context.Context, conn clisqlclient.Conn) error {
170174
// SET CLUSTER SETTING statements cannot be executed in multi-statement
171175
// implicit transaction, so we need to separate them out into their own
172-
// implicit transactions.
173-
initStmts := strings.Split(string(bundle.env), "SET CLUSTER SETTING")
176+
// implicit transactions. Comments are stripped from the env file first.
177+
lines := strings.Split(string(bundle.env), "\n")
178+
lines = slices.DeleteFunc(lines, commentPattern.MatchString)
179+
initStmts := strings.Split(strings.Join(lines, "\n"), "SET CLUSTER SETTING")
174180
for i := 1; i < len(initStmts); i++ {
175181
initStmts[i] = "SET CLUSTER SETTING " + initStmts[i]
176182
}

0 commit comments

Comments
 (0)