Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,10 @@ public TupleDomain<ColumnHandle> getCurrentPredicate()
return currentFilter.getDynamicFilter();
}

TupleDomain<ColumnHandle> dynamicFilter = completedDynamicFilters.stream()
.map(filter -> translateSummaryToTupleDomain(filter, context, symbolsMap, columnHandles, typeProvider))
.reduce(TupleDomain.all(), TupleDomain::intersect);
TupleDomain<ColumnHandle> dynamicFilter = TupleDomain.intersect(
completedDynamicFilters.stream()
.map(filter -> translateSummaryToTupleDomain(filter, context, symbolsMap, columnHandles, typeProvider))
.collect(toImmutableList()));

// It could happen that two threads update currentDynamicFilter concurrently.
// In such case, currentDynamicFilter might be set to dynamic filter with less domains.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,12 @@ public TupleDomain<T> intersect(TupleDomain<T> other)

public static <T> TupleDomain<T> intersect(List<TupleDomain<T>> domains)
{
if (domains.size() < 2) {
throw new IllegalArgumentException("Expected at least 2 elements");
if (domains.isEmpty()) {
return all();
}

if (domains.size() == 1) {
return domains.get(0);
}

if (domains.stream().anyMatch(TupleDomain::isNone)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import io.airlift.json.ObjectMapperProvider;
import io.trino.spi.block.Block;
Expand All @@ -38,6 +39,7 @@
import java.util.function.Predicate;

import static io.airlift.slice.Slices.utf8Slice;
import static io.trino.spi.predicate.TupleDomain.all;
import static io.trino.spi.predicate.TupleDomain.columnWiseUnion;
import static io.trino.spi.type.BigintType.BIGINT;
import static io.trino.spi.type.BooleanType.BOOLEAN;
Expand Down Expand Up @@ -112,6 +114,21 @@ public void testIntersection()

assertEquals(tupleDomain1.intersect(tupleDomain2), expectedTupleDomain);
assertEquals(tupleDomain2.intersect(tupleDomain1), expectedTupleDomain);

assertEquals(TupleDomain.intersect(ImmutableList.of()), all());
assertEquals(TupleDomain.intersect(ImmutableList.of(tupleDomain1)), tupleDomain1);
assertEquals(TupleDomain.intersect(ImmutableList.of(tupleDomain1, tupleDomain2)), expectedTupleDomain);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yikes, we had no tests here for TupleDomain.intersect(List)... thanks for adding them!


TupleDomain<ColumnHandle> tupleDomain3 = TupleDomain.withColumnDomains(ImmutableMap.of(
C, Domain.singleValue(BIGINT, 1L),
D, Domain.create(ValueSet.ofRanges(Range.range(DOUBLE, 5.0, true, 100.0, true)), true)));
expectedTupleDomain = TupleDomain.withColumnDomains(
ImmutableMap.of(
A, Domain.singleValue(VARCHAR, utf8Slice("value")),
B, Domain.singleValue(DOUBLE, 0.0),
C, Domain.singleValue(BIGINT, 1L),
D, Domain.create(ValueSet.ofRanges(Range.range(DOUBLE, 5.0, true, 10.0, false)), false)));
assertEquals(TupleDomain.intersect(ImmutableList.of(tupleDomain1, tupleDomain2, tupleDomain3)), expectedTupleDomain);
}

@Test
Expand Down