diff --git a/presto-main/src/main/java/com/facebook/presto/cost/AggregationStatsRule.java b/presto-main/src/main/java/com/facebook/presto/cost/AggregationStatsRule.java index 866eb21b09cac..c11fedce9c259 100644 --- a/presto-main/src/main/java/com/facebook/presto/cost/AggregationStatsRule.java +++ b/presto-main/src/main/java/com/facebook/presto/cost/AggregationStatsRule.java @@ -26,6 +26,7 @@ import java.util.Optional; import static com.facebook.presto.spi.plan.AggregationNode.Step.SINGLE; +import static com.facebook.presto.spi.statistics.SourceInfo.ConfidenceLevel.FACT; import static com.facebook.presto.sql.planner.plan.Patterns.aggregation; import static java.lang.Math.min; import static java.util.Objects.requireNonNull; @@ -66,6 +67,11 @@ protected Optional doCalculate(AggregationNode node, Stat public static PlanNodeStatsEstimate groupBy(PlanNodeStatsEstimate sourceStats, Collection groupByVariables, Map aggregations) { PlanNodeStatsEstimate.Builder result = PlanNodeStatsEstimate.builder(); + + if (isGlobalAggregation(groupByVariables)) { + result.setConfidence(FACT); + } + for (VariableReferenceExpression groupByVariable : groupByVariables) { VariableStatsEstimate symbolStatistics = sourceStats.getVariableStatistics(groupByVariable); result.addVariableStatistics(groupByVariable, symbolStatistics.mapNullsFraction(nullsFraction -> { @@ -99,4 +105,9 @@ private static VariableStatsEstimate estimateAggregationStats(Aggregation aggreg // TODO implement simple aggregations like: min, max, count, sum return VariableStatsEstimate.unknown(); } + + private static boolean isGlobalAggregation(Collection groupingKeys) + { + return groupingKeys.isEmpty(); + } } diff --git a/presto-main/src/main/java/com/facebook/presto/cost/EnforceSingleRowStatsRule.java b/presto-main/src/main/java/com/facebook/presto/cost/EnforceSingleRowStatsRule.java index 940d7bda9519e..d390c35d9352b 100644 --- a/presto-main/src/main/java/com/facebook/presto/cost/EnforceSingleRowStatsRule.java +++ b/presto-main/src/main/java/com/facebook/presto/cost/EnforceSingleRowStatsRule.java @@ -21,6 +21,7 @@ import java.util.Optional; +import static com.facebook.presto.spi.statistics.SourceInfo.ConfidenceLevel.FACT; import static com.facebook.presto.sql.planner.plan.Patterns.enforceSingleRow; public class EnforceSingleRowStatsRule @@ -44,6 +45,7 @@ protected Optional doCalculate(EnforceSingleRowNode node, { return Optional.of(PlanNodeStatsEstimate.buildFrom(sourceStats.getStats(node.getSource())) .setOutputRowCount(1) + .setConfidence(FACT) .build()); } } diff --git a/presto-main/src/main/java/com/facebook/presto/cost/ExchangeStatsRule.java b/presto-main/src/main/java/com/facebook/presto/cost/ExchangeStatsRule.java index 903884c8e5fe7..7fbd2240ee969 100644 --- a/presto-main/src/main/java/com/facebook/presto/cost/ExchangeStatsRule.java +++ b/presto-main/src/main/java/com/facebook/presto/cost/ExchangeStatsRule.java @@ -26,6 +26,8 @@ import static com.facebook.presto.SystemSessionProperties.shouldOptimizerUseHistograms; import static com.facebook.presto.cost.PlanNodeStatsEstimate.buildFrom; +import static com.facebook.presto.spi.statistics.SourceInfo.ConfidenceLevel; +import static com.facebook.presto.spi.statistics.SourceInfo.ConfidenceLevel.FACT; import static com.facebook.presto.sql.planner.plan.Patterns.exchange; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Verify.verify; @@ -51,13 +53,13 @@ protected Optional doCalculate(ExchangeNode node, StatsPr { Optional estimate = Optional.empty(); double totalSize = 0; - boolean confident = true; + ConfidenceLevel confidenceLevel = FACT; for (int i = 0; i < node.getSources().size(); i++) { PlanNode source = node.getSources().get(i); PlanNodeStatsEstimate sourceStats = statsProvider.getStats(source); totalSize += sourceStats.getOutputSizeInBytes(); - if (!sourceStats.isConfident()) { - confident = false; + if (sourceStats.confidenceLevel().ordinal() < confidenceLevel.ordinal()) { + confidenceLevel = sourceStats.confidenceLevel(); } PlanNodeStatsEstimate sourceStatsWithMappedSymbols = mapToOutputVariables(sourceStats, node.getInputs().get(i), node.getOutputVariables()); @@ -74,7 +76,7 @@ protected Optional doCalculate(ExchangeNode node, StatsPr verify(estimate.isPresent()); return Optional.of(buildFrom(estimate.get()) .setTotalSize(totalSize) - .setConfident(confident) + .setConfidence(confidenceLevel) .build()); } diff --git a/presto-main/src/main/java/com/facebook/presto/cost/LimitStatsRule.java b/presto-main/src/main/java/com/facebook/presto/cost/LimitStatsRule.java index 29479668357f0..bc2305ca2ae5c 100644 --- a/presto-main/src/main/java/com/facebook/presto/cost/LimitStatsRule.java +++ b/presto-main/src/main/java/com/facebook/presto/cost/LimitStatsRule.java @@ -50,6 +50,7 @@ protected Optional doCalculate(LimitNode node, StatsProvi // LIMIT actually limits (or when there was no row count estimated for source) return Optional.of(PlanNodeStatsEstimate.buildFrom(sourceStats) .setOutputRowCount(node.getCount()) + .setConfidence(sourceStats.confidenceLevel()) .build()); } } diff --git a/presto-main/src/main/java/com/facebook/presto/cost/PlanNodeStatsEstimate.java b/presto-main/src/main/java/com/facebook/presto/cost/PlanNodeStatsEstimate.java index e825c7565260c..ab6bf3c397bf7 100644 --- a/presto-main/src/main/java/com/facebook/presto/cost/PlanNodeStatsEstimate.java +++ b/presto-main/src/main/java/com/facebook/presto/cost/PlanNodeStatsEstimate.java @@ -41,6 +41,8 @@ import java.util.Set; import java.util.function.Function; +import static com.facebook.presto.spi.statistics.SourceInfo.ConfidenceLevel; +import static com.facebook.presto.spi.statistics.SourceInfo.ConfidenceLevel.LOW; import static com.facebook.presto.util.MoreMath.firstNonNaN; import static com.google.common.base.MoreObjects.toStringHelper; import static com.google.common.base.Preconditions.checkArgument; @@ -51,7 +53,7 @@ public class PlanNodeStatsEstimate { private static final double DEFAULT_DATA_SIZE_PER_COLUMN = 50; - private static final PlanNodeStatsEstimate UNKNOWN = new PlanNodeStatsEstimate(NaN, NaN, false, ImmutableMap.of(), JoinNodeStatsEstimate.unknown(), TableWriterNodeStatsEstimate.unknown(), PartialAggregationStatsEstimate.unknown()); + private static final PlanNodeStatsEstimate UNKNOWN = new PlanNodeStatsEstimate(NaN, NaN, LOW, ImmutableMap.of(), JoinNodeStatsEstimate.unknown(), TableWriterNodeStatsEstimate.unknown(), PartialAggregationStatsEstimate.unknown()); private final double outputRowCount; private final double totalSize; @@ -74,7 +76,7 @@ public static PlanNodeStatsEstimate unknown() public PlanNodeStatsEstimate( @JsonProperty("outputRowCount") double outputRowCount, @JsonProperty("totalSize") double totalSize, - @JsonProperty("confident") boolean confident, + @JsonProperty("confident") ConfidenceLevel confidenceLevel, @JsonProperty("variableStatistics") Map variableStatistics, @JsonProperty("joinNodeStatsEstimate") JoinNodeStatsEstimate joinNodeStatsEstimate, @JsonProperty("tableWriterNodeStatsEstimate") TableWriterNodeStatsEstimate tableWriterNodeStatsEstimate, @@ -83,12 +85,12 @@ public PlanNodeStatsEstimate( this(outputRowCount, totalSize, HashTreePMap.from(requireNonNull(variableStatistics, "variableStatistics is null")), - new CostBasedSourceInfo(confident), joinNodeStatsEstimate, tableWriterNodeStatsEstimate, partialAggregationStatsEstimate); + new CostBasedSourceInfo(confidenceLevel), joinNodeStatsEstimate, tableWriterNodeStatsEstimate, partialAggregationStatsEstimate); } - private PlanNodeStatsEstimate(double outputRowCount, double totalSize, boolean confident, PMap variableStatistics) + private PlanNodeStatsEstimate(double outputRowCount, double totalSize, ConfidenceLevel confidenceLevel, PMap variableStatistics) { - this(outputRowCount, totalSize, variableStatistics, new CostBasedSourceInfo(confident)); + this(outputRowCount, totalSize, variableStatistics, new CostBasedSourceInfo(confidenceLevel)); } public PlanNodeStatsEstimate(double outputRowCount, double totalSize, PMap variableStatistics, SourceInfo sourceInfo) @@ -126,9 +128,9 @@ public double getTotalSize() } @JsonProperty - public boolean isConfident() + public ConfidenceLevel confidenceLevel() { - return sourceInfo.isConfident(); + return sourceInfo.confidenceLevel(); } public SourceInfo getSourceInfo() @@ -327,7 +329,7 @@ public PlanStatisticsWithSourceInfo toPlanStatisticsWithSourceInfo(PlanNodeId id new PlanStatistics( Estimate.estimateFromDouble(outputRowCount), Estimate.estimateFromDouble(totalSize), - sourceInfo.isConfident() ? 1 : 0, + sourceInfo.confidenceLevel() == LOW ? 0 : 1, new JoinNodeStatistics( Estimate.estimateFromDouble(joinNodeStatsEstimate.getNullJoinBuildKeyCount()), Estimate.estimateFromDouble(joinNodeStatsEstimate.getJoinBuildKeyCount()), @@ -349,27 +351,27 @@ public static Builder builder() // we should propagate totalSize as default to simplify the relevant operations in rules that do not change this field. public static Builder buildFrom(PlanNodeStatsEstimate other) { - return new Builder(other.getOutputRowCount(), NaN, other.isConfident(), other.variableStatistics); + return new Builder(other.getOutputRowCount(), NaN, other.confidenceLevel(), other.variableStatistics); } public static final class Builder { private double outputRowCount; private double totalSize; - private boolean confident; + private ConfidenceLevel confidenceLevel; private PMap variableStatistics; private PartialAggregationStatsEstimate partialAggregationStatsEstimate; public Builder() { - this(NaN, NaN, false, HashTreePMap.empty()); + this(NaN, NaN, LOW, HashTreePMap.empty()); } - private Builder(double outputRowCount, double totalSize, boolean confident, PMap variableStatistics) + private Builder(double outputRowCount, double totalSize, ConfidenceLevel confidenceLevel, PMap variableStatistics) { this.outputRowCount = outputRowCount; this.totalSize = totalSize; - this.confident = confident; + this.confidenceLevel = confidenceLevel; this.variableStatistics = variableStatistics; this.partialAggregationStatsEstimate = PartialAggregationStatsEstimate.unknown(); } @@ -386,9 +388,9 @@ public Builder setTotalSize(double totalSize) return this; } - public Builder setConfident(boolean confident) + public Builder setConfidence(ConfidenceLevel confidenceLevel) { - this.confident = confident; + this.confidenceLevel = confidenceLevel; return this; } @@ -420,7 +422,7 @@ public PlanNodeStatsEstimate build() { return new PlanNodeStatsEstimate(outputRowCount, totalSize, - confident, + confidenceLevel, variableStatistics, JoinNodeStatsEstimate.unknown(), TableWriterNodeStatsEstimate.unknown(), diff --git a/presto-main/src/main/java/com/facebook/presto/cost/ProjectStatsRule.java b/presto-main/src/main/java/com/facebook/presto/cost/ProjectStatsRule.java index 24df58caa9d0a..e5d8649379c0e 100644 --- a/presto-main/src/main/java/com/facebook/presto/cost/ProjectStatsRule.java +++ b/presto-main/src/main/java/com/facebook/presto/cost/ProjectStatsRule.java @@ -24,6 +24,8 @@ import java.util.Map; import java.util.Optional; +import static com.facebook.presto.spi.statistics.SourceInfo.ConfidenceLevel; +import static com.facebook.presto.spi.statistics.SourceInfo.ConfidenceLevel.LOW; import static com.facebook.presto.sql.planner.plan.Patterns.project; import static java.util.Objects.requireNonNull; @@ -50,9 +52,12 @@ public Pattern getPattern() protected Optional doCalculate(ProjectNode node, StatsProvider statsProvider, Lookup lookup, Session session, TypeProvider types) { PlanNodeStatsEstimate sourceStats = statsProvider.getStats(node.getSource()); + + boolean noChange = noChangeToSourceColumns(node); + ConfidenceLevel newConfidence = noChange ? sourceStats.confidenceLevel() : LOW; PlanNodeStatsEstimate.Builder calculatedStats = PlanNodeStatsEstimate.builder() .setOutputRowCount(sourceStats.getOutputRowCount()) - .setConfident(sourceStats.isConfident() && noChangeToSourceColumns(node)); + .setConfidence(newConfidence); for (Map.Entry entry : node.getAssignments().entrySet()) { RowExpression expression = entry.getValue(); diff --git a/presto-main/src/main/java/com/facebook/presto/cost/TableScanStatsRule.java b/presto-main/src/main/java/com/facebook/presto/cost/TableScanStatsRule.java index 2bae731d8c66a..5cc3823a929ae 100644 --- a/presto-main/src/main/java/com/facebook/presto/cost/TableScanStatsRule.java +++ b/presto-main/src/main/java/com/facebook/presto/cost/TableScanStatsRule.java @@ -30,6 +30,7 @@ import java.util.Map; import java.util.Optional; +import static com.facebook.presto.spi.statistics.SourceInfo.ConfidenceLevel.FACT; import static com.facebook.presto.sql.planner.plan.Patterns.tableScan; import static java.util.Objects.requireNonNull; @@ -69,7 +70,9 @@ protected Optional doCalculate(TableScanNode node, StatsP return Optional.of(PlanNodeStatsEstimate.builder() .setOutputRowCount(tableStatistics.getRowCount().getValue()) .setTotalSize(tableStatistics.getTotalSize().getValue()) - .setConfident(true) + + // TODO Handle the confidence level properly when filters are pushed into the tablescan + .setConfidence(FACT) .addVariableStatistics(outputVariableStats) .build()); } diff --git a/presto-main/src/main/java/com/facebook/presto/cost/ValuesStatsRule.java b/presto-main/src/main/java/com/facebook/presto/cost/ValuesStatsRule.java index 916e4f39afc05..a7c67756c4622 100644 --- a/presto-main/src/main/java/com/facebook/presto/cost/ValuesStatsRule.java +++ b/presto-main/src/main/java/com/facebook/presto/cost/ValuesStatsRule.java @@ -32,6 +32,7 @@ import static com.facebook.presto.common.type.UnknownType.UNKNOWN; import static com.facebook.presto.cost.StatsUtil.toStatsRepresentation; +import static com.facebook.presto.spi.statistics.SourceInfo.ConfidenceLevel.FACT; import static com.facebook.presto.sql.planner.RowExpressionInterpreter.evaluateConstantRowExpression; import static com.facebook.presto.sql.planner.plan.Patterns.values; import static com.google.common.collect.ImmutableList.toImmutableList; @@ -60,7 +61,7 @@ public Optional calculate(ValuesNode node, StatsProvider { PlanNodeStatsEstimate.Builder statsBuilder = PlanNodeStatsEstimate.builder(); statsBuilder.setOutputRowCount(node.getRows().size()) - .setConfident(true); + .setConfidence(FACT); for (int variableId = 0; variableId < node.getOutputVariables().size(); ++variableId) { VariableReferenceExpression variable = node.getOutputVariables().get(variableId); diff --git a/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/PushPartialAggregationThroughExchange.java b/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/PushPartialAggregationThroughExchange.java index d687db6811451..54017dd2437a2 100644 --- a/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/PushPartialAggregationThroughExchange.java +++ b/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/PushPartialAggregationThroughExchange.java @@ -56,6 +56,8 @@ import static com.facebook.presto.spi.plan.AggregationNode.Step.PARTIAL; import static com.facebook.presto.spi.plan.AggregationNode.Step.SINGLE; import static com.facebook.presto.spi.plan.ProjectNode.Locality.LOCAL; +import static com.facebook.presto.spi.statistics.SourceInfo.ConfidenceLevel; +import static com.facebook.presto.spi.statistics.SourceInfo.ConfidenceLevel.LOW; import static com.facebook.presto.sql.analyzer.FeaturesConfig.PartialAggregationStrategy.AUTOMATIC; import static com.facebook.presto.sql.analyzer.FeaturesConfig.PartialAggregationStrategy.NEVER; import static com.facebook.presto.sql.planner.PlannerUtils.containsSystemTableScan; @@ -337,11 +339,11 @@ private boolean partialAggregationNotUseful(AggregationNode aggregationNode, Exc double inputSize = exchangeStats.getOutputSizeInBytes(exchangeNode); double outputSize = aggregationStats.getOutputSizeInBytes(aggregationNode); PartialAggregationStatsEstimate partialAggregationStatsEstimate = aggregationStats.getPartialAggregationStatsEstimate(); - boolean isConfident = exchangeStats.isConfident(); + ConfidenceLevel confidenceLevel = exchangeStats.confidenceLevel(); // keep old behavior of skipping partial aggregation only for single-key aggregations boolean numberOfKeyCheck = usePartialAggregationHistory(context.getSession()) || numAggregationKeys == 1; if (!isUnknown(partialAggregationStatsEstimate) && usePartialAggregationHistory(context.getSession())) { - isConfident = aggregationStats.isConfident(); + confidenceLevel = aggregationStats.confidenceLevel(); // use rows instead of bytes when use_partial_aggregation_history flag is on inputSize = partialAggregationStatsEstimate.getInputRowCount(); outputSize = partialAggregationStatsEstimate.getOutputRowCount(); @@ -349,7 +351,7 @@ private boolean partialAggregationNotUseful(AggregationNode aggregationNode, Exc double byteReductionThreshold = getPartialAggregationByteReductionThreshold(context.getSession()); // calling this function means we are using a cost-based strategy for this optimization - return numberOfKeyCheck && isConfident && outputSize > inputSize * byteReductionThreshold; + return numberOfKeyCheck && confidenceLevel != LOW && outputSize > inputSize * byteReductionThreshold; } private static boolean isLambda(RowExpression rowExpression) diff --git a/presto-main/src/main/java/com/facebook/presto/sql/planner/optimizations/AggregationNodeUtils.java b/presto-main/src/main/java/com/facebook/presto/sql/planner/optimizations/AggregationNodeUtils.java index 0d4c2e5c24232..ca3b849e025fc 100644 --- a/presto-main/src/main/java/com/facebook/presto/sql/planner/optimizations/AggregationNodeUtils.java +++ b/presto-main/src/main/java/com/facebook/presto/sql/planner/optimizations/AggregationNodeUtils.java @@ -36,6 +36,7 @@ import java.util.stream.Collectors; import static com.facebook.presto.common.type.BigintType.BIGINT; +import static com.facebook.presto.spi.statistics.SourceInfo.ConfidenceLevel.LOW; import static com.google.common.collect.ImmutableList.toImmutableList; public class AggregationNodeUtils @@ -77,7 +78,7 @@ public static boolean isAllLowCardinalityGroupByKeys(AggregationNode aggregation List groupbyKeys = aggregationNode.getGroupingSets().getGroupingKeys().stream().collect(Collectors.toList()); StatsProvider statsProvider = new CachingStatsProvider(statsCalculator, session, types); PlanNodeStatsEstimate estimate = statsProvider.getStats(scanNode); - if (!estimate.isConfident()) { + if (estimate.confidenceLevel() == LOW) { // For safety, we assume they are low card if not confident // TODO(kaikalur) : maybe return low card only for partition keys if/when we can detect that return true; diff --git a/presto-main/src/test/java/com/facebook/presto/cost/PlanNodeStatsAssertion.java b/presto-main/src/test/java/com/facebook/presto/cost/PlanNodeStatsAssertion.java index 9e618177caf89..6a1d8af928ae8 100644 --- a/presto-main/src/test/java/com/facebook/presto/cost/PlanNodeStatsAssertion.java +++ b/presto-main/src/test/java/com/facebook/presto/cost/PlanNodeStatsAssertion.java @@ -21,6 +21,7 @@ import static com.facebook.presto.common.type.BigintType.BIGINT; import static com.facebook.presto.cost.EstimateAssertion.assertEstimateEquals; +import static com.facebook.presto.spi.statistics.SourceInfo.ConfidenceLevel; import static com.google.common.collect.Sets.union; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; @@ -51,9 +52,9 @@ public PlanNodeStatsAssertion totalSize(double expected) return this; } - public PlanNodeStatsAssertion confident(boolean expected) + public PlanNodeStatsAssertion confident(ConfidenceLevel expected) { - assertEquals(actual.isConfident(), expected); + assertEquals(actual.confidenceLevel(), expected); return this; } @@ -100,7 +101,7 @@ public PlanNodeStatsAssertion variablesWithKnownStats(VariableReferenceExpressio public PlanNodeStatsAssertion equalTo(PlanNodeStatsEstimate expected) { assertEstimateEquals(actual.getOutputRowCount(), expected.getOutputRowCount(), "outputRowCount mismatch"); - assertEquals(actual.isConfident(), expected.isConfident()); + assertEquals(actual.confidenceLevel(), expected.confidenceLevel()); for (VariableReferenceExpression variable : union(expected.getVariablesWithKnownStatistics(), actual.getVariablesWithKnownStatistics())) { assertVariableStatsEqual(variable, actual.getVariableStatistics(variable), expected.getVariableStatistics(variable)); diff --git a/presto-main/src/test/java/com/facebook/presto/cost/TestExchangeStatsRule.java b/presto-main/src/test/java/com/facebook/presto/cost/TestExchangeStatsRule.java index 41cec60d38774..333de357c7471 100644 --- a/presto-main/src/test/java/com/facebook/presto/cost/TestExchangeStatsRule.java +++ b/presto-main/src/test/java/com/facebook/presto/cost/TestExchangeStatsRule.java @@ -21,6 +21,8 @@ import java.util.Optional; import static com.facebook.presto.common.type.BigintType.BIGINT; +import static com.facebook.presto.spi.statistics.SourceInfo.ConfidenceLevel.FACT; +import static com.facebook.presto.spi.statistics.SourceInfo.ConfidenceLevel.LOW; import static java.util.Collections.emptyList; public class TestExchangeStatsRule @@ -135,14 +137,14 @@ public void testExchangeConfidence() .addSource(pb.values()))) .withSourceStats(0, PlanNodeStatsEstimate.builder() .setOutputRowCount(100) - .setConfident(true) + .setConfidence(FACT) .build()) .withSourceStats(1, PlanNodeStatsEstimate.builder() .setOutputRowCount(100) - .setConfident(true) + .setConfidence(FACT) .build()) .check(check -> check - .confident(true)); + .confident(FACT)); tester().assertStatsFor(pb -> pb .exchange(exchangeBuilder -> exchangeBuilder @@ -153,13 +155,13 @@ public void testExchangeConfidence() .addSource(pb.values()))) .withSourceStats(0, PlanNodeStatsEstimate.builder() .setOutputRowCount(100) - .setConfident(true) + .setConfidence(FACT) .build()) .withSourceStats(1, PlanNodeStatsEstimate.builder() .setOutputRowCount(100) - .setConfident(false) + .setConfidence(LOW) .build()) .check(check -> check - .confident(false)); + .confident(LOW)); } } diff --git a/presto-main/src/test/java/com/facebook/presto/cost/TestFragmentStatsProvider.java b/presto-main/src/test/java/com/facebook/presto/cost/TestFragmentStatsProvider.java index 63cc56f3cbff9..3c444e28bbe04 100644 --- a/presto-main/src/test/java/com/facebook/presto/cost/TestFragmentStatsProvider.java +++ b/presto-main/src/test/java/com/facebook/presto/cost/TestFragmentStatsProvider.java @@ -19,6 +19,7 @@ import com.google.common.collect.ImmutableMap; import org.testng.annotations.Test; +import static com.facebook.presto.spi.statistics.SourceInfo.ConfidenceLevel.FACT; import static java.lang.Double.NaN; import static org.testng.Assert.assertEquals; @@ -32,8 +33,8 @@ public void testFragmentStatsProvider() QueryId queryId2 = new QueryId("queryid2"); PlanFragmentId planFragmentId1 = new PlanFragmentId(1); PlanFragmentId planFragmentId2 = new PlanFragmentId(2); - PlanNodeStatsEstimate planNodeStatsEstimate1 = new PlanNodeStatsEstimate(NaN, 10, true, ImmutableMap.of(), JoinNodeStatsEstimate.unknown(), TableWriterNodeStatsEstimate.unknown(), PartialAggregationStatsEstimate.unknown()); - PlanNodeStatsEstimate planNodeStatsEstimate2 = new PlanNodeStatsEstimate(NaN, 100, true, ImmutableMap.of(), JoinNodeStatsEstimate.unknown(), TableWriterNodeStatsEstimate.unknown(), PartialAggregationStatsEstimate.unknown()); + PlanNodeStatsEstimate planNodeStatsEstimate1 = new PlanNodeStatsEstimate(NaN, 10, FACT, ImmutableMap.of(), JoinNodeStatsEstimate.unknown(), TableWriterNodeStatsEstimate.unknown(), PartialAggregationStatsEstimate.unknown()); + PlanNodeStatsEstimate planNodeStatsEstimate2 = new PlanNodeStatsEstimate(NaN, 100, FACT, ImmutableMap.of(), JoinNodeStatsEstimate.unknown(), TableWriterNodeStatsEstimate.unknown(), PartialAggregationStatsEstimate.unknown()); assertEquals(fragmentStatsProvider.getStats(queryId1, planFragmentId1), PlanNodeStatsEstimate.unknown()); diff --git a/presto-main/src/test/java/com/facebook/presto/cost/TestRemoteSourceStatsRule.java b/presto-main/src/test/java/com/facebook/presto/cost/TestRemoteSourceStatsRule.java index 275b501658498..9eaa14841efa4 100644 --- a/presto-main/src/test/java/com/facebook/presto/cost/TestRemoteSourceStatsRule.java +++ b/presto-main/src/test/java/com/facebook/presto/cost/TestRemoteSourceStatsRule.java @@ -22,6 +22,7 @@ import com.google.common.collect.ImmutableMap; import org.testng.annotations.Test; +import static com.facebook.presto.spi.statistics.SourceInfo.ConfidenceLevel.FACT; import static com.facebook.presto.testing.TestingSession.testSessionBuilder; import static java.lang.Double.NaN; @@ -37,8 +38,8 @@ public void testRemoteSourceStatsRule() LocalQueryRunner localQueryRunner = new LocalQueryRunner(session); StatsCalculatorTester tester = new StatsCalculatorTester(localQueryRunner); FragmentStatsProvider fragmentStatsProvider = localQueryRunner.getFragmentStatsProvider(); - fragmentStatsProvider.putStats(queryId, new PlanFragmentId(1), new PlanNodeStatsEstimate(NaN, 1000, true, ImmutableMap.of(), JoinNodeStatsEstimate.unknown(), TableWriterNodeStatsEstimate.unknown(), PartialAggregationStatsEstimate.unknown())); - fragmentStatsProvider.putStats(queryId, new PlanFragmentId(2), new PlanNodeStatsEstimate(NaN, 1000, true, ImmutableMap.of(), JoinNodeStatsEstimate.unknown(), TableWriterNodeStatsEstimate.unknown(), PartialAggregationStatsEstimate.unknown())); + fragmentStatsProvider.putStats(queryId, new PlanFragmentId(1), new PlanNodeStatsEstimate(NaN, 1000, FACT, ImmutableMap.of(), JoinNodeStatsEstimate.unknown(), TableWriterNodeStatsEstimate.unknown(), PartialAggregationStatsEstimate.unknown())); + fragmentStatsProvider.putStats(queryId, new PlanFragmentId(2), new PlanNodeStatsEstimate(NaN, 1000, FACT, ImmutableMap.of(), JoinNodeStatsEstimate.unknown(), TableWriterNodeStatsEstimate.unknown(), PartialAggregationStatsEstimate.unknown())); tester.assertStatsFor(planBuilder -> planBuilder.remoteSource(ImmutableList.of(new PlanFragmentId(1), new PlanFragmentId(2)))) .check(check -> check.totalSize(2000) .outputRowsCountUnknown()); diff --git a/presto-main/src/test/java/com/facebook/presto/cost/TestValuesNodeStats.java b/presto-main/src/test/java/com/facebook/presto/cost/TestValuesNodeStats.java index b986d9d8c6a80..db9166d0f8056 100644 --- a/presto-main/src/test/java/com/facebook/presto/cost/TestValuesNodeStats.java +++ b/presto-main/src/test/java/com/facebook/presto/cost/TestValuesNodeStats.java @@ -25,6 +25,7 @@ import static com.facebook.presto.common.type.UnknownType.UNKNOWN; import static com.facebook.presto.common.type.VarcharType.VARCHAR; import static com.facebook.presto.common.type.VarcharType.createVarcharType; +import static com.facebook.presto.spi.statistics.SourceInfo.ConfidenceLevel.FACT; import static com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder.constantExpressions; import static com.facebook.presto.sql.relational.Expressions.call; import static com.facebook.presto.sql.relational.Expressions.constant; @@ -49,7 +50,7 @@ public void testStatsForValuesNode() .check(outputStats -> outputStats.equalTo( PlanNodeStatsEstimate.builder() .setOutputRowCount(3) - .setConfident(true) + .setConfidence(FACT) .addVariableStatistics( new VariableReferenceExpression(Optional.empty(), "a", BIGINT), VariableStatsEstimate.builder() @@ -79,7 +80,7 @@ public void testStatsForValuesNode() .check(outputStats -> outputStats.equalTo( PlanNodeStatsEstimate.builder() .setOutputRowCount(4) - .setConfident(true) + .setConfidence(FACT) .addVariableStatistics( new VariableReferenceExpression(Optional.empty(), "v", createVarcharType(30)), VariableStatsEstimate.builder() @@ -96,7 +97,7 @@ public void testStatsForValuesNodeWithJustNulls() FunctionResolution resolution = new FunctionResolution(tester().getMetadata().getFunctionAndTypeManager().getFunctionAndTypeResolver()); PlanNodeStatsEstimate bigintNullAStats = PlanNodeStatsEstimate.builder() .setOutputRowCount(1) - .setConfident(true) + .setConfidence(FACT) .addVariableStatistics(new VariableReferenceExpression(Optional.empty(), "a", BIGINT), VariableStatsEstimate.zero()) .build(); @@ -115,7 +116,7 @@ public void testStatsForValuesNodeWithJustNulls() PlanNodeStatsEstimate unknownNullAStats = PlanNodeStatsEstimate.builder() .setOutputRowCount(1) - .setConfident(true) + .setConfidence(FACT) .addVariableStatistics(new VariableReferenceExpression(Optional.empty(), "a", UNKNOWN), VariableStatsEstimate.zero()) .build(); @@ -136,7 +137,7 @@ public void testStatsForEmptyValues() .check(outputStats -> outputStats.equalTo( PlanNodeStatsEstimate.builder() .setOutputRowCount(0) - .setConfident(true) + .setConfidence(FACT) .addVariableStatistics(new VariableReferenceExpression(Optional.empty(), "a", BIGINT), VariableStatsEstimate.zero()) .build())); } diff --git a/presto-main/src/test/java/com/facebook/presto/operator/scalar/queryplan/TestJsonPrestoQueryPlanFunctionUtils.java b/presto-main/src/test/java/com/facebook/presto/operator/scalar/queryplan/TestJsonPrestoQueryPlanFunctionUtils.java index 0c77a04d046e0..cc2dc220a903f 100644 --- a/presto-main/src/test/java/com/facebook/presto/operator/scalar/queryplan/TestJsonPrestoQueryPlanFunctionUtils.java +++ b/presto-main/src/test/java/com/facebook/presto/operator/scalar/queryplan/TestJsonPrestoQueryPlanFunctionUtils.java @@ -39,7 +39,7 @@ private TestJsonPrestoQueryPlanFunctionUtils() {} " \"estimates\" : [ {\n" + " \"outputRowCount\" : 0.0,\n" + " \"totalSize\" : \"NaN\",\n" + - " \"confident\" : false,\n" + + " \"confident\" : \"LOW\",\n" + " \"variableStatistics\" : {\n" + " \"a\" : {\n" + " \"lowValue\" : \"NaN\",\n" + @@ -111,7 +111,7 @@ private TestJsonPrestoQueryPlanFunctionUtils() {} " \"estimates\" : [ {\n" + " \"outputRowCount\" : 0.0,\n" + " \"totalSize\" : \"NaN\",\n" + - " \"confident\" : true,\n" + + " \"confident\" : \"HIGH\",\n" + " \"variableStatistics\" : {\n" + " \"$hashvalue_21\" : {\n" + " \"lowValue\" : \"NaN\",\n" + @@ -154,7 +154,7 @@ private TestJsonPrestoQueryPlanFunctionUtils() {} " \"estimates\" : [ {\n" + " \"outputRowCount\" : 0.0,\n" + " \"totalSize\" : \"NaN\",\n" + - " \"confident\" : false,\n" + + " \"confident\" : \"LOW\",\n" + " \"variableStatistics\" : {\n" + " \"a\" : {\n" + " \"lowValue\" : \"NaN\",\n" + @@ -205,7 +205,7 @@ private TestJsonPrestoQueryPlanFunctionUtils() {} " \"estimates\" : [ {\n" + " \"outputRowCount\" : 0.0,\n" + " \"totalSize\" : 0.0,\n" + - " \"confident\" : true,\n" + + " \"confident\" : \"HIGH\",\n" + " \"variableStatistics\" : {\n" + " \"a\" : {\n" + " \"lowValue\" : \"NaN\",\n" + @@ -238,7 +238,7 @@ private TestJsonPrestoQueryPlanFunctionUtils() {} " }, {\n" + " \"outputRowCount\" : 0.0,\n" + " \"totalSize\" : \"NaN\",\n" + - " \"confident\" : true,\n" + + " \"confident\" : \"HIGH\",\n" + " \"variableStatistics\" : {\n" + " \"$hashvalue_20\" : {\n" + " \"lowValue\" : \"NaN\",\n" + @@ -289,7 +289,7 @@ private TestJsonPrestoQueryPlanFunctionUtils() {} " \"estimates\" : [ {\n" + " \"outputRowCount\" : 0.0,\n" + " \"totalSize\" : 0.0,\n" + - " \"confident\" : true,\n" + + " \"confident\" : \"HIGH\",\n" + " \"variableStatistics\" : {\n" + " \"a_0\" : {\n" + " \"lowValue\" : \"NaN\",\n" + @@ -322,7 +322,7 @@ private TestJsonPrestoQueryPlanFunctionUtils() {} " }, {\n" + " \"outputRowCount\" : 0.0,\n" + " \"totalSize\" : \"NaN\",\n" + - " \"confident\" : true,\n" + + " \"confident\" : \"HIGH\",\n" + " \"variableStatistics\" : {\n" + " \"$hashvalue_23\" : {\n" + " \"lowValue\" : \"NaN\",\n" + diff --git a/presto-main/src/test/java/com/facebook/presto/sql/planner/iterative/rule/TestPushPartialAggregationThroughExchange.java b/presto-main/src/test/java/com/facebook/presto/sql/planner/iterative/rule/TestPushPartialAggregationThroughExchange.java index f07412e9f4bae..0a6f8b9e58fd0 100644 --- a/presto-main/src/test/java/com/facebook/presto/sql/planner/iterative/rule/TestPushPartialAggregationThroughExchange.java +++ b/presto-main/src/test/java/com/facebook/presto/sql/planner/iterative/rule/TestPushPartialAggregationThroughExchange.java @@ -30,6 +30,8 @@ import static com.facebook.presto.common.type.DoubleType.DOUBLE; import static com.facebook.presto.spi.plan.AggregationNode.Step.PARTIAL; import static com.facebook.presto.spi.plan.AggregationNode.Step.SINGLE; +import static com.facebook.presto.spi.statistics.SourceInfo.ConfidenceLevel.FACT; +import static com.facebook.presto.spi.statistics.SourceInfo.ConfidenceLevel.LOW; import static com.facebook.presto.sql.planner.assertions.PlanMatchPattern.aggregation; import static com.facebook.presto.sql.planner.assertions.PlanMatchPattern.exchange; import static com.facebook.presto.sql.planner.assertions.PlanMatchPattern.functionCall; @@ -106,7 +108,7 @@ public void testNoPartialAggregationWhenReductionBelowThreshold() .overrideStats("values", PlanNodeStatsEstimate.builder() .setOutputRowCount(1000) .addVariableStatistics(variable("b", DOUBLE), new VariableStatsEstimate(0, 100, 0, 8, 800)) - .setConfident(true) + .setConfidence(FACT) .build()) .doesNotFire(); } @@ -120,7 +122,7 @@ public void testNoPartialAggregationWhenReductionBelowThresholdUsingPartialAggre .on(p -> constructAggregation(p)) .overrideStats("aggregation", PlanNodeStatsEstimate.builder() .addVariableStatistics(variable("b", DOUBLE), new VariableStatsEstimate(0, 100, 0, 8, 800)) - .setConfident(true) + .setConfidence(FACT) .setPartialAggregationStatsEstimate(new PartialAggregationStatsEstimate(1000, 800, 10, 10)) .build()) .doesNotFire(); @@ -136,7 +138,7 @@ public void testNoPartialAggregationWhenReductionAboveThresholdUsingPartialAggre .on(p -> constructAggregation(p)) .overrideStats("aggregation", PlanNodeStatsEstimate.builder() .addVariableStatistics(variable("b", DOUBLE), new VariableStatsEstimate(0, 100, 0, 8, 800)) - .setConfident(true) + .setConfidence(FACT) .setPartialAggregationStatsEstimate(new PartialAggregationStatsEstimate(1000, 300, 10, 10)) .build()) .doesNotFire(); @@ -151,7 +153,7 @@ public void testNoPartialAggregationWhenRowReductionBelowThreshold() .on(p -> constructAggregation(p)) .overrideStats("aggregation", PlanNodeStatsEstimate.builder() .addVariableStatistics(variable("b", DOUBLE), new VariableStatsEstimate(0, 100, 0, 8, 800)) - .setConfident(true) + .setConfidence(FACT) .setPartialAggregationStatsEstimate(new PartialAggregationStatsEstimate(0, 300, 10, 8)) .build()) .doesNotFire(); @@ -166,7 +168,7 @@ public void testPartialAggregationWhenRowReductionAboveThreshold() .on(p -> constructAggregation(p)) .overrideStats("aggregation", PlanNodeStatsEstimate.builder() .addVariableStatistics(variable("b", DOUBLE), new VariableStatsEstimate(0, 100, 0, 8, 800)) - .setConfident(true) + .setConfidence(FACT) .setPartialAggregationStatsEstimate(new PartialAggregationStatsEstimate(0, 300, 10, 1)) .build()) .matches(aggregation(ImmutableMap.of("sum", functionCall("sum", ImmutableList.of("sum0"))), @@ -197,7 +199,7 @@ public void testPartialAggregationEnabledWhenNotConfident() .overrideStats("values", PlanNodeStatsEstimate.builder() .setOutputRowCount(1000) .addVariableStatistics(variable("b", DOUBLE), new VariableStatsEstimate(0, 100, 0, 8, 800)) - .setConfident(false) + .setConfidence(LOW) .build()) .matches(exchange( project( diff --git a/presto-main/src/test/java/com/facebook/presto/sql/planner/iterative/rule/TestTransformDistinctInnerJoinToLeftEarlyOutJoin.java b/presto-main/src/test/java/com/facebook/presto/sql/planner/iterative/rule/TestTransformDistinctInnerJoinToLeftEarlyOutJoin.java index b938d0478a0b0..7ddd5ba5544c6 100644 --- a/presto-main/src/test/java/com/facebook/presto/sql/planner/iterative/rule/TestTransformDistinctInnerJoinToLeftEarlyOutJoin.java +++ b/presto-main/src/test/java/com/facebook/presto/sql/planner/iterative/rule/TestTransformDistinctInnerJoinToLeftEarlyOutJoin.java @@ -38,6 +38,7 @@ import static com.facebook.presto.common.type.BigintType.BIGINT; import static com.facebook.presto.spi.plan.AggregationNode.Step.SINGLE; import static com.facebook.presto.spi.plan.JoinType.INNER; +import static com.facebook.presto.spi.statistics.SourceInfo.ConfidenceLevel.FACT; import static com.facebook.presto.sql.analyzer.FeaturesConfig.JoinReorderingStrategy.AUTOMATIC; import static com.facebook.presto.sql.planner.assertions.PlanMatchPattern.aggregation; import static com.facebook.presto.sql.planner.assertions.PlanMatchPattern.assignUniqueId; @@ -83,12 +84,12 @@ public void testAggregationPushedDown() }) .overrideStats("valuesA", PlanNodeStatsEstimate.builder() .setOutputRowCount(1000) - .setConfident(true) + .setConfidence(FACT) .addVariableStatistics(variable("a", BIGINT), new VariableStatsEstimate(0, 1000, 0, 8, 100)) .build()) .overrideStats("valuesB", PlanNodeStatsEstimate.builder() .setOutputRowCount(100) - .setConfident(true) + .setConfidence(FACT) .addVariableStatistics(variable("b", BIGINT), new VariableStatsEstimate(0, 1000, 0, 8, 10)) .build()) .matches(aggregation(ImmutableMap.of(), @@ -124,12 +125,12 @@ public void testAggregationPushedDown() }) .overrideStats("valuesA", PlanNodeStatsEstimate.builder() .setOutputRowCount(1000) - .setConfident(true) + .setConfidence(FACT) .addVariableStatistics(variable("a", BIGINT), new VariableStatsEstimate(0, 1000, 0, 8, 100)) .build()) .overrideStats("valuesB", PlanNodeStatsEstimate.builder() .setOutputRowCount(100) - .setConfident(true) + .setConfidence(FACT) .addVariableStatistics(variable("b", BIGINT), new VariableStatsEstimate(0, 1000, 0, 8, 10)) .addVariableStatistics(variable("c", BIGINT), new VariableStatsEstimate(0, 1000, 0, 8, 10)) .build()) diff --git a/presto-main/src/test/java/com/facebook/presto/sql/planner/iterative/rule/TestTransformDistinctInnerJoinToRightEarlyOutJoin.java b/presto-main/src/test/java/com/facebook/presto/sql/planner/iterative/rule/TestTransformDistinctInnerJoinToRightEarlyOutJoin.java index 9c8b7f8a736b9..e67ec3af92824 100644 --- a/presto-main/src/test/java/com/facebook/presto/sql/planner/iterative/rule/TestTransformDistinctInnerJoinToRightEarlyOutJoin.java +++ b/presto-main/src/test/java/com/facebook/presto/sql/planner/iterative/rule/TestTransformDistinctInnerJoinToRightEarlyOutJoin.java @@ -37,6 +37,7 @@ import static com.facebook.presto.common.type.BigintType.BIGINT; import static com.facebook.presto.spi.plan.AggregationNode.Step.SINGLE; import static com.facebook.presto.spi.plan.JoinType.INNER; +import static com.facebook.presto.spi.statistics.SourceInfo.ConfidenceLevel.FACT; import static com.facebook.presto.sql.analyzer.FeaturesConfig.JoinReorderingStrategy.AUTOMATIC; import static com.facebook.presto.sql.planner.assertions.PlanMatchPattern.aggregation; import static com.facebook.presto.sql.planner.assertions.PlanMatchPattern.assignUniqueId; @@ -79,12 +80,12 @@ public void testAggregationPushedDown() }) .overrideStats("valuesA", PlanNodeStatsEstimate.builder() .setOutputRowCount(1000) - .setConfident(true) + .setConfidence(FACT) .addVariableStatistics(variable("a", BIGINT), new VariableStatsEstimate(0, 1000, 0, 8, 100)) .build()) .overrideStats("valuesB", PlanNodeStatsEstimate.builder() .setOutputRowCount(100) - .setConfident(true) + .setConfidence(FACT) .addVariableStatistics(variable("b", BIGINT), new VariableStatsEstimate(0, 1000, 0, 8, 10)) .build()) .matches(aggregation(ImmutableMap.of(), diff --git a/presto-spark-base/src/test/java/com/facebook/presto/spark/planner/TestPrestoSparkStatsCalculator.java b/presto-spark-base/src/test/java/com/facebook/presto/spark/planner/TestPrestoSparkStatsCalculator.java index 11f6e9df1738e..044706bda7e1a 100644 --- a/presto-spark-base/src/test/java/com/facebook/presto/spark/planner/TestPrestoSparkStatsCalculator.java +++ b/presto-spark-base/src/test/java/com/facebook/presto/spark/planner/TestPrestoSparkStatsCalculator.java @@ -53,6 +53,7 @@ import static com.facebook.presto.SystemSessionProperties.USE_HISTORY_BASED_PLAN_STATISTICS; import static com.facebook.presto.common.plan.PlanCanonicalizationStrategy.IGNORE_SAFE_CONSTANTS; +import static com.facebook.presto.spi.statistics.SourceInfo.ConfidenceLevel.HIGH; import static com.facebook.presto.testing.TestingSession.testSessionBuilder; import static java.lang.Double.NaN; @@ -113,7 +114,7 @@ public void resetCaches() @Test public void testUsesHboStatsWhenMatchRuntime() { - fragmentStatsProvider.putStats(TEST_QUERY_ID, new PlanFragmentId(1), new PlanNodeStatsEstimate(NaN, 1000, true, ImmutableMap.of(), JoinNodeStatsEstimate.unknown(), TableWriterNodeStatsEstimate.unknown(), PartialAggregationStatsEstimate.unknown())); + fragmentStatsProvider.putStats(TEST_QUERY_ID, new PlanFragmentId(1), new PlanNodeStatsEstimate(NaN, 1000, HIGH, ImmutableMap.of(), JoinNodeStatsEstimate.unknown(), TableWriterNodeStatsEstimate.unknown(), PartialAggregationStatsEstimate.unknown())); PlanBuilder planBuilder = new PlanBuilder(session, new PlanNodeIdAllocator(), metadata); PlanNode statsEquivalentRemoteSource = planBuilder .registerVariable(planBuilder.variable("c1")) @@ -140,7 +141,7 @@ public void testUsesHboStatsWhenMatchRuntime() @Test public void testUsesRuntimeStatsWhenNoHboStats() { - fragmentStatsProvider.putStats(TEST_QUERY_ID, new PlanFragmentId(1), new PlanNodeStatsEstimate(NaN, 1000, true, ImmutableMap.of(), JoinNodeStatsEstimate.unknown(), TableWriterNodeStatsEstimate.unknown(), PartialAggregationStatsEstimate.unknown())); + fragmentStatsProvider.putStats(TEST_QUERY_ID, new PlanFragmentId(1), new PlanNodeStatsEstimate(NaN, 1000, HIGH, ImmutableMap.of(), JoinNodeStatsEstimate.unknown(), TableWriterNodeStatsEstimate.unknown(), PartialAggregationStatsEstimate.unknown())); tester.assertStatsFor(pb -> pb.remoteSource(ImmutableList.of(new PlanFragmentId(1)))) .check(check -> check.totalSize(1000) .outputRowsCountUnknown()); @@ -163,7 +164,7 @@ public void testUsesRuntimeStatsWhenHboDisabled() StatsCalculatorTester tester = new StatsCalculatorTester( localQueryRunner, prestoSparkStatsCalculator); - fragmentStatsProvider.putStats(TEST_QUERY_ID, new PlanFragmentId(1), new PlanNodeStatsEstimate(NaN, 1000, true, ImmutableMap.of(), JoinNodeStatsEstimate.unknown(), TableWriterNodeStatsEstimate.unknown(), PartialAggregationStatsEstimate.unknown())); + fragmentStatsProvider.putStats(TEST_QUERY_ID, new PlanFragmentId(1), new PlanNodeStatsEstimate(NaN, 1000, HIGH, ImmutableMap.of(), JoinNodeStatsEstimate.unknown(), TableWriterNodeStatsEstimate.unknown(), PartialAggregationStatsEstimate.unknown())); PlanBuilder planBuilder = new PlanBuilder(session, new PlanNodeIdAllocator(), localQueryRunner.getMetadata()); PlanNode statsEquivalentRemoteSource = planBuilder @@ -190,7 +191,7 @@ public void testUsesRuntimeStatsWhenHboDisabled() @Test public void testUsesRuntimeStatsWhenDiffersFromHbo() { - fragmentStatsProvider.putStats(TEST_QUERY_ID, new PlanFragmentId(1), new PlanNodeStatsEstimate(NaN, 1000, true, ImmutableMap.of(), JoinNodeStatsEstimate.unknown(), TableWriterNodeStatsEstimate.unknown(), PartialAggregationStatsEstimate.unknown())); + fragmentStatsProvider.putStats(TEST_QUERY_ID, new PlanFragmentId(1), new PlanNodeStatsEstimate(NaN, 1000, HIGH, ImmutableMap.of(), JoinNodeStatsEstimate.unknown(), TableWriterNodeStatsEstimate.unknown(), PartialAggregationStatsEstimate.unknown())); PlanBuilder planBuilder = new PlanBuilder(session, new PlanNodeIdAllocator(), metadata); PlanNode statsEquivalentRemoteSource = planBuilder diff --git a/presto-spi/src/main/java/com/facebook/presto/spi/statistics/CostBasedSourceInfo.java b/presto-spi/src/main/java/com/facebook/presto/spi/statistics/CostBasedSourceInfo.java index 49410b0215d59..fd2fdd2a503dd 100644 --- a/presto-spi/src/main/java/com/facebook/presto/spi/statistics/CostBasedSourceInfo.java +++ b/presto-spi/src/main/java/com/facebook/presto/spi/statistics/CostBasedSourceInfo.java @@ -19,11 +19,11 @@ public class CostBasedSourceInfo extends SourceInfo { - private boolean confident; + private ConfidenceLevel confidenceLevel; - public CostBasedSourceInfo(boolean confident) + public CostBasedSourceInfo(ConfidenceLevel confidenceLevel) { - this.confident = confident; + this.confidenceLevel = confidenceLevel; } @Override @@ -45,9 +45,9 @@ public String toString() } @Override - public boolean isConfident() + public ConfidenceLevel confidenceLevel() { - return confident; + return confidenceLevel; } @Override diff --git a/presto-spi/src/main/java/com/facebook/presto/spi/statistics/HistoryBasedSourceInfo.java b/presto-spi/src/main/java/com/facebook/presto/spi/statistics/HistoryBasedSourceInfo.java index d66cabfb1b3dc..90ff6957e45ee 100644 --- a/presto-spi/src/main/java/com/facebook/presto/spi/statistics/HistoryBasedSourceInfo.java +++ b/presto-spi/src/main/java/com/facebook/presto/spi/statistics/HistoryBasedSourceInfo.java @@ -17,6 +17,7 @@ import java.util.Objects; import java.util.Optional; +import static com.facebook.presto.spi.statistics.SourceInfo.ConfidenceLevel.HIGH; import static java.util.Objects.requireNonNull; /** @@ -71,9 +72,9 @@ public int hashCode() } @Override - public boolean isConfident() + public ConfidenceLevel confidenceLevel() { - return true; + return HIGH; } @Override diff --git a/presto-spi/src/main/java/com/facebook/presto/spi/statistics/RuntimeSourceInfo.java b/presto-spi/src/main/java/com/facebook/presto/spi/statistics/RuntimeSourceInfo.java index ce4761039411d..4df7c54c7bd46 100644 --- a/presto-spi/src/main/java/com/facebook/presto/spi/statistics/RuntimeSourceInfo.java +++ b/presto-spi/src/main/java/com/facebook/presto/spi/statistics/RuntimeSourceInfo.java @@ -13,6 +13,8 @@ */ package com.facebook.presto.spi.statistics; +import static com.facebook.presto.spi.statistics.SourceInfo.ConfidenceLevel.HIGH; + /** * Describes plan statistics which are derived at runtime. */ @@ -40,9 +42,9 @@ public String toString() } @Override - public boolean isConfident() + public ConfidenceLevel confidenceLevel() { - return true; + return HIGH; } @Override diff --git a/presto-spi/src/main/java/com/facebook/presto/spi/statistics/SourceInfo.java b/presto-spi/src/main/java/com/facebook/presto/spi/statistics/SourceInfo.java index 8c13972ab226d..f4f0d9cb72561 100644 --- a/presto-spi/src/main/java/com/facebook/presto/spi/statistics/SourceInfo.java +++ b/presto-spi/src/main/java/com/facebook/presto/spi/statistics/SourceInfo.java @@ -19,7 +19,12 @@ */ public abstract class SourceInfo { - public abstract boolean isConfident(); + public enum ConfidenceLevel + { + LOW, HIGH, FACT; + } + + public abstract ConfidenceLevel confidenceLevel(); /** * Whether to estimate size of plan output using variable statistics.