abhishekagarwal87 commented on a change in pull request #12279:
URL: https://github.com/apache/druid/pull/12279#discussion_r830785559



##########
File path: 
indexing-service/src/test/java/org/apache/druid/indexing/common/task/IndexTaskTest.java
##########
@@ -213,6 +213,117 @@ public void setup() throws IOException
     taskRunner = new TestTaskRunner();
   }
 
+  @Test
+  public void testIngestNullOnlyColumns() throws Exception
+  {
+    File tmpDir = temporaryFolder.newFolder();
+
+    File tmpFile = File.createTempFile("druid", "index", tmpDir);
+
+    try (BufferedWriter writer = Files.newWriter(tmpFile, 
StandardCharsets.UTF_8)) {
+      writer.write("2014-01-01T00:00:10Z,,\n");
+      writer.write("2014-01-01T01:00:20Z,,\n");
+      writer.write("2014-01-01T02:00:30Z,,\n");
+    }
+
+    IndexTask indexTask = new IndexTask(
+        null,
+        null,
+        new IndexIngestionSpec(
+            new DataSchema(
+                "test-json",
+                DEFAULT_TIMESTAMP_SPEC,
+                new DimensionsSpec(
+                    ImmutableList.of(
+                        new StringDimensionSchema("ts"),
+                        new StringDimensionSchema("dim"),
+                        new LongDimensionSchema("valDim")
+                    )
+                ),
+                new AggregatorFactory[]{new LongSumAggregatorFactory("valMet", 
"val")},
+                new UniformGranularitySpec(
+                    Granularities.DAY,
+                    Granularities.MINUTE,
+                    Collections.singletonList(Intervals.of("2014/P1D"))
+                ),
+                null
+            ),
+            new IndexIOConfig(
+                null,
+                new LocalInputSource(tmpDir, "druid*"),
+                DEFAULT_INPUT_FORMAT,
+                false,
+                false
+            ),
+            createTuningConfigWithMaxRowsPerSegment(10, true)
+        ),
+        null
+    );
+
+    Assert.assertFalse(indexTask.supportsQueries());
+
+    final List<DataSegment> segments = runTask(indexTask).rhs;
+    Assert.assertEquals(1, segments.size());
+    Assert.assertEquals(ImmutableList.of("ts", "dim", "valDim"), 
segments.get(0).getDimensions());
+    Assert.assertEquals(ImmutableList.of("valMet"), 
segments.get(0).getMetrics());
+  }
+
+  @Test
+  public void 
testIngestNullOnlyColumns_storeEmptyColumnsOff_shouldNotStoreEmptyColumns() 
throws Exception
+  {
+    File tmpDir = temporaryFolder.newFolder();
+
+    File tmpFile = File.createTempFile("druid", "index", tmpDir);
+
+    try (BufferedWriter writer = Files.newWriter(tmpFile, 
StandardCharsets.UTF_8)) {
+      writer.write("2014-01-01T00:00:10Z,,\n");
+      writer.write("2014-01-01T01:00:20Z,,\n");
+      writer.write("2014-01-01T02:00:30Z,,\n");
+    }
+
+    IndexTask indexTask = new IndexTask(
+        null,
+        null,
+        new IndexIngestionSpec(
+            new DataSchema(
+                "test-json",
+                DEFAULT_TIMESTAMP_SPEC,
+                new DimensionsSpec(
+                    ImmutableList.of(
+                        new StringDimensionSchema("ts"),
+                        new StringDimensionSchema("dim"),
+                        new LongDimensionSchema("valDim")
+                    )
+                ),
+                new AggregatorFactory[]{new LongSumAggregatorFactory("valMet", 
"val")},
+                new UniformGranularitySpec(
+                    Granularities.DAY,
+                    Granularities.MINUTE,
+                    Collections.singletonList(Intervals.of("2014/P1D"))
+                ),
+                null
+            ),
+            new IndexIOConfig(
+                null,
+                new LocalInputSource(tmpDir, "druid*"),
+                DEFAULT_INPUT_FORMAT,
+                false,
+                false
+            ),
+            createTuningConfigWithMaxRowsPerSegment(10, true)
+        ),
+        ImmutableMap.of(Tasks.STORE_EMPTY_COLUMNS_KEY, false)
+    );
+
+    Assert.assertFalse(indexTask.supportsQueries());
+
+    final List<DataSegment> segments = runTask(indexTask).rhs;
+    Assert.assertEquals(1, segments.size());
+    // only empty string dimensions are ignored currently
+    Assert.assertEquals(ImmutableList.of("ts", "valDim"), 
segments.get(0).getDimensions());
+    Assert.assertEquals(ImmutableList.of("valMet"), 
segments.get(0).getMetrics());

Review comment:
       I was expecting `valMet` to be not stored. did I miss something? 

##########
File path: 
processing/src/main/java/org/apache/druid/segment/column/BitmapIndexes.java
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.google.common.base.Supplier;
+import com.google.common.base.Suppliers;
+import com.google.common.collect.ImmutableList;
+import org.apache.druid.collections.bitmap.BitmapFactory;
+import org.apache.druid.collections.bitmap.ImmutableBitmap;
+import org.apache.druid.common.config.NullHandling;
+import org.apache.druid.segment.serde.StringBitmapIndexColumnPartSupplier;
+
+import javax.annotation.Nullable;
+import java.util.Collections;
+import java.util.Set;
+import java.util.function.IntSupplier;
+import java.util.function.Predicate;
+
+public final class BitmapIndexes
+{
+  /**
+   * Returns a bitmapIndex for null-only columns.
+   *
+   * @param rowCountSupplier a supplier that returns the row count of the 
segment that the column belongs to.
+   *                         Getting from the supplier the row count can be 
expensive and thus should be
+   *                         evaluated lazily.
+   * @param bitmapFactory    a bitmapFactory to create a bitmapIndex.
+   */
+  public static BitmapIndex forNilColumn(IntSupplier rowCountSupplier, 
BitmapFactory bitmapFactory)
+  {
+    return new BitmapIndex()
+    {
+      private final Supplier<ImmutableBitmap> nullBitmapSupplier = 
Suppliers.memoize(
+          () -> getBitmapFactory().complement(
+              getBitmapFactory().makeEmptyImmutableBitmap(),
+              rowCountSupplier.getAsInt()
+          )
+      );
+
+      @Override
+      public int getCardinality()
+      {
+        return 1;
+      }
+
+      @Nullable
+      @Override
+      public String getValue(int index)
+      {
+        return null;
+      }
+
+      @Override
+      public boolean hasNulls()
+      {
+        return true;
+      }
+
+      @Override
+      public BitmapFactory getBitmapFactory()
+      {
+        return bitmapFactory;
+      }
+
+      /**
+       * Return -2 for non-null values to match what the {@link BitmapIndex} 
implementation in
+       * {@link StringBitmapIndexColumnPartSupplier}
+       * would return for {@link BitmapIndex#getIndex(String)} when there is 
only a single index, for the null value.
+       * i.e., return an 'insertion point' of 1 for non-null values (see 
{@link BitmapIndex} interface)
+       */
+      @Override
+      public int getIndex(@Nullable String value)
+      {
+        return NullHandling.isNullOrEquivalent(value) ? 0 : -2;
+      }
+
+      @Override
+      public ImmutableBitmap getBitmap(int idx)
+      {
+        if (idx == 0) {
+          return nullBitmapSupplier.get();
+        } else {
+          return bitmapFactory.makeEmptyImmutableBitmap();
+        }
+      }
+
+      @Override
+      public ImmutableBitmap getBitmapForValue(@Nullable String value)
+      {
+        if (NullHandling.isNullOrEquivalent(value)) {
+          return 
bitmapFactory.complement(bitmapFactory.makeEmptyImmutableBitmap(), 
rowCountSupplier.getAsInt());

Review comment:
       this could be nullBitmapSupplier.get()

##########
File path: processing/src/main/java/org/apache/druid/segment/IndexMergerV9.java
##########
@@ -809,6 +933,63 @@ private void mergeCapabilities(
     }
   }
 
+  /**
+   * Creates a merged columnCapabilities to merge two queryableIndexes.
+   * This method first snapshots a pair of capabilities and then merges them.
+   */
+  @Nullable
+  private static ColumnCapabilitiesImpl mergeCapabilities(
+      @Nullable final ColumnCapabilities capabilities,
+      @Nullable final ColumnCapabilities other,
+      CoercionLogic coercionLogic
+  )
+  {
+    ColumnCapabilitiesImpl merged = 
ColumnCapabilitiesImpl.snapshot(capabilities, coercionLogic);
+    ColumnCapabilitiesImpl otherSnapshot = 
ColumnCapabilitiesImpl.snapshot(other, coercionLogic);
+    if (merged == null) {
+      return otherSnapshot;
+    } else if (otherSnapshot == null) {
+      return merged;
+    }
+
+    if (!Objects.equals(merged.getType(), otherSnapshot.getType())
+        || !Objects.equals(merged.getComplexTypeName(), 
otherSnapshot.getComplexTypeName())
+        || !Objects.equals(merged.getElementType(), 
otherSnapshot.getElementType())) {
+      throw new ISE(

Review comment:
       can we add other info such as complex typename and element type name in 
the exception? 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to