use of com.facebook.presto.expressions.DynamicFilters.DynamicFilterPlaceholder in project presto by prestodb.
the class TestLocalDynamicFilter method testSimple.
@Test
public void testSimple() throws ExecutionException, InterruptedException {
LocalDynamicFilter filter = new LocalDynamicFilter(ImmutableMultimap.of("123", new DynamicFilterPlaceholder("123", new VariableReferenceExpression(Optional.empty(), "a", INTEGER), EQUAL)), ImmutableMap.of("123", 0), 1);
assertEquals(filter.getBuildChannels(), ImmutableMap.of("123", 0));
Consumer<TupleDomain<String>> consumer = filter.getTupleDomainConsumer();
ListenableFuture<TupleDomain<VariableReferenceExpression>> result = filter.getResultFuture();
assertFalse(result.isDone());
consumer.accept(TupleDomain.withColumnDomains(ImmutableMap.of("123", Domain.singleValue(INTEGER, 7L))));
assertEquals(result.get(), TupleDomain.withColumnDomains(ImmutableMap.of(new VariableReferenceExpression(Optional.empty(), "a", INTEGER), Domain.singleValue(INTEGER, 7L))));
}
use of com.facebook.presto.expressions.DynamicFilters.DynamicFilterPlaceholder 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));
}
use of com.facebook.presto.expressions.DynamicFilters.DynamicFilterPlaceholder in project presto by prestodb.
the class LocalDynamicFilter method convertTupleDomain.
private TupleDomain<VariableReferenceExpression> convertTupleDomain(TupleDomain<String> result) {
if (result.isNone()) {
return TupleDomain.none();
}
// Convert the predicate to use probe variables (instead dynamic filter IDs).
// Note that in case of a probe-side union, a single dynamic filter may match multiple probe variables.
ImmutableMap.Builder<VariableReferenceExpression, Domain> builder = ImmutableMap.builder();
for (Map.Entry<String, Domain> entry : result.getDomains().get().entrySet()) {
Domain domain = entry.getValue();
// Store all matching variables for each build channel index.
for (DynamicFilterPlaceholder placeholder : probeVariables.get(entry.getKey())) {
Domain updatedDomain = placeholder.applyComparison(domain);
builder.put((VariableReferenceExpression) placeholder.getInput(), updatedDomain);
}
}
return TupleDomain.withColumnDomains(builder.build());
}
Aggregations