Skip to content

Commit

Permalink
fix null
Browse files Browse the repository at this point in the history
  • Loading branch information
englefly committed Oct 23, 2024
1 parent ed00c90 commit 81541fa
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ private Plan planWithoutLock(
.collectToList(LogicalOlapScan.class::isInstance);
Optional<String> disableJoinReorderReason = StatsCalculator
.disableJoinReorderIfStatsInvalid(scans, cascadesContext);
statementContext.setDisableJoinReorderReason(disableJoinReorderReason);
disableJoinReorderReason.ifPresent(statementContext::setDisableJoinReorderReason);
}

optimize();
Expand Down Expand Up @@ -578,13 +578,6 @@ public String getHintExplainString(List<Hint> hints) {
public String getExplainString(ExplainOptions explainOptions) {
ExplainLevel explainLevel = getExplainLevel(explainOptions);
String plan = "";
String mvSummary = "";
if (this.getPhysicalPlan() != null && cascadesContext != null) {
mvSummary = cascadesContext.getMaterializationContexts().isEmpty() ? "" :
"\n\n========== MATERIALIZATIONS ==========\n"
+ MaterializationContext.toSummaryString(cascadesContext.getMaterializationContexts(),
this.getPhysicalPlan());
}
switch (explainLevel) {
case PARSED_PLAN:
plan = parsedPlan.treeString();
Expand Down Expand Up @@ -637,23 +630,23 @@ public String getExplainString(ExplainOptions explainOptions) {
+ getTimeMetricString(SummaryProfile::getPrettyNereidsDistributeTime) + " ==========\n";
plan += DistributedPlan.toString(Lists.newArrayList(distributedPlans.values())) + "\n\n";
}
plan += mvSummary;
break;
default:
plan = super.getExplainString(explainOptions);
plan += mvSummary;
plan += "\n\n\n========== STATISTICS ==========\n";
if (statementContext != null) {
if (statementContext.isHasUnknownColStats()) {
plan += "planed with unknown column statistics\n";
}
}
}

if (this.getPhysicalPlan() != null && cascadesContext != null) {
plan += cascadesContext.getMaterializationContexts().isEmpty() ? "" :
"\n\n========== MATERIALIZATIONS ==========\n"
+ MaterializationContext.toSummaryString(cascadesContext.getMaterializationContexts(),
this.getPhysicalPlan());
}
if (statementContext != null) {
if (statementContext.isHasUnknownColStats()) {
plan += "planed with unknown column statistics\n";
}
if (statementContext.getDisableJoinReorderReason().isPresent()) {
plan += "\n\n\n========== DISABLE JOIN REORDER ==========\n";
plan += statementContext.getDisableJoinReorderReason().get();
plan += "\ndisable join reorder reason\n";
plan += statementContext.getDisableJoinReorderReason().get() + "\n";
}
if (!statementContext.getHints().isEmpty()) {
String hint = getHintExplainString(statementContext.getHints());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public class StatementContext implements Closeable {

private List<PlannerHook> plannerHooks = new ArrayList<>();

private Optional<String> disableJoinReorderReason;
private String disableJoinReorderReason;

public StatementContext() {
this(ConnectContext.get(), null, 0);
Expand Down Expand Up @@ -562,10 +562,10 @@ public TableId getTableId(TableIf tableIf) {
}

public Optional<String> getDisableJoinReorderReason() {
return disableJoinReorderReason;
return Optional.ofNullable(disableJoinReorderReason);
}

public void setDisableJoinReorderReason(Optional<String> disableJoinReorderReason) {
public void setDisableJoinReorderReason(String disableJoinReorderReason) {
this.disableJoinReorderReason = disableJoinReorderReason;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -221,17 +221,18 @@ public static Optional<String> disableJoinReorderIfStatsInvalid(List<LogicalOlap
CascadesContext context) {
StatsCalculator calculator = new StatsCalculator(context);
if (ConnectContext.get() == null) {
// ut
// ut case
return Optional.empty();
}
for (LogicalOlapScan scan : scans) {
double rowCount = calculator.getOlapTableRowCount(scan);
// analyzed rowCount may be zero, but BE-reported rowCount could be positive.
// row count not available
if (rowCount == -1) {
LOG.info("disable join reorder since row count not available: "
+ scan.getTable().getNameWithFullQualifiers());
return Optional.of("table[" + scan.getTable().getName() + "] row count is invalid");
}
// ndv abnormal
Optional<String> reason = calculator.checkNdvValidation(scan, rowCount);
if (reason.isPresent()) {
try {
Expand Down

0 comments on commit 81541fa

Please sign in to comment.