[fix](stats) Fix potential NPE when loading Histogram (#19078)
Return Histogram.UNKNOWN as default when error occurred during loding
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user