From 273db8ff0de272c664d08c18f0ae1ecbf38262af Mon Sep 17 00:00:00 2001 From: Marcus Gartner Date: Thu, 25 Jan 2024 11:29:14 -0500 Subject: [PATCH] roachtest: remove interesting whitespace characters in random SQL tests logs In #102038 we started writing statements to the query log in SQL comments. The change removes newline characters in the statement to ensure that the statement will be on one line all within the comment. However, we still see test logs where the comments are broken onto multiple lines, as in #118273, which makes the file invalid syntactically. This makes reproducing the test failure more difficult because the comments have to be manually fixed so that the log file can be successfully parsed. I was able to determine that the line breaks are coming from other "interesting" whitespace characters. The `xxd` output from the log file in #118273 shows the carriage return character, `0d` being used in the middle of a column name: 00000090: 2041 5320 2263 6f0d 6c33 3830 2246 524f AS "co.l380"FRO This commit strips all interesting whitespace characters from the statement to prevent the comment from being broken on multiple lines. Release note: None --- pkg/cmd/roachtest/tests/query_comparison_util.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/cmd/roachtest/tests/query_comparison_util.go b/pkg/cmd/roachtest/tests/query_comparison_util.go index caf67686507f..ab92903e0aaa 100644 --- a/pkg/cmd/roachtest/tests/query_comparison_util.go +++ b/pkg/cmd/roachtest/tests/query_comparison_util.go @@ -437,6 +437,10 @@ type queryComparisonHelper struct { colTypes []string } +// stmtReplacer removes interesting white space characters that may be in +// a column or table name. See nameGenerator.GenerateOne. +var stmtReplacer = strings.NewReplacer("\n", "", "\r", "", "\f", "", "\v", "") + // runQuery runs the given query and returns the output. If the stmt doesn't // result in an error, as a side effect, it also saves the query, the query // plan, and the output of running the query so they can be logged in case of @@ -450,7 +454,7 @@ func (h *queryComparisonHelper) runQuery(stmt string) ([][]string, error) { // Remove all newline symbols to log this stmt as a single line. This // way this auxiliary logging takes up less space (if the stmt executes // successfully, it'll still get logged with the nice formatting). - strings.ReplaceAll(stmt, "\n", "")), + stmtReplacer.Replace(stmt)), ) runQueryImpl := func(stmt string) ([][]string, error) {