use of io.prestosql.spi.plan.TopNNode in project hetu-core by openlookeng.
the class TopNMatcher method detailMatches.
@Override
public MatchResult detailMatches(PlanNode node, StatsProvider stats, Session session, Metadata metadata, SymbolAliases symbolAliases) {
checkState(shapeMatches(node), "Plan testing framework error: shapeMatches returned false in detailMatches in %s", this.getClass().getName());
TopNNode topNNode = (TopNNode) node;
if (topNNode.getCount() != count) {
return NO_MATCH;
}
if (!orderingSchemeMatches(orderBy, topNNode.getOrderingScheme(), symbolAliases)) {
return NO_MATCH;
}
if (topNNode.getStep() != step) {
return NO_MATCH;
}
return match();
}
use of io.prestosql.spi.plan.TopNNode in project hetu-core by openlookeng.
the class TestEffectivePredicateExtractor method testTopN.
@Test
public void testTopN() {
PlanNode node = new TopNNode(newId(), filter(baseTableScan, and(equals(AE, BE), equals(BE, CE), lessThan(CE, bigintLiteral(10)))), 1, new OrderingScheme(ImmutableList.of(A), ImmutableMap.of(A, SortOrder.ASC_NULLS_LAST)), TopNNode.Step.PARTIAL);
Expression effectivePredicate = effectivePredicateExtractor.extract(SESSION, node, TypeProvider.empty(), typeAnalyzer);
// Pass through
assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjunctsSet(equals(AE, BE), equals(BE, CE), lessThan(CE, bigintLiteral(10))));
}
use of io.prestosql.spi.plan.TopNNode in project hetu-core by openlookeng.
the class TopNStatsRule method doCalculate.
@Override
protected Optional<PlanNodeStatsEstimate> doCalculate(TopNNode node, StatsProvider statsProvider, Lookup lookup, Session session, TypeProvider types) {
PlanNodeStatsEstimate sourceStats = statsProvider.getStats(node.getSource());
double rowCount = sourceStats.getOutputRowCount();
if (rowCount <= node.getCount()) {
return Optional.of(sourceStats);
}
long limitCount = node.getCount();
PlanNodeStatsEstimate resultStats = PlanNodeStatsEstimate.buildFrom(sourceStats).setOutputRowCount(limitCount).build();
if (limitCount == 0) {
return Optional.of(resultStats);
}
// augment null fraction estimation for first ORDER BY symbol
// Assuming not empty list
Symbol firstOrderSymbol = node.getOrderingScheme().getOrderBy().get(0);
SortOrder sortOrder = node.getOrderingScheme().getOrdering(firstOrderSymbol);
resultStats = resultStats.mapSymbolColumnStatistics(firstOrderSymbol, symbolStats -> {
SymbolStatsEstimate.Builder newStats = SymbolStatsEstimate.buildFrom(symbolStats);
double nullCount = rowCount * symbolStats.getNullsFraction();
if (sortOrder.isNullsFirst()) {
if (nullCount > limitCount) {
newStats.setNullsFraction(1.0);
} else {
newStats.setNullsFraction(nullCount / limitCount);
}
} else {
double nonNullCount = (rowCount - nullCount);
if (nonNullCount > limitCount) {
newStats.setNullsFraction(0.0);
} else {
newStats.setNullsFraction((limitCount - nonNullCount) / limitCount);
}
}
return newStats.build();
});
// TopN actually limits (or when there was no row count estimated for source)
return Optional.of(resultStats);
}
use of io.prestosql.spi.plan.TopNNode in project hetu-core by openlookeng.
the class PushTopNThroughProject method apply.
@Override
public Result apply(TopNNode parent, Captures captures, Context context) {
ProjectNode projectNode = captures.get(PROJECT_CHILD);
// do not push topN between projection and filter(table scan) so that they can be merged into a PageProcessor
PlanNode projectSource = context.getLookup().resolve(projectNode.getSource());
if (projectSource instanceof FilterNode) {
PlanNode filterSource = context.getLookup().resolve(((FilterNode) projectSource).getSource());
if (filterSource instanceof TableScanNode) {
return Result.empty();
}
}
Optional<SymbolMapper> symbolMapper = symbolMapper(parent.getOrderingScheme().getOrderBy(), projectNode.getAssignments());
if (!symbolMapper.isPresent()) {
return Result.empty();
}
TopNNode mappedTopN = symbolMapper.get().map(parent, projectNode.getSource(), context.getIdAllocator().getNextId());
return Result.ofPlanNode(projectNode.replaceChildren(ImmutableList.of(mappedTopN)));
}
use of io.prestosql.spi.plan.TopNNode in project hetu-core by openlookeng.
the class MergeLimitOverProjectWithSort method apply.
@Override
public Result apply(LimitNode parent, Captures captures, Context context) {
ProjectNode project = captures.get(PROJECT);
SortNode sort = captures.get(SORT);
return Result.ofPlanNode(project.replaceChildren(ImmutableList.of(new TopNNode(parent.getId(), sort.getSource(), parent.getCount(), sort.getOrderingScheme(), parent.isPartial() ? PARTIAL : SINGLE))));
}
Aggregations