From 1714c45aa146f27b3df20dfe692777c2765e71d6 Mon Sep 17 00:00:00 2001 From: Gian Merlino Date: Wed, 6 Dec 2023 01:39:59 -0800 Subject: [PATCH] Fix NullFilter getDimensionRangeSet. (#15500) It wasn't checking the column name, so it would return a domain regardless of the input column. This means that null filters on data sources with range partitioning would lead to excessive pruning of segments, and therefore missing results. --- .../apache/druid/query/filter/NullFilter.java | 4 ++++ .../druid/segment/filter/NullFilterTests.java | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/processing/src/main/java/org/apache/druid/query/filter/NullFilter.java b/processing/src/main/java/org/apache/druid/query/filter/NullFilter.java index 14bdb6f4185e..da737bdce890 100644 --- a/processing/src/main/java/org/apache/druid/query/filter/NullFilter.java +++ b/processing/src/main/java/org/apache/druid/query/filter/NullFilter.java @@ -114,6 +114,10 @@ public Filter toFilter() @Override public RangeSet getDimensionRangeSet(String dimension) { + if (!Objects.equals(getColumn(), dimension)) { + return null; + } + RangeSet retSet = TreeRangeSet.create(); // Nulls are less than empty String in segments retSet.add(Range.lessThan("")); diff --git a/processing/src/test/java/org/apache/druid/segment/filter/NullFilterTests.java b/processing/src/test/java/org/apache/druid/segment/filter/NullFilterTests.java index b123ead53a54..084c1c24c2bf 100644 --- a/processing/src/test/java/org/apache/druid/segment/filter/NullFilterTests.java +++ b/processing/src/test/java/org/apache/druid/segment/filter/NullFilterTests.java @@ -23,6 +23,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.base.Function; import com.google.common.collect.ImmutableList; +import com.google.common.collect.Range; +import com.google.common.collect.TreeRangeSet; import nl.jqno.equalsverifier.EqualsVerifier; import org.apache.druid.common.config.NullHandling; import org.apache.druid.jackson.DefaultObjectMapper; @@ -41,6 +43,7 @@ import java.io.Closeable; import java.util.Arrays; +import java.util.Collections; @RunWith(Enclosed.class) public class NullFilterTests @@ -310,6 +313,19 @@ public void testArrays() public static class NullFilterNonParameterizedTest { + @Test + public void testGetDimensionRangeSet() + { + final NullFilter filter = new NullFilter("x", null); + + Assert.assertEquals( + TreeRangeSet.create(Collections.singleton(Range.lessThan(""))), + filter.getDimensionRangeSet("x") + ); + + Assert.assertNull(filter.getDimensionRangeSet("y")); + } + @Test public void testSerde() throws JsonProcessingException {