You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by cw...@apache.org on 2020/06/09 00:40:49 UTC
[druid] branch master updated: fix NilVectorSelector filter
optimization (#9989)
This is an automated email from the ASF dual-hosted git repository.
cwylie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/druid.git
The following commit(s) were added to refs/heads/master by this push:
new 7f51e44 fix NilVectorSelector filter optimization (#9989)
7f51e44 is described below
commit 7f51e44b008a0e6cf7d7d128ef3c97f8a4e12c65
Author: Clint Wylie <cw...@apache.org>
AuthorDate: Mon Jun 8 17:40:29 2020 -0700
fix NilVectorSelector filter optimization (#9989)
---
.../druid/segment/vector/NilVectorSelector.java | 2 +-
.../druid/segment/filter/ValueMatchersTest.java | 152 +++++++++++++++++++++
2 files changed, 153 insertions(+), 1 deletion(-)
diff --git a/processing/src/main/java/org/apache/druid/segment/vector/NilVectorSelector.java b/processing/src/main/java/org/apache/druid/segment/vector/NilVectorSelector.java
index 3aeb32c..9cc6dea 100644
--- a/processing/src/main/java/org/apache/druid/segment/vector/NilVectorSelector.java
+++ b/processing/src/main/java/org/apache/druid/segment/vector/NilVectorSelector.java
@@ -142,7 +142,7 @@ public class NilVectorSelector
@Override
public boolean nameLookupPossibleInAdvance()
{
- return false;
+ return true;
}
@Nullable
diff --git a/processing/src/test/java/org/apache/druid/segment/filter/ValueMatchersTest.java b/processing/src/test/java/org/apache/druid/segment/filter/ValueMatchersTest.java
new file mode 100644
index 0000000..6698c3a
--- /dev/null
+++ b/processing/src/test/java/org/apache/druid/segment/filter/ValueMatchersTest.java
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.segment.filter;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.druid.segment.DimensionSelector;
+import org.apache.druid.segment.SimpleAscendingOffset;
+import org.apache.druid.segment.data.GenericIndexed;
+import org.apache.druid.segment.data.VSizeColumnarInts;
+import org.apache.druid.segment.data.VSizeColumnarMultiInts;
+import org.apache.druid.segment.serde.DictionaryEncodedColumnSupplier;
+import org.apache.druid.segment.vector.NilVectorSelector;
+import org.apache.druid.segment.vector.NoFilterVectorOffset;
+import org.apache.druid.testing.InitializedNullHandlingTest;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ValueMatchersTest extends InitializedNullHandlingTest
+{
+ private DictionaryEncodedColumnSupplier supplierSingleConstant;
+ private DictionaryEncodedColumnSupplier supplierSingle;
+ private DictionaryEncodedColumnSupplier supplierMulti;
+
+ @Before
+ public void setup()
+ {
+ supplierSingleConstant = new DictionaryEncodedColumnSupplier(
+ GenericIndexed.fromIterable(ImmutableList.of("value"), GenericIndexed.STRING_STRATEGY),
+ () -> VSizeColumnarInts.fromArray(new int[]{0}),
+ null,
+ 0
+ );
+ supplierSingle = new DictionaryEncodedColumnSupplier(
+ GenericIndexed.fromIterable(ImmutableList.of("value", "value2"), GenericIndexed.STRING_STRATEGY),
+ () -> VSizeColumnarInts.fromArray(new int[]{0, 0, 1, 0, 1}),
+ null,
+ 0
+ );
+ supplierMulti = new DictionaryEncodedColumnSupplier(
+ GenericIndexed.fromIterable(ImmutableList.of("value"), GenericIndexed.STRING_STRATEGY),
+ null,
+ () -> VSizeColumnarMultiInts.fromIterable(
+ ImmutableList.of(
+ VSizeColumnarInts.fromArray(new int[]{0, 0}),
+ VSizeColumnarInts.fromArray(new int[]{0})
+ )
+ ),
+ 0
+ );
+ }
+ @Test
+ public void testNullDimensionSelectorCanBeBoolean()
+ {
+ Boolean resultMatchNull = ValueMatchers.toBooleanIfPossible(
+ DimensionSelector.constant(null),
+ false,
+ string -> string == null
+ );
+ Assert.assertNotNull(resultMatchNull);
+ Assert.assertTrue(resultMatchNull);
+
+ Boolean resultMatchNotNull = ValueMatchers.toBooleanIfPossible(
+ DimensionSelector.constant(null),
+ false,
+ string -> string != null
+ );
+ Assert.assertNotNull(resultMatchNotNull);
+ Assert.assertFalse(resultMatchNotNull);
+
+ Boolean resultMatchNonNilConstant = ValueMatchers.toBooleanIfPossible(
+ supplierSingleConstant.get().makeDimensionSelector(new SimpleAscendingOffset(1), null),
+ false,
+ string -> string != null
+ );
+ Assert.assertNotNull(resultMatchNonNilConstant);
+ Assert.assertTrue(resultMatchNonNilConstant);
+
+ Boolean resultMatchNonNil = ValueMatchers.toBooleanIfPossible(
+ supplierSingle.get().makeDimensionSelector(new SimpleAscendingOffset(1), null),
+ false,
+ string -> string != null
+ );
+ Assert.assertNull(resultMatchNonNil);
+
+ Boolean resultMatchNonNilMulti = ValueMatchers.toBooleanIfPossible(
+ supplierMulti.get().makeDimensionSelector(new SimpleAscendingOffset(1), null),
+ true,
+ string -> string != null
+ );
+ Assert.assertNull(resultMatchNonNilMulti);
+ }
+
+ @Test
+ public void testNilVectorSelectorCanBeBoolean()
+ {
+ Boolean resultMatchNull = ValueMatchers.toBooleanIfPossible(
+ NilVectorSelector.create(new NoFilterVectorOffset(10, 0, 100)),
+ false,
+ string -> string == null
+ );
+ Assert.assertNotNull(resultMatchNull);
+ Assert.assertTrue(resultMatchNull);
+
+ Boolean resultMatchNotNull = ValueMatchers.toBooleanIfPossible(
+ NilVectorSelector.create(new NoFilterVectorOffset(10, 0, 100)),
+ false,
+ string -> string != null
+ );
+ Assert.assertNotNull(resultMatchNotNull);
+ Assert.assertFalse(resultMatchNotNull);
+
+ Boolean resultMatchNotNilConstant = ValueMatchers.toBooleanIfPossible(
+ supplierSingleConstant.get().makeSingleValueDimensionVectorSelector(new NoFilterVectorOffset(10, 0, 1)),
+ false,
+ string -> string != null
+ );
+ Assert.assertNotNull(resultMatchNotNilConstant);
+ Assert.assertTrue(resultMatchNotNilConstant);
+
+ Boolean resultMatchNotNil = ValueMatchers.toBooleanIfPossible(
+ supplierSingle.get().makeSingleValueDimensionVectorSelector(new NoFilterVectorOffset(10, 0, 1)),
+ false,
+ string -> string != null
+ );
+ Assert.assertNull(resultMatchNotNil);
+
+ Boolean resultMatchNotNilMulti = ValueMatchers.toBooleanIfPossible(
+ supplierMulti.get().makeSingleValueDimensionVectorSelector(new NoFilterVectorOffset(10, 0, 1)),
+ true,
+ string -> string != null
+ );
+ Assert.assertNull(resultMatchNotNilMulti);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org