Skip to content

Commit 26e1eb3

Browse files
craig[bot]yuzefovich
andcommitted
Merge #157861
157861: cmd/reduce: include removed lines into output r=yuzefovich a=yuzefovich `reduce` has several modes of operations where the "tail" queries from the reproduction are extracted to construct the special "comparison check" query. Previously, these extracted queries were omitted from the output, but now we'll include them (unreduced) at the tail. Epic: None Release note: None Co-authored-by: Yahor Yuzefovich <yahor@cockroachlabs.com>
2 parents 930e2ef + 4571e91 commit 26e1eb3

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

pkg/cmd/reduce/main.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func reduceSQL(
147147
chunkReductions int,
148148
multiRegion bool,
149149
tlp, costfuzz, unoptimizedOracle bool,
150-
) (string, error) {
150+
) (out string, retErr error) {
151151
var settings string
152152
if devLicense, ok := envutil.EnvString("COCKROACH_DEV_LICENSE", 0); ok {
153153
settings += "SET CLUSTER SETTING cluster.organization = 'Cockroach Labs - Production Testing';\n"
@@ -173,6 +173,20 @@ func reduceSQL(
173173

174174
inputString := string(input)
175175
var queryComparisonCheck string
176+
// removedLines, if set, indicates the lines from the end of input that were
177+
// removed from the input string (and were incorporated into
178+
// queryComparisonCheck).
179+
var removedLines []string
180+
defer func() {
181+
if retErr == nil && len(removedLines) > 0 {
182+
inputTail, err := reducesql.Pretty(strings.Join(removedLines, "\n"))
183+
if err != nil {
184+
retErr = errors.Wrapf(err, "when pretty-printing tail")
185+
} else {
186+
out = out + "\n" + inputTail
187+
}
188+
}
189+
}()
176190

177191
// If TLP check is requested, then we remove the last two queries from the
178192
// input (each query is expected to be delimited by empty lines) which we
@@ -187,6 +201,7 @@ func reduceSQL(
187201
lineIdx := len(lines) - 1
188202
partitioned, lineIdx := findPreviousQuery(lines, lineIdx)
189203
unpartitioned, lineIdx := findPreviousQuery(lines, lineIdx)
204+
removedLines = lines[lineIdx:]
190205
inputString = strings.Join(lines[:lineIdx], "\n")
191206
// We make queryComparisonCheck a query that will result in an error with
192207
// tlpFailureError error message when unpartitioned and partitioned queries
@@ -213,6 +228,7 @@ SELECT CASE
213228
setting2, lineIdx := findPreviousQuery(lines, lineIdx)
214229
setting1, lineIdx := findPreviousQuery(lines, lineIdx)
215230
control, lineIdx := findPreviousQuery(lines, lineIdx)
231+
removedLines = lines[lineIdx:]
216232
inputString = strings.Join(lines[:lineIdx], "\n")
217233
// We make queryComparisonCheck the original control / settings / perturbed
218234
// statements, surrounded by sentinel statements.
@@ -247,6 +263,7 @@ SELECT '%[1]s';
247263
settings2, lineIdx := findPreviousSetStatements(lines, lineIdx)
248264
unoptimized, lineIdx := findPreviousQuery(lines, lineIdx)
249265
settings1, lineIdx := findPreviousSetStatements(lines, lineIdx)
266+
removedLines = lines[lineIdx:]
250267
inputString = strings.Join(lines[:lineIdx], "\n")
251268
// We make queryComparisonCheck the original unoptimized / settings /
252269
// optimized statements, surrounded by sentinel statements.
@@ -372,7 +389,7 @@ SELECT '%[1]s';
372389
return containsRE.Match(out), logOriginalHint
373390
}
374391

375-
out, err := reduce.Reduce(
392+
return reduce.Reduce(
376393
logger,
377394
inputSQL,
378395
isInteresting,
@@ -381,7 +398,6 @@ SELECT '%[1]s';
381398
chunkReducer,
382399
reducesql.SQLPasses...,
383400
)
384-
return out, err
385401
}
386402

387403
// findPreviousQuery return the query preceding lineIdx without a semicolon.

0 commit comments

Comments
 (0)