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



##########
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:
       The use of this and `OrDimFilter` are prevalent in unit tests so I 
believe they are being tested somewhere (I didn't change the logic of the lines 
you mentioned). But I can add some more tests.

##########
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:
       Good point. Will add it.

##########
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:
       👍 




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