You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by ch...@apache.org on 2022/10/11 22:54:47 UTC

[druid] branch master updated: fix issue with nested column null value index incorrectly matching non-null values (#13211)

This is an automated email from the ASF dual-hosted git repository.

cheddar 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 9688674ea8 fix issue with nested column null value index incorrectly matching non-null values (#13211)
9688674ea8 is described below

commit 9688674ea880194caff1f12e38ad31ca0220ce0d
Author: Clint Wylie <cw...@apache.org>
AuthorDate: Tue Oct 11 15:54:36 2022 -0700

    fix issue with nested column null value index incorrectly matching non-null values (#13211)
---
 .../nested/NestedFieldLiteralColumnIndexSupplier.java  | 10 ++++++++--
 .../NestedFieldLiteralColumnIndexSupplierTest.java     | 18 ++++++++++++++++++
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/processing/src/main/java/org/apache/druid/segment/nested/NestedFieldLiteralColumnIndexSupplier.java b/processing/src/main/java/org/apache/druid/segment/nested/NestedFieldLiteralColumnIndexSupplier.java
index de7476bfbc..d3030c66f2 100644
--- a/processing/src/main/java/org/apache/druid/segment/nested/NestedFieldLiteralColumnIndexSupplier.java
+++ b/processing/src/main/java/org/apache/druid/segment/nested/NestedFieldLiteralColumnIndexSupplier.java
@@ -108,8 +108,14 @@ public class NestedFieldLiteralColumnIndexSupplier implements ColumnIndexSupplie
   public <T> T as(Class<T> clazz)
   {
     if (clazz.equals(NullValueIndex.class)) {
-      // null index is always 0 in the global dictionary, even if there are no null rows in any of the literal columns
-      return (T) (NullValueIndex) () -> new SimpleImmutableBitmapIndex(bitmaps.get(0));
+      final BitmapColumnIndex nullIndex;
+      if (dictionary.get(0) == 0) {
+        // null index is always 0 in the global dictionary, even if there are no null rows in any of the literal columns
+        nullIndex = new SimpleImmutableBitmapIndex(bitmaps.get(0));
+      } else {
+        nullIndex = new SimpleImmutableBitmapIndex(bitmapFactory.makeEmptyImmutableBitmap());
+      }
+      return (T) (NullValueIndex) () -> nullIndex;
     } else if (clazz.equals(DictionaryEncodedStringValueIndex.class) || clazz.equals(DictionaryEncodedValueIndex.class)) {
       return (T) new NestedLiteralDictionaryEncodedStringValueIndex();
     }
diff --git a/processing/src/test/java/org/apache/druid/segment/nested/NestedFieldLiteralColumnIndexSupplierTest.java b/processing/src/test/java/org/apache/druid/segment/nested/NestedFieldLiteralColumnIndexSupplierTest.java
index b4d576ac04..850baf4412 100644
--- a/processing/src/test/java/org/apache/druid/segment/nested/NestedFieldLiteralColumnIndexSupplierTest.java
+++ b/processing/src/test/java/org/apache/druid/segment/nested/NestedFieldLiteralColumnIndexSupplierTest.java
@@ -128,6 +128,24 @@ public class NestedFieldLiteralColumnIndexSupplierTest extends InitializedNullHa
     globalDoubles = FixedIndexed.read(doubleBuffer, TypeStrategies.DOUBLE, ByteOrder.nativeOrder(), Double.BYTES);
   }
 
+  @Test
+  public void testSingleTypeStringColumnValueIndex() throws IOException
+  {
+    NestedFieldLiteralColumnIndexSupplier indexSupplier = makeSingleTypeStringSupplier();
+
+    NullValueIndex nullIndex = indexSupplier.as(NullValueIndex.class);
+    Assert.assertNotNull(nullIndex);
+
+    // 10 rows
+    // local: [b, foo, fooo, z]
+    // column: [foo, b, fooo, b, z, fooo, z, b, b, foo]
+
+    BitmapColumnIndex columnIndex = nullIndex.forNull();
+    Assert.assertNotNull(columnIndex);
+    Assert.assertEquals(0.0, columnIndex.estimateSelectivity(10), 0.0);
+    ImmutableBitmap bitmap = columnIndex.computeBitmapResult(bitmapResultFactory);
+    Assert.assertEquals(0, bitmap.size());
+  }
 
   @Test
   public void testSingleTypeStringColumnValueSetIndex() throws IOException


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org