This is an automated email from the ASF dual-hosted git repository. morrysnow pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new 39cf393874 [fix](stats) Fix potential NPE when loading Histogram (#19078) 39cf393874 is described below commit 39cf393874162aa0457c354d165c9f68f22c2153 Author: AKIRA <33112463+kikyou1...@users.noreply.github.com> AuthorDate: Wed Apr 26 15:24:01 2023 +0900 [fix](stats) Fix potential NPE when loading Histogram (#19078) Return Histogram.UNKNOWN as default when error occurred during loding --- .../main/java/org/apache/doris/nereids/stats/FilterEstimation.java | 6 +++--- .../src/main/java/org/apache/doris/statistics/ColumnStatistic.java | 4 ++++ fe/fe-core/src/main/java/org/apache/doris/statistics/Histogram.java | 4 ++-- .../src/main/java/org/apache/doris/statistics/StatisticsCache.java | 4 ++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/stats/FilterEstimation.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/stats/FilterEstimation.java index 6deca33e2e..90ab646146 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/stats/FilterEstimation.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/stats/FilterEstimation.java @@ -173,7 +173,7 @@ public class FilterEstimation extends ExpressionVisitor<Statistics, EstimationCo private Statistics updateLessThanLiteral(Expression leftExpr, ColumnStatistic statsForLeft, double val, EstimationContext context, boolean contains) { - if (statsForLeft.histogram != null) { + if (statsForLeft.hasHistogram()) { return estimateLessThanLiteralWithHistogram(leftExpr, statsForLeft, val, context, contains); } //rightRange.distinctValues should not be used @@ -186,7 +186,7 @@ public class FilterEstimation extends ExpressionVisitor<Statistics, EstimationCo private Statistics updateGreaterThanLiteral(Expression leftExpr, ColumnStatistic statsForLeft, double val, EstimationContext context, boolean contains) { - if (statsForLeft.histogram != null) { + if (statsForLeft.hasHistogram()) { return estimateGreaterThanLiteralWithHistogram(leftExpr, statsForLeft, val, context, contains); } //rightRange.distinctValues should not be used @@ -228,7 +228,7 @@ public class FilterEstimation extends ExpressionVisitor<Statistics, EstimationCo } else { selectivity = StatsMathUtil.minNonNaN(1.0, 1.0 / ndv); } - if (statsForLeft.histogram != null) { + if (statsForLeft.hasHistogram()) { return estimateEqualToWithHistogram(cp.left(), statsForLeft, val, context); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/statistics/ColumnStatistic.java b/fe/fe-core/src/main/java/org/apache/doris/statistics/ColumnStatistic.java index 2e2cb9b66c..ef5da59d81 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/statistics/ColumnStatistic.java +++ b/fe/fe-core/src/main/java/org/apache/doris/statistics/ColumnStatistic.java @@ -271,4 +271,8 @@ public class ColumnStatistic { public boolean minOrMaxIsInf() { return Double.isInfinite(maxValue) || Double.isInfinite(minValue); } + + public boolean hasHistogram() { + return histogram != null && histogram != Histogram.UNKNOWN; + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/statistics/Histogram.java b/fe/fe-core/src/main/java/org/apache/doris/statistics/Histogram.java index 0592a241e1..643c25c82b 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/statistics/Histogram.java +++ b/fe/fe-core/src/main/java/org/apache/doris/statistics/Histogram.java @@ -109,7 +109,7 @@ public class Histogram { */ public static Histogram deserializeFromJson(String json) { if (Strings.isNullOrEmpty(json)) { - return null; + return Histogram.UNKNOWN; } try { @@ -140,7 +140,7 @@ public class Histogram { LOG.error("deserialize from json error.", e); } - return null; + return Histogram.UNKNOWN; } /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/statistics/StatisticsCache.java b/fe/fe-core/src/main/java/org/apache/doris/statistics/StatisticsCache.java index ccac80a5f2..ea0028dbbd 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/statistics/StatisticsCache.java +++ b/fe/fe-core/src/main/java/org/apache/doris/statistics/StatisticsCache.java @@ -93,7 +93,7 @@ public class StatisticsCache { StatisticsCacheKey k = new StatisticsCacheKey(tblId, idxId, colName); try { CompletableFuture<Optional<ColumnStatistic>> f = columnStatisticsCache.get(k); - if (f.isDone() && f.get() != null) { + if (f.isDone()) { return f.get(); } } catch (Exception e) { @@ -114,7 +114,7 @@ public class StatisticsCache { StatisticsCacheKey k = new StatisticsCacheKey(tblId, idxId, colName); try { CompletableFuture<Optional<Histogram>> f = histogramCache.get(k); - if (f.isDone() && f.get() != null) { + if (f.isDone()) { return f.get(); } } catch (Exception e) { --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org