From bf2a31a5bc1549e5c9a246e963ab74efefa59667 Mon Sep 17 00:00:00 2001 From: scrawfor Date: Thu, 28 Jun 2018 14:52:45 -0400 Subject: [PATCH] Add new 'true' filter which always returns true. (#5711) * Add new 'true' filter which always returns true. * Add support for bitmap index. * Adds documentation. * Removes No-op Filter --- docs/content/querying/filters.md | 7 +- .../java/io/druid/query/filter/DimFilter.java | 2 +- .../io/druid/query/filter/DimFilterUtils.java | 1 + .../io/druid/query/filter/TrueDimFilter.java | 54 ++++++++++++++ .../io/druid/segment/filter/TrueFilter.java | 74 +++++++++++++++++++ 5 files changed, 133 insertions(+), 5 deletions(-) create mode 100644 processing/src/main/java/io/druid/query/filter/TrueDimFilter.java create mode 100644 processing/src/main/java/io/druid/segment/filter/TrueFilter.java diff --git a/docs/content/querying/filters.md b/docs/content/querying/filters.md index d158b893d36..daa62f370ce 100644 --- a/docs/content/querying/filters.md +++ b/docs/content/querying/filters.md @@ -488,10 +488,9 @@ Filtering on a set of ISO 8601 intervals: } ``` - -### Noop Filter -The noop filter is a filter which applies no conditions to your query. Useful if you need to disable other filters when queries are generated programatically. +### True Filter +The true filter is a filter which matches all values. It can be used to temporarily disable other filters without removing the filter. ```json -{ "type" : "noop" } +{ "type" : "true" } ``` \ No newline at end of file diff --git a/processing/src/main/java/io/druid/query/filter/DimFilter.java b/processing/src/main/java/io/druid/query/filter/DimFilter.java index 3b9dc17642c..218affe8471 100644 --- a/processing/src/main/java/io/druid/query/filter/DimFilter.java +++ b/processing/src/main/java/io/druid/query/filter/DimFilter.java @@ -45,7 +45,7 @@ import java.util.HashSet; @JsonSubTypes.Type(name = "interval", value = IntervalDimFilter.class), @JsonSubTypes.Type(name = "like", value = LikeDimFilter.class), @JsonSubTypes.Type(name = "expression", value = ExpressionDimFilter.class), - @JsonSubTypes.Type(name = "noop", value = NoopDimFilter.class) + @JsonSubTypes.Type(name = "true", value = TrueDimFilter.class) }) public interface DimFilter extends Cacheable { diff --git a/processing/src/main/java/io/druid/query/filter/DimFilterUtils.java b/processing/src/main/java/io/druid/query/filter/DimFilterUtils.java index 25c991662ed..337a5819cdc 100644 --- a/processing/src/main/java/io/druid/query/filter/DimFilterUtils.java +++ b/processing/src/main/java/io/druid/query/filter/DimFilterUtils.java @@ -52,6 +52,7 @@ public class DimFilterUtils static final byte LIKE_CACHE_ID = 0xC; static final byte COLUMN_COMPARISON_CACHE_ID = 0xD; static final byte EXPRESSION_CACHE_ID = 0xE; + static final byte TRUE_CACHE_ID = 0xF; public static final byte STRING_SEPARATOR = (byte) 0xFF; static byte[] computeCacheKey(byte cacheIdKey, List filters) diff --git a/processing/src/main/java/io/druid/query/filter/TrueDimFilter.java b/processing/src/main/java/io/druid/query/filter/TrueDimFilter.java new file mode 100644 index 00000000000..5294bfda573 --- /dev/null +++ b/processing/src/main/java/io/druid/query/filter/TrueDimFilter.java @@ -0,0 +1,54 @@ +/* + * Licensed to Metamarkets Group Inc. (Metamarkets) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Metamarkets 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 io.druid.query.filter; + +import com.google.common.collect.RangeSet; +import io.druid.segment.filter.TrueFilter; + +import java.nio.ByteBuffer; + +/** + */ +public class TrueDimFilter implements DimFilter +{ + @Override + public byte[] getCacheKey() + { + return ByteBuffer.allocate(1).put(DimFilterUtils.TRUE_CACHE_ID).array(); + } + + @Override + public DimFilter optimize() + { + return this; + } + + @Override + public Filter toFilter() + { + return new TrueFilter(); + } + + @Override + public RangeSet getDimensionRangeSet(String dimension) + { + return null; + } +} diff --git a/processing/src/main/java/io/druid/segment/filter/TrueFilter.java b/processing/src/main/java/io/druid/segment/filter/TrueFilter.java new file mode 100644 index 00000000000..22e347dcfde --- /dev/null +++ b/processing/src/main/java/io/druid/segment/filter/TrueFilter.java @@ -0,0 +1,74 @@ +/* + * Licensed to Metamarkets Group Inc. (Metamarkets) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Metamarkets 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 io.druid.segment.filter; + +import io.druid.query.BitmapResultFactory; +import io.druid.query.filter.BitmapIndexSelector; +import io.druid.query.filter.Filter; +import io.druid.query.filter.ValueMatcher; +import io.druid.segment.ColumnSelector; +import io.druid.segment.ColumnSelectorFactory; + +/** + */ +public class TrueFilter implements Filter +{ + public TrueFilter() + { + } + + @Override + public T getBitmapResult(BitmapIndexSelector selector, BitmapResultFactory bitmapResultFactory) + { + return bitmapResultFactory.wrapAllTrue(Filters.allTrue(selector)); + } + + @Override + public ValueMatcher makeMatcher(ColumnSelectorFactory factory) + { + return TrueValueMatcher.instance(); + } + + @Override + public boolean supportsBitmapIndex(BitmapIndexSelector selector) + { + return true; + } + + @Override + public boolean supportsSelectivityEstimation( + ColumnSelector columnSelector, BitmapIndexSelector indexSelector + ) + { + return true; + } + + @Override + public double estimateSelectivity(BitmapIndexSelector indexSelector) + { + return 1; + } + + @Override + public String toString() + { + return "true"; + } +}