clintropolis commented on code in PR #16039:
URL: https://github.com/apache/druid/pull/16039#discussion_r1534871389


##########
processing/src/main/java/org/apache/druid/query/filter/TypedInFilter.java:
##########
@@ -0,0 +1,713 @@
+/*
+ * 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.query.filter;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Joiner;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Supplier;
+import com.google.common.base.Suppliers;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Range;
+import com.google.common.collect.RangeSet;
+import com.google.common.collect.Sets;
+import com.google.common.collect.TreeRangeSet;
+import com.google.common.hash.Hasher;
+import com.google.common.hash.Hashing;
+import it.unimi.dsi.fastutil.doubles.DoubleOpenHashSet;
+import it.unimi.dsi.fastutil.floats.FloatOpenHashSet;
+import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
+import it.unimi.dsi.fastutil.objects.ObjectAVLTreeSet;
+import it.unimi.dsi.fastutil.objects.ObjectArrays;
+import org.apache.druid.common.config.NullHandling;
+import org.apache.druid.error.InvalidInput;
+import org.apache.druid.java.util.common.ByteBufferUtils;
+import org.apache.druid.java.util.common.IAE;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.math.expr.Evals;
+import org.apache.druid.query.cache.CacheKeyBuilder;
+import org.apache.druid.query.filter.vector.VectorValueMatcher;
+import 
org.apache.druid.query.filter.vector.VectorValueMatcherColumnProcessorFactory;
+import org.apache.druid.segment.ColumnInspector;
+import org.apache.druid.segment.ColumnProcessors;
+import org.apache.druid.segment.ColumnSelectorFactory;
+import org.apache.druid.segment.DimensionHandlerUtils;
+import org.apache.druid.segment.column.ColumnIndexSupplier;
+import org.apache.druid.segment.column.ColumnType;
+import org.apache.druid.segment.column.NullableTypeStrategy;
+import org.apache.druid.segment.column.ValueType;
+import org.apache.druid.segment.filter.Filters;
+import org.apache.druid.segment.index.BitmapColumnIndex;
+import org.apache.druid.segment.index.semantic.Utf8ValueSetIndexes;
+import org.apache.druid.segment.index.semantic.ValueSetIndexes;
+import org.apache.druid.segment.vector.VectorColumnSelectorFactory;
+
+import javax.annotation.Nullable;
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.SortedSet;
+
+public class TypedInFilter extends AbstractOptimizableDimFilter implements 
Filter
+{
+  private final String column;
+  private final ColumnType matchValueType;
+  @Nullable
+  private final List<?> unsortedValues;
+  private final Supplier<List<?>> lazyMatchValues;
+  @Nullable
+  private final Supplier<SortedSet<ByteBuffer>> lazyMatchValueBytes;
+  @Nullable
+  private final FilterTuning filterTuning;
+  private final Supplier<DruidPredicateFactory> predicateFactorySupplier;
+
+  @JsonIgnore
+  private final Supplier<byte[]> cacheKeySupplier;
+
+  /**
+   * Creates a new filter.
+   *
+   * @param column         column to search
+   * @param values         set of values to match. This collection may be 
reused to avoid copying a big collection.
+   *                       Therefore, callers should <b>not</b> modify the 
collection after it is passed to this
+   *                       constructor.
+   * @param matchValueType type of values contained in set
+   * @param filterTuning   optional tuning
+   */
+  @JsonCreator
+  public TypedInFilter(
+      @JsonProperty("column") String column,
+      @JsonProperty("matchValueType") ColumnType matchValueType,
+      @JsonProperty("values") @Nullable List<?> values,
+      @JsonProperty("sortedValues") @Nullable List<?> sortedValues,
+      @JsonProperty("filterTuning") @Nullable FilterTuning filterTuning
+  )
+  {
+    if (NullHandling.replaceWithDefault()) {
+      throw InvalidInput.exception(
+          "Invalid IN filter, typed in filter only supports SQL compatible 
null handling mode, set druid.generic.useDefaultValue=false to use this filter"
+      );
+    }
+    this.column = column;
+    if (column == null) {
+      throw InvalidInput.exception("Invalid IN filter, column cannot be null");
+    }
+    this.filterTuning = filterTuning;
+    this.matchValueType = matchValueType;
+    if (matchValueType == null) {
+      throw InvalidInput.exception("Invalid IN filter on column [%s], 
matchValueType cannot be null", column);
+    }
+    // one of sorted or not sorted
+    if (values == null && sortedValues == null) {
+      throw InvalidInput.exception(
+          "Invalid IN filter on column [%s], exactly one of values or 
sortedValues must be non-null",
+          column
+      );
+    }
+    if (sortedValues != null) {
+      this.unsortedValues = null;
+      this.lazyMatchValues = () -> sortedValues;
+    } else {
+      if (checkSorted(values, matchValueType)) {

Review Comment:
   i went back to using a sorted set to order and dedupe since I could think of 
a very efficient way to do this otherwise other than creating my own modified 
version of quickSort that also dedupes



-- 
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