diff --git a/core/trino-main/src/main/java/io/trino/server/DynamicFilterService.java b/core/trino-main/src/main/java/io/trino/server/DynamicFilterService.java index 26b4ff70bc25..c56c7184b3e5 100644 --- a/core/trino-main/src/main/java/io/trino/server/DynamicFilterService.java +++ b/core/trino-main/src/main/java/io/trino/server/DynamicFilterService.java @@ -333,9 +333,10 @@ public TupleDomain getCurrentPredicate() return currentFilter.getDynamicFilter(); } - TupleDomain dynamicFilter = completedDynamicFilters.stream() - .map(filter -> translateSummaryToTupleDomain(filter, context, symbolsMap, columnHandles, typeProvider)) - .reduce(TupleDomain.all(), TupleDomain::intersect); + TupleDomain 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. diff --git a/core/trino-spi/src/main/java/io/trino/spi/predicate/TupleDomain.java b/core/trino-spi/src/main/java/io/trino/spi/predicate/TupleDomain.java index c95a826303a2..4e8e195d221a 100644 --- a/core/trino-spi/src/main/java/io/trino/spi/predicate/TupleDomain.java +++ b/core/trino-spi/src/main/java/io/trino/spi/predicate/TupleDomain.java @@ -247,8 +247,12 @@ public TupleDomain intersect(TupleDomain other) public static TupleDomain intersect(List> 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)) { diff --git a/core/trino-spi/src/test/java/io/trino/spi/predicate/TestTupleDomain.java b/core/trino-spi/src/test/java/io/trino/spi/predicate/TestTupleDomain.java index 238f83929f46..dd979967b423 100644 --- a/core/trino-spi/src/test/java/io/trino/spi/predicate/TestTupleDomain.java +++ b/core/trino-spi/src/test/java/io/trino/spi/predicate/TestTupleDomain.java @@ -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; @@ -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; @@ -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); + + TupleDomain 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