Skip to content

Commit

Permalink
[feat](nereids) when check shape failed, print all plan with memo (#4…
Browse files Browse the repository at this point in the history
…5627)

### What problem does this PR solve?
when check plan shape failed, print all plan and memo into log for debug
  • Loading branch information
englefly authored Dec 24, 2024
1 parent a16b682 commit 9b0d962
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,9 @@ public String getExplainString(ExplainOptions explainOptions) {
+ "========== OPTIMIZED PLAN "
+ getTimeMetricString(SummaryProfile::getPrettyNereidsOptimizeTime) + " ==========\n"
+ optimizedPlan.treeString() + "\n\n";
if (cascadesContext != null && cascadesContext.getMemo() != null) {
plan += "========== MEMO " + cascadesContext.getMemo().toString() + "\n\n";
}

if (distributedPlans != null && !distributedPlans.isEmpty()) {
plan += "========== DISTRIBUTED PLAN "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import java.util.concurrent.Future
import java.util.concurrent.ThreadFactory
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicBoolean
import java.util.regex.Pattern
import java.util.stream.Collectors
import java.util.stream.LongStream
import static org.apache.doris.regression.util.DataUtils.sortByToString
Expand Down Expand Up @@ -263,7 +264,7 @@ class Suite implements GroovyInterceptable {
}

public <T> T connect(String user = context.config.jdbcUser, String password = context.config.jdbcPassword,
String url = context.config.jdbcUrl, Closure<T> actionSupplier) {
String url = context.config.jdbcUrl, Closure<T> actionSupplier) {
return context.connect(user, password, url, actionSupplier)
}

Expand Down Expand Up @@ -640,7 +641,7 @@ class Suite implements GroovyInterceptable {
}

long getTableVersion(long dbId, String tableName) {
def result = sql_return_maparray """show proc '/dbs/${dbId}'"""
def result = sql_return_maparray """show proc '/dbs/${dbId}'"""
for (def res : result) {
if(res.TableName.equals(tableName)) {
log.info(res.toString())
Expand Down Expand Up @@ -989,7 +990,7 @@ class Suite implements GroovyInterceptable {
if (exitcode != 0) {
staticLogger.info("exit code: ${exitcode}, output\n: ${proc.text}")
if (mustSuc == true) {
Assert.assertEquals(0, exitcode)
Assert.assertEquals(0, exitcode)
}
}
} catch (IOException e) {
Expand Down Expand Up @@ -1119,7 +1120,7 @@ class Suite implements GroovyInterceptable {
Connection getTargetConnection() {
return context.getTargetConnection(this)
}

boolean deleteFile(String filePath) {
def file = new File(filePath)
file.delete()
Expand All @@ -1142,7 +1143,7 @@ class Suite implements GroovyInterceptable {
)
DISTRIBUTED BY HASH(id) BUCKETS 1
PROPERTIES (
"replication_num" = "${backends.size()}"
"replication_num" = "${backends.size()}"
)
"""

Expand Down Expand Up @@ -1314,13 +1315,24 @@ class Suite implements GroovyInterceptable {
throw new IllegalStateException("Check tag '${tag}' failed, sql:\n${arg}", t)
}
if (errorMsg != null) {
def allPlan = ""
if (arg instanceof String) {
def query = (String) arg;
def pattern = Pattern.compile("^\\s*explain\\s+shape\\s*plan\\s*", Pattern.MULTILINE)
if (query =~ pattern) {
def physical = query.replaceAll(pattern, "explain all plan ")
try {
allPlan = JdbcUtils.executeToStringList(context.getConnection(), physical)[0].join('\n')
} catch (Throwable ignore) {}
}
}
String csvRealResult = realResults.stream()
.map {row -> OutputUtils.toCsvString(row)}
.collect(Collectors.joining("\n"))
.map { row -> OutputUtils.toCsvString(row) }
.collect(Collectors.joining("\n"))
def outputFilePath = context.outputFile.getCanonicalPath().substring(context.config.dataPath.length() + 1)
def line = expectCsvResults.currentLine()
logger.warn("expect results in file: ${outputFilePath}, line: ${line}\nrealResults:\n" + csvRealResult)
throw new IllegalStateException("Check tag '${tag}' failed:\n${errorMsg}\n\nsql:\n${arg}")
throw new IllegalStateException("Check tag '${tag}' failed:\n${errorMsg}\n\nsql:\n${arg}\n\n${allPlan}")
}
}
}
Expand Down

0 comments on commit 9b0d962

Please sign in to comment.