Skip to content

Commit 602f942

Browse files
HIVE-29656: q.out regex fix
1 parent 4c4a618 commit 602f942

2 files changed

Lines changed: 37 additions & 2 deletions

File tree

itests/util/src/main/java/org/apache/hadoop/hive/ql/QOutProcessor.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public class QOutProcessor {
5858

5959
public static final String MASK_PATTERN = "#### A masked pattern was here ####";
6060
public static final String PARTIAL_MASK_PATTERN = "#### A PARTIAL masked pattern was here ####";
61+
public static final String MASKED_VERTEX_KILLED_PATTERN = "[Masked Vertex killed due to OTHER_VERTEX_FAILURE]";
6162
private static final PatternReplacementPair MASK_STATS = new PatternReplacementPair(
6263
Pattern.compile(" Num rows: [1-9][0-9]* Data size: [1-9][0-9]*"),
6364
" Num rows: ###Masked### Data size: ###Masked###");
@@ -197,6 +198,7 @@ public void maskPatterns(String fname) throws Exception {
197198
out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
198199

199200
boolean lastWasMasked = false;
201+
boolean lastWasVertexKilled = false;
200202

201203
while (null != (line = in.readLine())) {
202204
LineProcessingResult result = processLine(line);
@@ -209,10 +211,22 @@ public void maskPatterns(String fname) throws Exception {
209211
lastWasMasked = true;
210212
result.partialMaskWasMatched = false;
211213
}
214+
lastWasVertexKilled = false;
215+
} else if (result.line.equals(MASKED_VERTEX_KILLED_PATTERN)) {
216+
// Deduplicate consecutive standalone vertex-killed lines — the number of sibling
217+
// vertices still alive when the kill propagates is non-deterministic.
218+
if (!lastWasVertexKilled) {
219+
out.write(result.line);
220+
out.write("\n");
221+
lastWasVertexKilled = true;
222+
}
223+
lastWasMasked = false;
224+
result.partialMaskWasMatched = false;
212225
} else {
213226
out.write(result.line);
214227
out.write("\n");
215228
lastWasMasked = false;
229+
lastWasVertexKilled = false;
216230
result.partialMaskWasMatched = false;
217231
}
218232
}
@@ -350,7 +364,16 @@ private final static class PatternReplacementPair {
350364
// We do not want the test to fail because of this.
351365
ppm.add(new PatternReplacementPair(
352366
Pattern.compile("Vertex killed, vertexName=(.*?),.*\\[\\1\\] killed\\/failed due to:OTHER_VERTEX_FAILURE\\]"),
353-
"[Masked Vertex killed due to OTHER_VERTEX_FAILURE]"));
367+
MASKED_VERTEX_KILLED_PATTERN));
368+
369+
// Collapse multiple consecutive embedded [Masked Vertex killed] tokens on the same line
370+
// (the long FAILED: summary line repeats one token per killed vertex).
371+
ppm.add(new PatternReplacementPair(Pattern.compile("(\\Q" + MASKED_VERTEX_KILLED_PATTERN + "\\E){2,}"),
372+
MASKED_VERTEX_KILLED_PATTERN));
373+
374+
// The number of vertices killed when a DAG fails is a scheduling race condition —
375+
// depends on how many sibling vertices are still running at the moment the kill propagates.
376+
ppm.add(new PatternReplacementPair(Pattern.compile("killedVertices:[0-9]+"), "killedVertices:#Masked#"));
354377

355378
partialPlanMask = ppm.toArray(new PatternReplacementPair[ppm.size()]);
356379
}

itests/util/src/main/java/org/apache/hadoop/hive/ql/QTestUtil.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,19 @@ public QTestProcessExecResult checkCliDriverResults() throws Exception {
10201020
qTestResultProcessor.overwriteResults(f.getPath(), outFileName);
10211021
return QTestProcessExecResult.createWithoutOutput(0);
10221022
} else {
1023-
return qTestResultProcessor.executeDiffCommand(f.getPath(), outFileName, false);
1023+
// Apply the same masking pipeline to a temporary copy of the reference file so that
1024+
// non-deterministic values (e.g. killedVertices) are normalized on both sides.
1025+
// This preserves backward compatibility with existing .q.out files that were written
1026+
// before the masking rules were introduced.
1027+
File maskedRef = new File(outFileName + ".masked_ref");
1028+
try {
1029+
FileUtils.copyFile(new File(outFileName), maskedRef);
1030+
qOutProcessor.maskPatterns(maskedRef.getPath());
1031+
return qTestResultProcessor.executeDiffCommand(f.getPath(), maskedRef.getPath(), false);
1032+
} finally {
1033+
maskedRef.delete();
1034+
new File(maskedRef.getPath() + ".orig").delete();
1035+
}
10241036
}
10251037
}
10261038

0 commit comments

Comments
 (0)