From 42dfa082367b9cbcf94182aac32dd5f6e53ea7e9 Mon Sep 17 00:00:00 2001 From: Clint Wylie Date: Wed, 22 Jan 2025 17:59:05 -0800 Subject: [PATCH] bonus tests for funsies --- .../druid/segment/filter/AndFilterTest.java | 46 ++++++++++++++++--- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/processing/src/test/java/org/apache/druid/segment/filter/AndFilterTest.java b/processing/src/test/java/org/apache/druid/segment/filter/AndFilterTest.java index 35185967f66d..b60fa4dbe553 100644 --- a/processing/src/test/java/org/apache/druid/segment/filter/AndFilterTest.java +++ b/processing/src/test/java/org/apache/druid/segment/filter/AndFilterTest.java @@ -21,7 +21,6 @@ import com.google.common.base.Function; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import nl.jqno.equalsverifier.EqualsVerifier; import org.apache.druid.data.input.InputRow; import org.apache.druid.data.input.impl.DimensionsSpec; @@ -34,8 +33,11 @@ import org.apache.druid.query.filter.AndDimFilter; import org.apache.druid.query.filter.NotDimFilter; import org.apache.druid.query.filter.SelectorDimFilter; +import org.apache.druid.query.filter.TrueDimFilter; import org.apache.druid.segment.CursorFactory; import org.apache.druid.segment.IndexBuilder; +import org.apache.druid.segment.column.ColumnType; +import org.apache.druid.segment.column.RowSignature; import org.junit.AfterClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -57,13 +59,19 @@ public class AndFilterTest extends BaseFilterTest ) ); + private static final RowSignature ROW_SIGNATURE = RowSignature.builder() + .add("dim0", ColumnType.STRING) + .add("dim1", ColumnType.STRING) + .add("dim2", ColumnType.STRING) + .build(); + private static final List ROWS = ImmutableList.of( - PARSER.parseBatch(ImmutableMap.of("dim0", "0", "dim1", "0")).get(0), - PARSER.parseBatch(ImmutableMap.of("dim0", "1", "dim1", "0")).get(0), - PARSER.parseBatch(ImmutableMap.of("dim0", "2", "dim1", "0")).get(0), - PARSER.parseBatch(ImmutableMap.of("dim0", "3", "dim1", "0")).get(0), - PARSER.parseBatch(ImmutableMap.of("dim0", "4", "dim1", "0")).get(0), - PARSER.parseBatch(ImmutableMap.of("dim0", "5", "dim1", "0")).get(0) + makeSchemaRow(PARSER, ROW_SIGNATURE, "0", "0", "a"), + makeSchemaRow(PARSER, ROW_SIGNATURE, "1", "0", null), + makeSchemaRow(PARSER, ROW_SIGNATURE, "2", "0", "b"), + makeSchemaRow(PARSER, ROW_SIGNATURE, "3", "0", null), + makeSchemaRow(PARSER, ROW_SIGNATURE, "4", "0", "c"), + makeSchemaRow(PARSER, ROW_SIGNATURE, "5", "0", null) ); public AndFilterTest( @@ -177,6 +185,30 @@ public void testNotAnd() ); } + @Test + public void testNotAndWithNulls() + { + assertFilterMatches( + new AndDimFilter( + ImmutableList.of( + TrueDimFilter.instance(), + new SelectorDimFilter("dim2", "c", null) + ) + ), + ImmutableList.of("4") + ); + assertFilterMatches( + new NotDimFilter( + new AndDimFilter(ImmutableList.of( + TrueDimFilter.instance(), + new SelectorDimFilter("dim2", "c", null) + ) + ) + ), + ImmutableList.of("0", "2") + ); + } + @Test public void test_equals() {