use of io.prestosql.sql.planner.plan.SemiJoinNode in project hetu-core by openlookeng.
the class DynamicFilterService method registerTasks.
/**
* Registering tasks for global dynamic filters
*
* @param node the Join node from the logical plan
* @param taskIds set of task Ids
* @param workers set of workers
* @param stateMachine the state machine
*/
public void registerTasks(PlanNode node, Set<TaskId> taskIds, Set<InternalNode> workers, StageStateMachine stateMachine) {
if (taskIds.isEmpty() || stateStoreProvider.getStateStore() == null) {
return;
}
if (node instanceof JoinNode) {
JoinNode joinNode = (JoinNode) node;
List<JoinNode.EquiJoinClause> criterias = joinNode.getCriteria();
if (!criterias.isEmpty()) {
registerTasksHelper(node, criterias.get(0).getRight(), joinNode.getDynamicFilters(), taskIds, workers, stateMachine);
}
} else if (node instanceof SemiJoinNode) {
SemiJoinNode semiJoinNode = (SemiJoinNode) node;
if (semiJoinNode.getDynamicFilterId().isPresent()) {
registerTasksHelper(node, semiJoinNode.getFilteringSourceJoinSymbol(), Collections.singletonMap(semiJoinNode.getDynamicFilterId().get(), semiJoinNode.getFilteringSourceJoinSymbol()), taskIds, workers, stateMachine);
}
}
}
use of io.prestosql.sql.planner.plan.SemiJoinNode in project hetu-core by openlookeng.
the class TestEffectivePredicateExtractor method testSemiJoin.
@Test
public void testSemiJoin() {
PlanNode node = new SemiJoinNode(newId(), filter(baseTableScan, and(greaterThan(AE, bigintLiteral(10)), lessThan(AE, bigintLiteral(100)))), filter(baseTableScan, greaterThan(AE, bigintLiteral(5))), A, B, C, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty());
Expression effectivePredicate = effectivePredicateExtractor.extract(SESSION, node, TypeProvider.empty(), typeAnalyzer);
// Currently, only pull predicates through the source plan
assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(and(greaterThan(AE, bigintLiteral(10)), lessThan(AE, bigintLiteral(100)))));
}
use of io.prestosql.sql.planner.plan.SemiJoinNode in project hetu-core by openlookeng.
the class SimpleFilterProjectSemiJoinStatsRule method calculate.
private Optional<PlanNodeStatsEstimate> calculate(FilterNode filterNode, SemiJoinNode semiJoinNode, StatsProvider statsProvider, Session session, TypeProvider types) {
PlanNodeStatsEstimate sourceStats = statsProvider.getStats(semiJoinNode.getSource());
PlanNodeStatsEstimate filteringSourceStats = statsProvider.getStats(semiJoinNode.getFilteringSource());
Symbol filteringSourceJoinSymbol = semiJoinNode.getFilteringSourceJoinSymbol();
Symbol sourceJoinSymbol = semiJoinNode.getSourceJoinSymbol();
Optional<SemiJoinOutputFilter> semiJoinOutputFilter;
if (isExpression(filterNode.getPredicate())) {
semiJoinOutputFilter = extractSemiJoinOutputFilter(castToExpression(filterNode.getPredicate()), semiJoinNode.getSemiJoinOutput());
} else {
VariableReferenceExpression semiJoinOutput = new VariableReferenceExpression(semiJoinNode.getSemiJoinOutput().getName(), types.get(semiJoinNode.getSemiJoinOutput()));
semiJoinOutputFilter = extractSemiJoinOutputFilter(filterNode.getPredicate(), semiJoinOutput);
}
if (!semiJoinOutputFilter.isPresent()) {
return Optional.empty();
}
PlanNodeStatsEstimate semiJoinStats;
if (semiJoinOutputFilter.get().isNegated()) {
semiJoinStats = computeAntiJoin(sourceStats, filteringSourceStats, sourceJoinSymbol, filteringSourceJoinSymbol);
} else {
semiJoinStats = computeSemiJoin(sourceStats, filteringSourceStats, sourceJoinSymbol, filteringSourceJoinSymbol);
}
if (semiJoinStats.isOutputRowCountUnknown()) {
return Optional.of(PlanNodeStatsEstimate.unknown());
}
// apply remaining predicate
PlanNodeStatsEstimate filteredStats;
if (isExpression(filterNode.getPredicate())) {
filteredStats = filterStatsCalculator.filterStats(semiJoinStats, castToExpression(semiJoinOutputFilter.get().getRemainingPredicate()), session, types);
} else {
Map<Integer, Symbol> layout = SymbolUtils.toLayOut(filterNode.getOutputSymbols());
filteredStats = filterStatsCalculator.filterStats(semiJoinStats, semiJoinOutputFilter.get().getRemainingPredicate(), session, types, layout);
}
if (filteredStats.isOutputRowCountUnknown()) {
return Optional.of(semiJoinStats.mapOutputRowCount(rowCount -> rowCount * UNKNOWN_FILTER_COEFFICIENT));
}
return Optional.of(filteredStats);
}
use of io.prestosql.sql.planner.plan.SemiJoinNode in project hetu-core by openlookeng.
the class SimpleFilterProjectSemiJoinStatsRule method doCalculate.
@Override
protected Optional<PlanNodeStatsEstimate> doCalculate(FilterNode node, StatsProvider sourceStats, Lookup lookup, Session session, TypeProvider types) {
PlanNode nodeSource = lookup.resolve(node.getSource());
SemiJoinNode semiJoinNode;
if (nodeSource instanceof ProjectNode) {
ProjectNode projectNode = (ProjectNode) nodeSource;
if (!isIdentity(projectNode)) {
return Optional.empty();
}
PlanNode projectNodeSource = lookup.resolve(projectNode.getSource());
if (!(projectNodeSource instanceof SemiJoinNode)) {
return Optional.empty();
}
semiJoinNode = (SemiJoinNode) projectNodeSource;
} else if (nodeSource instanceof SemiJoinNode) {
semiJoinNode = (SemiJoinNode) nodeSource;
} else {
return Optional.empty();
}
return calculate(node, semiJoinNode, sourceStats, session, types);
}
Aggregations