Skip to content

Commit 3d3b571

Browse files
committed
catch exception in statsCalculator
1 parent 2fd4fd2 commit 3d3b571

5 files changed

Lines changed: 41 additions & 10 deletions

File tree

fe/fe-core/src/main/java/org/apache/doris/nereids/stats/StatsCalculator.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,13 +301,32 @@ public static void estimate(GroupExpression groupExpression, CascadesContext con
301301

302302
private void estimate() {
303303
Plan plan = groupExpression.getPlan();
304-
Statistics newStats = plan.accept(this, null);
304+
Statistics newStats;
305+
try {
306+
newStats = plan.accept(this, null);
307+
} catch (Exception e) {
308+
// throw exception in debug mode
309+
if (ConnectContext.get() != null && ConnectContext.get().getSessionVariable().feDebug) {
310+
throw e;
311+
}
312+
// use unknown stats or the first child's stats
313+
if (plan.children().isEmpty() || !(plan.child(0) instanceof GroupPlan)) {
314+
Map<Expression, ColumnStatistic> columnStatisticMap = new HashMap<>();
315+
for (Slot slot : plan.getOutput()) {
316+
columnStatisticMap.put(slot, ColumnStatistic.createUnknownByDataType(slot.getDataType()));
317+
}
318+
newStats = new Statistics(1, 1, columnStatisticMap);
319+
} else {
320+
newStats = ((GroupPlan) plan.child(0)).getStats();
321+
}
322+
}
305323
newStats.normalizeColumnStatistics();
306324

307325
// We ensure that the rowCount remains unchanged in order to make the cost of each plan comparable.
326+
final Statistics tmpStats = newStats;
308327
if (groupExpression.getOwnerGroup().getStatistics() == null) {
309328
boolean isReliable = groupExpression.getPlan().getExpressions().stream()
310-
.noneMatch(e -> newStats.isInputSlotsUnknown(e.getInputSlots()));
329+
.noneMatch(e -> tmpStats.isInputSlotsUnknown(e.getInputSlots()));
311330
groupExpression.getOwnerGroup().setStatsReliable(isReliable);
312331
groupExpression.getOwnerGroup().setStatistics(newStats);
313332
} else {

fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DateLiteral.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ static Result<String, AnalysisException> normalize(String s) {
245245
}
246246
}
247247
// year/month/day missing
248-
if (partNumber < 3) {
248+
if (partNumber != 3) {
249249
final String currentString = s;
250250
return Result.err(
251251
() -> new AnalysisException("date/datetime literal [" + currentString + "] is invalid")

fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/GroupPlan.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public List<? extends Expression> getExpressions() {
6262

6363
@Override
6464
public Statistics getStats() {
65-
throw new IllegalStateException("GroupPlan can not invoke getStats()");
65+
return group.getStatistics();
6666
}
6767

6868
@Override

fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2272,12 +2272,8 @@ public void setDetailShapePlanNodes(String detailShapePlanNodes) {
22722272
public boolean fallbackOtherReplicaWhenFixedCorrupt = false;
22732273

22742274
@VariableMgr.VarAttr(name = "FE_DEBUG", needForward = true, fuzzy = true,
2275-
description = {"This is for testing purposes. In release mode (set to false), "
2276-
+ "the FE suppresses certain exceptions to allow SQL statements to proceed whenever possible.\n"
2277-
+ "In debug mode (set to true), the FE prioritizes throwing exceptions and halting SQL execution "
2278-
+ "immediately to expose errors.",
2279-
"release版本设置为false,系统会忽略一部分异常,使得sql尽可能执行;"
2280-
+ "debug版本设置为true,系统尽量返回异常,中断sql执行。"})
2275+
description = {"when set true, FE will throw exceptions instead swallow them. This is used for test",
2276+
"when set true, FE will throw exceptions instead swallow them. This is used for test"})
22812277
public boolean feDebug = false;
22822278

22832279
@VariableMgr.VarAttr(name = SHOW_ALL_FE_CONNECTION,

fe/fe-core/src/main/java/org/apache/doris/statistics/ColumnStatistic.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import org.apache.doris.catalog.Type;
2323
import org.apache.doris.common.AnalysisException;
2424
import org.apache.doris.datasource.InternalCatalog;
25+
import org.apache.doris.nereids.types.DataType;
26+
import org.apache.doris.nereids.types.coercion.CharacterType;
2527
import org.apache.doris.persist.gson.GsonUtils;
2628
import org.apache.doris.statistics.util.StatisticsUtil;
2729

@@ -369,4 +371,18 @@ public boolean isUnKnown() {
369371
public ColumnStatistic withAvgSizeByte(double avgSizeByte) {
370372
return new ColumnStatisticBuilder(this).setAvgSizeByte(avgSizeByte).build();
371373
}
374+
375+
public static ColumnStatistic createUnknownByDataType(DataType dataType) {
376+
if (dataType instanceof CharacterType) {
377+
return new ColumnStatisticBuilder(1).setAvgSizeByte(CharacterType.DEFAULT_PRECISION).setNdv(1)
378+
.setNumNulls(1).setMaxValue(Double.POSITIVE_INFINITY).setMinValue(Double.NEGATIVE_INFINITY)
379+
.setIsUnknown(true).setUpdatedTime("")
380+
.build();
381+
} else {
382+
return new ColumnStatisticBuilder(1).setAvgSizeByte(dataType.width()).setNdv(1)
383+
.setNumNulls(1).setMaxValue(Double.POSITIVE_INFINITY).setMinValue(Double.NEGATIVE_INFINITY)
384+
.setIsUnknown(true).setUpdatedTime("")
385+
.build();
386+
}
387+
}
372388
}

0 commit comments

Comments
 (0)