From 6d10f29892f43d770e3145b7bdce26a33d4c502e Mon Sep 17 00:00:00 2001 From: Clint Wylie Date: Tue, 22 Oct 2024 00:39:24 -0700 Subject: [PATCH] cleanup --- .../druid/segment/StringDimensionIndexer.java | 160 +++++++++--------- 1 file changed, 77 insertions(+), 83 deletions(-) diff --git a/processing/src/main/java/org/apache/druid/segment/StringDimensionIndexer.java b/processing/src/main/java/org/apache/druid/segment/StringDimensionIndexer.java index 5ebe0c5bc10..42b1a9ae1f5 100644 --- a/processing/src/main/java/org/apache/druid/segment/StringDimensionIndexer.java +++ b/processing/src/main/java/org/apache/druid/segment/StringDimensionIndexer.java @@ -25,6 +25,7 @@ import org.apache.druid.collections.bitmap.BitmapFactory; import org.apache.druid.collections.bitmap.MutableBitmap; import org.apache.druid.common.config.NullHandling; import org.apache.druid.data.input.impl.DimensionSchema.MultiValueHandling; +import org.apache.druid.error.DruidException; import org.apache.druid.java.util.common.ISE; import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.java.util.common.guava.Comparators; @@ -294,6 +295,7 @@ public class StringDimensionIndexer extends DictionaryEncodedColumnIndexer= 0 && nullId < maxId) { - // null was added to the dictionary before this selector was created; return its ID. - if (nullIdIntArray == null) { - nullIdIntArray = new int[]{nullId}; - } - row = nullIdIntArray; - rowSize = 1; - } else { - // null doesn't exist in the dictionary; return an empty array. - // Choose to use ArrayBasedIndexedInts later, instead of special "empty" IndexedInts, for monomorphism - row = IntArrays.EMPTY_ARRAY; - rowSize = 0; + DruidException.conditionalDefensive( + nullId >= 0 && nullId < maxId, + "Null value not present in dictionary, how did this happen?" + ); + if (nullIdIntArray == null) { + nullIdIntArray = new int[]{nullId}; } + row = nullIdIntArray; + rowSize = 1; } - } - - if (row == null && indices != null && indices.length > 0) { + } else { row = indices; rowSize = indices.length; } @@ -337,76 +332,75 @@ public class StringDimensionIndexer extends DictionaryEncodedColumnIndexer= 0 || value == null) { - return new ValueMatcher() - { - @Override - public boolean matches(boolean includeUnknown) - { - Object[] dims = currEntry.get().getDims(); - if (dimIndex >= dims.length) { - return includeUnknown || value == null; - } - - int[] dimsInt = (int[]) dims[dimIndex]; - if (dimsInt == null || dimsInt.length == 0) { - return includeUnknown || value == null; - } - - for (int id : dimsInt) { - if (id == valueId) { - return true; - } - if (includeUnknown && (id == nullValueId)) { - return true; - } - } - return false; - } - - @Override - public void inspectRuntimeShape(RuntimeShapeInspector inspector) - { - // nothing to inspect - } - }; - } else { - return new ValueMatcher() - { - @Override - public boolean matches(boolean includeUnknown) - { - if (includeUnknown) { - IndexedInts row = getRow(); - final int size = row.size(); - if (size == 0) { - return true; - } - for (int i = 0; i < size; i++) { - if (row.get(i) == nullValueId) { - return true; - } - } - } - return false; - } - - @Override - public void inspectRuntimeShape(RuntimeShapeInspector inspector) - { - // nothing to inspect - } - }; - } - } else { + if (extractionFn != null) { // Employ caching BitSet optimization return makeValueMatcher(StringPredicateDruidPredicateFactory.equalTo(value)); } + final int valueId = lookupId(value); + final int nullValueId = lookupId(null); + if (valueId >= 0 || value == null) { + return new ValueMatcher() + { + @Override + public boolean matches(boolean includeUnknown) + { + Object[] dims = currEntry.get().getDims(); + if (dimIndex >= dims.length) { + return includeUnknown || value == null; + } + + int[] dimsInt = (int[]) dims[dimIndex]; + if (dimsInt == null || dimsInt.length == 0) { + return includeUnknown || value == null; + } + + for (int id : dimsInt) { + if (id == valueId) { + return true; + } + if (includeUnknown && (id == nullValueId)) { + return true; + } + } + return false; + } + + @Override + public void inspectRuntimeShape(RuntimeShapeInspector inspector) + { + // nothing to inspect + } + }; + } else { + return new ValueMatcher() + { + @Override + public boolean matches(boolean includeUnknown) + { + if (includeUnknown) { + IndexedInts row = getRow(); + final int size = row.size(); + if (size == 0) { + return true; + } + for (int i = 0; i < size; i++) { + if (row.get(i) == nullValueId) { + return true; + } + } + } + return false; + } + + @Override + public void inspectRuntimeShape(RuntimeShapeInspector inspector) + { + // nothing to inspect + } + }; + } } @Override @@ -488,7 +482,7 @@ public class StringDimensionIndexer extends DictionaryEncodedColumnIndexer