use of com.facebook.presto.expressions.DynamicFilters.DynamicFilterExtractResult 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();
}
use of com.facebook.presto.expressions.DynamicFilters.DynamicFilterExtractResult in project presto by prestodb.
the class LocalDynamicFilter method create.
public static Optional<LocalDynamicFilter> create(AbstractJoinNode planNode, int partitionCount) {
Set<String> joinDynamicFilters = planNode.getDynamicFilters().keySet();
List<FilterNode> filterNodes = PlanNodeSearcher.searchFrom(planNode.getProbe()).where(LocalDynamicFilter::isFilterAboveTableScan).findAll();
// Mapping from probe-side dynamic filters' IDs to their matching probe variables.
ImmutableMultimap.Builder<String, DynamicFilterPlaceholder> probeVariablesBuilder = ImmutableMultimap.builder();
for (FilterNode filterNode : filterNodes) {
DynamicFilterExtractResult extractResult = extractDynamicFilters(filterNode.getPredicate());
for (DynamicFilterPlaceholder placeholder : extractResult.getDynamicConjuncts()) {
if (placeholder.getInput() instanceof VariableReferenceExpression) {
// Add descriptors that match the local dynamic filter (from the current join node).
if (joinDynamicFilters.contains(placeholder.getId())) {
probeVariablesBuilder.put(placeholder.getId(), placeholder);
}
}
}
}
Multimap<String, DynamicFilterPlaceholder> probeVariables = probeVariablesBuilder.build();
PlanNode buildNode = planNode.getBuild();
Map<String, Integer> buildChannels = planNode.getDynamicFilters().entrySet().stream().filter(entry -> probeVariables.containsKey(entry.getKey())).collect(toMap(// Dynamic filter ID
Map.Entry::getKey, // Build-side channel index
entry -> {
VariableReferenceExpression buildVariable = entry.getValue();
int buildChannelIndex = buildNode.getOutputVariables().indexOf(buildVariable);
verify(buildChannelIndex >= 0);
return buildChannelIndex;
}));
if (buildChannels.isEmpty()) {
return Optional.empty();
}
return Optional.of(new LocalDynamicFilter(probeVariables, buildChannels, partitionCount));
}
Aggregations