Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,11 @@ public Double visitLiteral(RexLiteral literal) {
private static double rangedSelectivity(KllFloatsSketch kll, float val1, float val2) {
float[] splitPoints = new float[] { val1, val2 };
double[] boundaries = kll.getCDF(splitPoints, QuantileSearchCriteria.EXCLUSIVE);
return boundaries[1] - boundaries[0];
// due to the way the KLL sketch is constructed,
// it is not possible to differentiate selectivity values below the error
// (e.g., if the error is 2%, a real selectivity of 1.5% might be estimated as 0% by KLL)
double normalizedRankError = kll.getNormalizedRankError(false);
return Math.max(boundaries[1] - boundaries[0], normalizedRankError);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public class TestFilterSelectivityEstimator {
private static final float[] VALUES = { 1, 2, 2, 2, 2, 2, 2, 2, 3, 4, 5, 6, 7 };
private static final KllFloatsSketch KLL = StatisticsTestUtils.createKll(VALUES);
private static final float DELTA = Float.MIN_VALUE;
private static final double MIN_KLL_SELECTIVITY = 0.013294757464848584;
private static final RexBuilder REX_BUILDER = new RexBuilder(new JavaTypeFactoryImpl(new HiveTypeSystemImpl()));
private static final RelDataTypeFactory TYPE_FACTORY = REX_BUILDER.getTypeFactory();
private static RelOptCluster relOptCluster;
Expand Down Expand Up @@ -240,12 +241,12 @@ public void testBetweenSelectivityLeftLowerThanMin() {

@Test
public void testBetweenSelectivityRightLowerThanMin() {
Assert.assertEquals(0, betweenSelectivity(KLL, -1, 0), DELTA);
Assert.assertEquals(MIN_KLL_SELECTIVITY, betweenSelectivity(KLL, -1, 0), DELTA);
}

@Test
public void testBetweenSelectivityLeftHigherThanMax() {
Assert.assertEquals(0, betweenSelectivity(KLL, 10, 11), DELTA);
Assert.assertEquals(MIN_KLL_SELECTIVITY, betweenSelectivity(KLL, 10, 11), DELTA);
}

@Test
Expand Down Expand Up @@ -399,15 +400,15 @@ public void testComputeRangePredicateSelectivityBetweenRightLowerThanMin() {
doReturn(Collections.singletonList(stats)).when(tableMock).getColStat(Collections.singletonList(0));
RexNode filter = REX_BUILDER.makeCall(HiveBetween.INSTANCE, boolFalse, inputRef0, intMinus1, int0);
FilterSelectivityEstimator estimator = new FilterSelectivityEstimator(scan, mq);
Assert.assertEquals(0, estimator.estimateSelectivity(filter), DELTA);
Assert.assertEquals(MIN_KLL_SELECTIVITY, estimator.estimateSelectivity(filter), DELTA);
}

@Test
public void testComputeRangePredicateSelectivityBetweenLeftHigherThanMax() {
doReturn(Collections.singletonList(stats)).when(tableMock).getColStat(Collections.singletonList(0));
RexNode filter = REX_BUILDER.makeCall(HiveBetween.INSTANCE, boolFalse, inputRef0, int10, int11);
FilterSelectivityEstimator estimator = new FilterSelectivityEstimator(scan, mq);
Assert.assertEquals(0, estimator.estimateSelectivity(filter), DELTA);
Assert.assertEquals(MIN_KLL_SELECTIVITY, estimator.estimateSelectivity(filter), DELTA);
}

@Test
Expand Down