You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2018/09/05 19:28:51 UTC

[GitHub] gianm closed pull request #6223: make COMPLEX column optionally filterable in Druid code

gianm closed pull request #6223: make COMPLEX column optionally filterable in Druid code
URL: https://github.com/apache/incubator-druid/pull/6223
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/processing/src/main/java/org/apache/druid/segment/ColumnSelectorBitmapIndexSelector.java b/processing/src/main/java/org/apache/druid/segment/ColumnSelectorBitmapIndexSelector.java
index f452a5025b2..df0bddde886 100644
--- a/processing/src/main/java/org/apache/druid/segment/ColumnSelectorBitmapIndexSelector.java
+++ b/processing/src/main/java/org/apache/druid/segment/ColumnSelectorBitmapIndexSelector.java
@@ -29,10 +29,8 @@
 import org.apache.druid.segment.column.Column;
 import org.apache.druid.segment.column.DictionaryEncodedColumn;
 import org.apache.druid.segment.column.GenericColumn;
-import org.apache.druid.segment.column.ValueType;
 import org.apache.druid.segment.data.Indexed;
 import org.apache.druid.segment.data.IndexedIterable;
-import org.apache.druid.segment.filter.Filters;
 
 import java.util.Iterator;
 
@@ -142,7 +140,7 @@ public BitmapIndex getBitmapIndex(String dimension)
     }
 
     final Column column = index.getColumn(dimension);
