jihoonson commented on a change in pull request #9800:
URL: https://github.com/apache/druid/pull/9800#discussion_r421005456



##########
File path: 
processing/src/main/java/org/apache/druid/query/filter/AndDimFilter.java
##########
@@ -72,8 +73,20 @@ public AndDimFilter(DimFilter... fields)
   @Override
   public DimFilter optimize()
   {
-    List<DimFilter> elements = DimFilters.optimize(fields);
-    return elements.size() == 1 ? elements.get(0) : new AndDimFilter(elements);
+    List<DimFilter> elements = DimFilters.optimize(fields)
+                                         .stream()
+                                         .filter(filter -> !(filter instanceof 
TrueDimFilter))
+                                         .collect(Collectors.toList());
+    if (elements.isEmpty()) {
+      // All elements were TrueDimFilter after optimization
+      return TrueDimFilter.instance();
+    } else if (elements.size() == 1) {
+      return elements.get(0);

Review comment:
       Added.

##########
File path: 
processing/src/main/java/org/apache/druid/query/filter/FalseDimFilter.java
##########
@@ -0,0 +1,94 @@
+/*
+ * 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.google.common.collect.ImmutableRangeSet;
+import com.google.common.collect.RangeSet;
+import org.apache.druid.query.cache.CacheKeyBuilder;
+import org.apache.druid.segment.filter.FalseFilter;
+
+import javax.annotation.Nullable;
+import java.util.Collections;
+import java.util.Set;
+
+public class FalseDimFilter implements DimFilter
+{
+  private static final FalseDimFilter INSTANCE = new FalseDimFilter();
+
+  @JsonCreator
+  public static FalseDimFilter instance()
+  {
+    return INSTANCE;
+  }
+
+  private FalseDimFilter()
+  {
+  }
+
+  @Override
+  public DimFilter optimize()
+  {
+    return this;
+  }
+
+  @Override
+  public Filter toFilter()
+  {
+    return FalseFilter.instance();
+  }
+
+  @Nullable
+  @Override
+  public RangeSet<String> getDimensionRangeSet(String dimension)
+  {
+    return ImmutableRangeSet.of();
+  }
+
+  @Override
+  public Set<String> getRequiredColumns()
+  {
+    return Collections.emptySet();
+  }
+
+  @Override
+  public byte[] getCacheKey()
+  {
+    return new CacheKeyBuilder(DimFilterUtils.FALSE_CACHE_ID).build();

Review comment:
       Done.

##########
File path: 
processing/src/main/java/org/apache/druid/query/filter/FalseDimFilter.java
##########
@@ -0,0 +1,94 @@
+/*
+ * 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.google.common.collect.ImmutableRangeSet;
+import com.google.common.collect.RangeSet;
+import org.apache.druid.query.cache.CacheKeyBuilder;
+import org.apache.druid.segment.filter.FalseFilter;
+
+import javax.annotation.Nullable;
+import java.util.Collections;
+import java.util.Set;
+
+public class FalseDimFilter implements DimFilter
+{
+  private static final FalseDimFilter INSTANCE = new FalseDimFilter();
+
+  @JsonCreator
+  public static FalseDimFilter instance()
+  {
+    return INSTANCE;
+  }
+
+  private FalseDimFilter()
+  {
+  }
+
+  @Override
+  public DimFilter optimize()
+  {
+    return this;
+  }
+
+  @Override
+  public Filter toFilter()
+  {
+    return FalseFilter.instance();
+  }
+
+  @Nullable
+  @Override
+  public RangeSet<String> getDimensionRangeSet(String dimension)
+  {
+    return ImmutableRangeSet.of();
+  }
+
+  @Override
+  public Set<String> getRequiredColumns()
+  {
+    return Collections.emptySet();
+  }
+
+  @Override
+  public byte[] getCacheKey()
+  {
+    return new CacheKeyBuilder(DimFilterUtils.FALSE_CACHE_ID).build();
+  }
+
+  @Override
+  public int hashCode()
+  {
+    return DimFilterUtils.FALSE_CACHE_ID;
+  }
+
+  @Override
+  public boolean equals(Object o)
+  {
+    return o == this;
+  }

Review comment:
       Done.

##########
File path: 
processing/src/main/java/org/apache/druid/query/filter/InDimFilter.java
##########
@@ -73,9 +77,14 @@
   private final Supplier<DruidFloatPredicate> floatPredicateSupplier;
   private final Supplier<DruidDoublePredicate> doublePredicateSupplier;
 
+  @JsonIgnore
+  private byte[] cacheKey;
+
   @JsonCreator
   public InDimFilter(
       @JsonProperty("dimension") String dimension,
+      // This 'values' collection instance can be reused if possible to avoid 
copying a big collection.
+      // Callers should _not_ modify the collection after it is passed to this 
constructor.
       @JsonProperty("values") Collection<String> values,

Review comment:
       Done.

##########
File path: 
processing/src/main/java/org/apache/druid/query/filter/InDimFilter.java
##########
@@ -132,31 +145,40 @@ public FilterTuning getFilterTuning()
   @Override
   public byte[] getCacheKey()
   {
-    boolean hasNull = false;
-    for (String value : values) {
-      if (value == null) {
-        hasNull = true;
-        break;
+    if (cacheKey == null) {
+      final List<String> sortedValues = new ArrayList<>(values);

Review comment:
       Added.




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

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