public void empty() { this.emptyRange() .distinctValuesCount(0) .nullsFraction(1); }
@Test public void testFunctionCall() { assertCalculate( new FunctionCall( QualifiedName.of("length"), ImmutableList.of(new Cast(new NullLiteral(), "VARCHAR(10)")))) .distinctValuesCount(0.0) .lowValueUnknown() .highValueUnknown() .nullsFraction(1.0); assertCalculate( new FunctionCall( QualifiedName.of("length"), ImmutableList.of(new SymbolReference("x"))), PlanNodeStatsEstimate.unknown(), TypeProvider.viewOf(ImmutableMap.of(new Symbol("x"), createVarcharType(2)))) .distinctValuesCountUnknown() .lowValueUnknown() .highValueUnknown() .nullsFractionUnknown(); }
@Test public void testVarbinaryConstant() { MetadataManager metadata = createTestMetadataManager(); LiteralEncoder literalEncoder = new LiteralEncoder(metadata.getBlockEncodingSerde()); Expression expression = literalEncoder.toExpression(Slices.utf8Slice("ala ma kota"), VARBINARY); assertCalculate(expression) .distinctValuesCount(1.0) .lowValueUnknown() .highValueUnknown() .nullsFraction(0.0); }
@Test public void testIsNotNullFilter() { assertExpression("x IS NOT NULL") .outputRowsCount(750.0) .symbolStats("x", symbolStats -> symbolStats.distinctValuesCount(40.0) .lowValue(-10.0) .highValue(10.0) .nullsFraction(0.0)); assertExpression("emptyRange IS NOT NULL") .outputRowsCount(0.0) .symbolStats("emptyRange", SymbolStatsAssertion::empty); }
private Consumer<SymbolStatsAssertion> equalTo(SymbolStatsEstimate estimate) { return symbolAssert -> { symbolAssert .lowValue(estimate.getLowValue()) .highValue(estimate.getHighValue()) .distinctValuesCount(estimate.getDistinctValuesCount()) .nullsFraction(estimate.getNullsFraction()); }; }
.highValue(3) .distinctValuesCount(26) .nullsFraction(0.0)); .highValue(-3) .distinctValuesCount(1) .nullsFraction(0.0)); .highValue(-3) .distinctValuesCount(14) .nullsFraction(0.0));
@Test public void testIsNullFilter() { assertExpression("x IS NULL") .outputRowsCount(250.0) .symbolStats(new Symbol("x"), symbolStats -> symbolStats.distinctValuesCount(0) .emptyRange() .nullsFraction(1.0)); assertExpression("emptyRange IS NULL") .outputRowsCount(1000.0) .symbolStats(new Symbol("emptyRange"), SymbolStatsAssertion::empty); }
.lowValue(7) .highValue(7) .nullsFraction(0.0); .lowValue(8) .highValue(8) .nullsFraction(0.0); .lowValue(9) .highValue(9) .nullsFraction(0.0); .lowValue(Long.MAX_VALUE) .highValue(Long.MAX_VALUE) .nullsFraction(0.0); .lowValue(7.5) .highValue(7.5) .nullsFraction(0.0); .lowValue(75.5) .highValue(75.5) .nullsFraction(0.0); .lowValueUnknown() .highValueUnknown() .nullsFraction(0.0); .lowValueUnknown()
public SymbolStatsAssertion isEqualTo(SymbolStatsEstimate expected) { return nullsFraction(expected.getNullsFraction()) .lowValue(expected.getLowValue()) .highValue(expected.getHighValue()) .distinctValuesCount(expected.getDistinctValuesCount()) .averageRowSize(expected.getAverageRowSize()); } }
.highValue(0.0) .distinctValuesCount(20.0) .nullsFraction(0.0)); .highValue(0.0) .distinctValuesCount(2.0) .nullsFraction(0.0)); .highValue(3) .distinctValuesCount(2) .nullsFraction(0)); .highValue(3) .distinctValuesCount(2) .nullsFraction(0));
@Test public void testNotStats() { assertExpression("NOT(x < 0e0)") .outputRowsCount(625) // FIXME - nulls shouldn't be restored .symbolStats(new Symbol("x"), symbolAssert -> symbolAssert.averageRowSize(4.0) .lowValue(-10.0) .highValue(10.0) .distinctValuesCount(20.0) .nullsFraction(0.4)) // FIXME - nulls shouldn't be restored .symbolStats(new Symbol("y"), symbolAssert -> symbolAssert.isEqualTo(yStats)); assertExpression("NOT(x IS NULL)") .outputRowsCount(750) .symbolStats(new Symbol("x"), symbolAssert -> symbolAssert.averageRowSize(4.0) .lowValue(-10.0) .highValue(10.0) .distinctValuesCount(40.0) .nullsFraction(0)) .symbolStats(new Symbol("y"), symbolAssert -> symbolAssert.isEqualTo(yStats)); assertExpression("NOT(json_array_contains(JSON '[]', x))") .outputRowsCountUnknown(); }
.highValue(0.0) .distinctValuesCount(15.0) .nullsFraction(0.0)); .highValue(0) .distinctValuesCount(20) .nullsFraction(0)); .highValue(0) .distinctValuesCount(20) .nullsFraction(0));
@Test public void testCastDoubleToShortRangeUnknownDistinctValuesCount() { PlanNodeStatsEstimate inputStatistics = PlanNodeStatsEstimate.builder() .addSymbolStatistics(new Symbol("a"), SymbolStatsEstimate.builder() .setNullsFraction(0.3) .setLowValue(1.6) .setHighValue(3.3) .setAverageRowSize(2.0) .build()) .build(); assertCalculate(new Cast(new SymbolReference("a"), "bigint"), inputStatistics) .lowValue(2.0) .highValue(3.0) .distinctValuesCountUnknown() .nullsFraction(0.3) .dataSizeUnknown(); }
@Test public void testCastDoubleToShortRange() { PlanNodeStatsEstimate inputStatistics = PlanNodeStatsEstimate.builder() .addSymbolStatistics(new Symbol("a"), SymbolStatsEstimate.builder() .setNullsFraction(0.3) .setLowValue(1.6) .setHighValue(3.3) .setDistinctValuesCount(10) .setAverageRowSize(2.0) .build()) .build(); assertCalculate(new Cast(new SymbolReference("a"), "bigint"), inputStatistics) .lowValue(2.0) .highValue(3.0) .distinctValuesCount(2) .nullsFraction(0.3) .dataSizeUnknown(); }
@Test public void testCastDoubleToBigint() { PlanNodeStatsEstimate inputStatistics = PlanNodeStatsEstimate.builder() .addSymbolStatistics(new Symbol("a"), SymbolStatsEstimate.builder() .setNullsFraction(0.3) .setLowValue(1.6) .setHighValue(17.3) .setDistinctValuesCount(10) .setAverageRowSize(2.0) .build()) .build(); assertCalculate(new Cast(new SymbolReference("a"), "bigint"), inputStatistics) .lowValue(2.0) .highValue(17.0) .distinctValuesCount(10) .nullsFraction(0.3) .dataSizeUnknown(); }
@Test public void testCastBigintToDouble() { PlanNodeStatsEstimate inputStatistics = PlanNodeStatsEstimate.builder() .addSymbolStatistics(new Symbol("a"), SymbolStatsEstimate.builder() .setNullsFraction(0.3) .setLowValue(2.0) .setHighValue(10.0) .setDistinctValuesCount(4) .setAverageRowSize(2.0) .build()) .build(); assertCalculate(new Cast(new SymbolReference("a"), "double"), inputStatistics) .lowValue(2.0) .highValue(10.0) .distinctValuesCount(4) .nullsFraction(0.3) .dataSizeUnknown(); }
.lowValue(-3.0) .highValue(15.0) .nullsFraction(0.28) .averageRowSize(2.0); .lowValue(-6.0) .highValue(12.0) .nullsFraction(0.28) .averageRowSize(2.0); .lowValue(-20.0) .highValue(50.0) .nullsFraction(0.28) .averageRowSize(2.0);
.lowValue(-2) .highValue(10) .nullsFraction(0.02) .averageRowSize(2.0); .lowValue(-2) .highValue(10) .nullsFraction(0.02) .averageRowSize(2.0);
.lowValue(xStats.getLowValue()) .highValue(xStats.getHighValue()) .nullsFraction(0) .distinctValuesCount(wStats.getDistinctValuesCount())) .symbolStats(w, stats -> stats.isEqualTo(wStats)) .lowValue(xStats.getLowValue()) .highValue(xStats.getHighValue()) .nullsFraction(0) .distinctValuesCount(xStats.getDistinctValuesCount())) .symbolStats(u, stats -> stats.isEqualTo(uStats)) .nullsFraction(0) .distinctValuesCountUnknown() .unknownRange()) .nullsFraction(0) .lowValue(xStats.getLowValue()) .highValue(xStats.getHighValue()) .outputRowsCount(1000) .symbolStats(fractionalNdv, stats -> stats .nullsFraction(0) .distinctValuesCount(0.1));
.lowValue(uStats.getLowValue()) .highValue(uStats.getHighValue()) .nullsFraction(0) .distinctValuesCount(uStats.getDistinctValuesCount() - xStats.getDistinctValuesCount())) .symbolStats(x, stats -> stats.isEqualTo(xStats)) .lowValue(xStats.getLowValue()) .highValue(xStats.getHighValue()) .nullsFraction(0) .distinctValuesCount(xStats.getDistinctValuesCount() * 0.5)) .symbolStats(u, stats -> stats.isEqualTo(uStats)) .nullsFraction(0) .distinctValuesCountUnknown() .unknownRange()) .nullsFraction(0) .lowValue(xStats.getLowValue()) .highValue(xStats.getHighValue()) .outputRowsCount(500) .symbolStats(fractionalNdv, stats -> stats .nullsFraction(0) .distinctValuesCount(0.05));