[fix](stats) Fix potential NPE when loading Histogram (#19078)

Return Histogram.UNKNOWN as default when error occurred during loding
This commit is contained in:
AKIRA
2023-04-26 15:24:01 +09:00
committed by GitHub
parent d3a0b94602
commit 39cf393874
4 changed files with 11 additions and 7 deletions

View File

@ -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);
}

View File

@ -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;
}
}

View File

@ -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;
}
/**

View File

@ -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) {