-    if (column == null || !columnSupportsFiltering(column)) {
+    if (column == null || !column.getCapabilities().isFilterable()) {
       // for missing columns and columns with types that do not support filtering,
       // treat the column as if it were a String column full of nulls.
       // Create a BitmapIndex so that filters applied to null columns can use
@@ -212,7 +210,7 @@ public ImmutableBitmap getBitmapIndex(String dimension, String value)
     }
 
     final Column column = index.getColumn(dimension);
-    if (column == null || !columnSupportsFiltering(column)) {
+    if (column == null || !column.getCapabilities().isFilterable()) {
       if (NullHandling.isNullOrEquivalent(value)) {
         return bitmapFactory.complement(bitmapFactory.makeEmptyImmutableBitmap(), getNumRows());
       } else {
@@ -247,10 +245,4 @@ private boolean isVirtualColumn(final String columnName)
   {
     return virtualColumns.getVirtualColumn(columnName) != null;
   }
-
-  private static boolean columnSupportsFiltering(Column column)
-  {
-    ValueType columnType = column.getCapabilities().getType();
-    return Filters.FILTERABLE_TYPES.contains(columnType);
-  }
 }
diff --git a/processing/src/main/java/org/apache/druid/segment/column/ColumnBuilder.java b/processing/src/main/java/org/apache/druid/segment/column/ColumnBuilder.java
index 92ad6f5bb88..c5f0e5012a1 100644
--- a/processing/src/main/java/org/apache/druid/segment/column/ColumnBuilder.java
+++ b/processing/src/main/java/org/apache/druid/segment/column/ColumnBuilder.java
@@ -29,6 +29,7 @@
 {
   private ValueType type = null;
   private boolean hasMultipleValues = false;
+  private boolean filterable = false;
 
   private Supplier<DictionaryEncodedColumn> dictionaryEncodedColumn = null;
   private Supplier<GenericColumn> genericColumn = null;
@@ -60,6 +61,13 @@ public ColumnBuilder setHasMultipleValues(boolean hasMultipleValues)
     return this;
   }
 
+  @SuppressWarnings("unused")
+  public ColumnBuilder setFilterable(boolean filterable)
+  {
+    this.filterable = filterable;
+    return this;
+  }
+
   public ColumnBuilder setDictionaryEncodedColumn(Supplier<DictionaryEncodedColumn> dictionaryEncodedColumn)
   {
     this.dictionaryEncodedColumn = dictionaryEncodedColumn;
@@ -100,7 +108,8 @@ public Column build()
             .setDictionaryEncoded(dictionaryEncodedColumn != null)
             .setHasBitmapIndexes(bitmapIndex != null)
             .setHasSpatialIndexes(spatialIndex != null)
-            .setHasMultipleValues(hasMultipleValues),
+            .setHasMultipleValues(hasMultipleValues)
+            .setFilterable(filterable),
         dictionaryEncodedColumn,
         genericColumn,
         complexColumn,
diff --git a/processing/src/main/java/org/apache/druid/segment/column/ColumnCapabilities.java b/processing/src/main/java/org/apache/druid/segment/column/ColumnCapabilities.java
index 10fe1c91e4d..f3bf54efac6 100644
--- a/processing/src/main/java/org/apache/druid/segment/column/ColumnCapabilities.java
+++ b/processing/src/main/java/org/apache/druid/segment/column/ColumnCapabilities.java
@@ -30,4 +30,5 @@
   boolean hasBitmapIndexes();
   boolean hasSpatialIndexes();
   boolean hasMultipleValues();
+  boolean isFilterable();
 }
diff --git a/processing/src/main/java/org/apache/druid/segment/column/ColumnCapabilitiesImpl.java b/processing/src/main/java/org/apache/druid/segment/column/ColumnCapabilitiesImpl.java
index 961163033b2..65c94ae091a 100644
--- a/processing/src/main/java/org/apache/druid/segment/column/ColumnCapabilitiesImpl.java
+++ b/processing/src/main/java/org/apache/druid/segment/column/ColumnCapabilitiesImpl.java
@@ -19,6 +19,7 @@
 
 package org.apache.druid.segment.column;
 
+import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.fasterxml.jackson.annotation.JsonProperty;
 import org.apache.druid.java.util.common.ISE;
 
@@ -33,6 +34,10 @@
   private boolean hasSpatialIndexes = false;
   private boolean hasMultipleValues = false;
 
+  // This is a query time concept and not persisted in the segment files.
+  @JsonIgnore
+  private boolean filterable;
+
   @Override
   @JsonProperty
   public ValueType getType()
@@ -99,6 +104,22 @@ public boolean hasMultipleValues()
     return hasMultipleValues;
   }
 
+  @Override
+  public boolean isFilterable()
+  {
+    return type == ValueType.STRING ||
+           type == ValueType.LONG ||
+           type == ValueType.FLOAT ||
+           type == ValueType.DOUBLE ||
+           filterable;
+  }
+
+  public ColumnCapabilitiesImpl setFilterable(boolean filterable)
+  {
+    this.filterable = filterable;
+    return this;
+  }
+
   public ColumnCapabilitiesImpl setHasMultipleValues(boolean hasMultipleValues)
   {
     this.hasMultipleValues = hasMultipleValues;
@@ -124,5 +145,6 @@ public void merge(ColumnCapabilities other)
     this.hasInvertedIndexes |= other.hasBitmapIndexes();
     this.hasSpatialIndexes |= other.hasSpatialIndexes();
     this.hasMultipleValues |= other.hasMultipleValues();
+    this.filterable &= other.isFilterable();
   }
 }
diff --git a/processing/src/main/java/org/apache/druid/segment/filter/Filters.java b/processing/src/main/java/org/apache/druid/segment/filter/Filters.java
index 6f56f199b2f..c6d485d2cb7 100644
--- a/processing/src/main/java/org/apache/druid/segment/filter/Filters.java
+++ b/processing/src/main/java/org/apache/druid/segment/filter/Filters.java
@@ -64,12 +64,6 @@
  */
 public class Filters
 {
-  public static final List<ValueType> FILTERABLE_TYPES = ImmutableList.of(
-      ValueType.STRING,
-      ValueType.LONG,
-      ValueType.FLOAT,
-      ValueType.DOUBLE
-  );
   private static final String CTX_KEY_USE_FILTER_CNF = "useFilterCNF";
 
   /**
diff --git a/processing/src/test/java/org/apache/druid/segment/column/ColumnCapabilitiesImplTest.java b/processing/src/test/java/org/apache/druid/segment/column/ColumnCapabilitiesImplTest.java
new file mode 100644
index 00000000000..53e93c7a3b5
--- /dev/null
+++ b/processing/src/test/java/org/apache/druid/segment/column/ColumnCapabilitiesImplTest.java
@@ -0,0 +1,79 @@
+/*
+ * 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.column;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.druid.segment.TestHelper;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ColumnCapabilitiesImplTest
+{
+  private final ObjectMapper mapper = TestHelper.makeJsonMapper();
+
+  @Test
+  public void testSerde() throws Exception
+  {
+    String json = mapper.writeValueAsString(new ColumnCapabilitiesImpl()
+                                                .setDictionaryEncoded(true)
+                                                .setHasBitmapIndexes(true)
+                                                .setHasMultipleValues(true)
+                                                .setHasSpatialIndexes(true)
+                                                .setType(ValueType.COMPLEX)
+                                                .setFilterable(true));
+
+    Assert.assertFalse(json.contains("filterable"));
+    
+    ColumnCapabilities cc = mapper.readValue(json, ColumnCapabilitiesImpl.class);
+
+    Assert.assertEquals(ValueType.COMPLEX, cc.getType());
+    Assert.assertTrue(cc.isDictionaryEncoded());
+    Assert.assertFalse(cc.isRunLengthEncoded());
+    Assert.assertTrue(cc.hasSpatialIndexes());
+    Assert.assertTrue(cc.hasMultipleValues());
+    Assert.assertTrue(cc.hasBitmapIndexes());
+    Assert.assertFalse(cc.isFilterable());
+  }
+
+  @Test
+  public void testDeserialization() throws Exception
+  {
+    String json = "{\n"
+                  + "  \"type\":\"COMPLEX\",\n"
+                  + "  \"dictionaryEncoded\":true,\n"
+                  + "  \"runLengthEncoded\":true,\n"
+                  + "  \"hasSpatialIndexes\":true,\n"
+                  + "  \"hasMultipleValues\":true,\n"
+                  + "  \"hasBitmapIndexes\":true,\n"
+                  + "  \"filterable\":true\n"
+                  + "}";
+
+
+    ColumnCapabilities cc = mapper.readValue(json, ColumnCapabilitiesImpl.class);
+
+    Assert.assertEquals(ValueType.COMPLEX, cc.getType());
+    Assert.assertTrue(cc.isDictionaryEncoded());
+    Assert.assertTrue(cc.isRunLengthEncoded());
+    Assert.assertTrue(cc.hasSpatialIndexes());
+    Assert.assertTrue(cc.hasMultipleValues());
+    Assert.assertTrue(cc.hasBitmapIndexes());
+    Assert.assertFalse(cc.isFilterable());
+  }
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

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