use of com.facebook.presto.spi.relation.RowExpression in project presto by prestodb.
the class JoinGraph method joinWith.
private JoinGraph joinWith(JoinGraph other, List<JoinNode.EquiJoinClause> joinClauses, Context context, PlanNodeId newRoot) {
for (PlanNode node : other.nodes) {
checkState(!edges.containsKey(node.getId()), format("Node [%s] appeared in two JoinGraphs", node));
}
List<PlanNode> nodes = ImmutableList.<PlanNode>builder().addAll(this.nodes).addAll(other.nodes).build();
ImmutableMultimap.Builder<PlanNodeId, Edge> edges = ImmutableMultimap.<PlanNodeId, Edge>builder().putAll(this.edges).putAll(other.edges);
List<RowExpression> joinedFilters = ImmutableList.<RowExpression>builder().addAll(this.filters).addAll(other.filters).build();
for (JoinNode.EquiJoinClause edge : joinClauses) {
VariableReferenceExpression leftVariable = edge.getLeft();
VariableReferenceExpression rightVariable = edge.getRight();
checkState(context.containsVariable(leftVariable));
checkState(context.containsVariable(rightVariable));
PlanNode left = context.getVariableSource(leftVariable);
PlanNode right = context.getVariableSource(rightVariable);
edges.put(left.getId(), new Edge(right, leftVariable, rightVariable));
edges.put(right.getId(), new Edge(left, rightVariable, leftVariable));
}
return new JoinGraph(nodes, edges.build(), newRoot, joinedFilters, Optional.empty());
}
use of com.facebook.presto.spi.relation.RowExpression in project presto by prestodb.
the class TestConnectorFilterStatsCalculatorService method assertPredicate.
private void assertPredicate(Expression filterExpression, TableStatistics tableStatistics, TableStatistics expectedStatistics) {
RowExpression predicate = translator.translateAndOptimize(filterExpression, standardTypes);
TableStatistics filteredStatistics = statsCalculatorService.filterStats(tableStatistics, predicate, session.toConnectorSession(), ImmutableMap.of(xColumn, "x"), ImmutableMap.of("x", DOUBLE));
assertEquals(filteredStatistics, expectedStatistics);
}
use of com.facebook.presto.spi.relation.RowExpression in project presto by prestodb.
the class TestFilterStatsCalculator method assertExpression.
private PlanNodeStatsAssertion assertExpression(Expression expression) {
// assert both visitors yield the same result
RowExpression rowExpression = translator.translateAndOptimize(expression, standardTypes);
PlanNodeStatsEstimate expressionStatsEstimate = statsCalculator.filterStats(standardInputStatistics, expression, session, standardTypes);
PlanNodeStatsEstimate rowExpressionStatsEstimate = statsCalculator.filterStats(standardInputStatistics, rowExpression, session);
assertEquals(expressionStatsEstimate, rowExpressionStatsEstimate);
return PlanNodeStatsAssertion.assertThat(expressionStatsEstimate);
}
use of com.facebook.presto.spi.relation.RowExpression in project presto by prestodb.
the class TestScalarStatsCalculator method assertCalculate.
private VariableStatsAssertion assertCalculate(Expression scalarExpression, PlanNodeStatsEstimate inputStatistics, TypeProvider types) {
// assert both visitors yield the same result
RowExpression scalarRowExpression = translator.translate(scalarExpression, types);
VariableStatsEstimate expressionVariableStatsEstimate = calculator.calculate(scalarExpression, inputStatistics, session, types);
VariableStatsEstimate rowExpressionVariableStatsEstimate = calculator.calculate(scalarRowExpression, inputStatistics, session);
assertEquals(expressionVariableStatsEstimate, rowExpressionVariableStatsEstimate);
return VariableStatsAssertion.assertThat(expressionVariableStatsEstimate);
}
use of com.facebook.presto.spi.relation.RowExpression in project presto by prestodb.
the class OrcSelectivePageSourceFactory method toFilterFunctions.
/**
* Split filter expression into groups of conjuncts that depend on the same set of inputs,
* then compile each group into FilterFunction.
*/
private static List<FilterFunction> toFilterFunctions(RowExpression filter, Optional<BucketAdapter> bucketAdapter, ConnectorSession session, DeterminismEvaluator determinismEvaluator, PredicateCompiler predicateCompiler) {
ImmutableList.Builder<FilterFunction> filterFunctions = ImmutableList.builder();
bucketAdapter.map(predicate -> new FilterFunction(session.getSqlFunctionProperties(), true, predicate)).ifPresent(filterFunctions::add);
if (TRUE_CONSTANT.equals(filter)) {
return filterFunctions.build();
}
DynamicFilterExtractResult extractDynamicFilterResult = extractDynamicFilters(filter);
// dynamic filter will be added through subfield pushdown
filter = and(extractDynamicFilterResult.getStaticConjuncts());
if (!isAdaptiveFilterReorderingEnabled(session)) {
filterFunctions.add(new FilterFunction(session.getSqlFunctionProperties(), determinismEvaluator.isDeterministic(filter), predicateCompiler.compilePredicate(session.getSqlFunctionProperties(), session.getSessionFunctions(), filter).get()));
return filterFunctions.build();
}
List<RowExpression> conjuncts = extractConjuncts(filter);
if (conjuncts.size() == 1) {
filterFunctions.add(new FilterFunction(session.getSqlFunctionProperties(), determinismEvaluator.isDeterministic(filter), predicateCompiler.compilePredicate(session.getSqlFunctionProperties(), session.getSessionFunctions(), filter).get()));
return filterFunctions.build();
}
// Use LinkedHashMap to preserve user-specified order of conjuncts. This will be the initial order in which filters are applied.
Map<Set<Integer>, List<RowExpression>> inputsToConjuncts = new LinkedHashMap<>();
for (RowExpression conjunct : conjuncts) {
inputsToConjuncts.computeIfAbsent(extractInputs(conjunct), k -> new ArrayList<>()).add(conjunct);
}
inputsToConjuncts.values().stream().map(expressions -> binaryExpression(AND, expressions)).map(predicate -> new FilterFunction(session.getSqlFunctionProperties(), determinismEvaluator.isDeterministic(predicate), predicateCompiler.compilePredicate(session.getSqlFunctionProperties(), session.getSessionFunctions(), predicate).get())).forEach(filterFunctions::add);
return filterFunctions.build();
}
Aggregations