mirror of https://github.com/apache/druid.git
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
This commit is contained in:
parent
d857345b7d
commit
bf2a31a5bc
|
@ -488,10 +488,9 @@ Filtering on a set of ISO 8601 intervals:
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### True Filter
|
||||||
### Noop Filter
|
The true filter is a filter which matches all values. It can be used to temporarily disable other filters without removing the 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.
|
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{ "type" : "noop" }
|
{ "type" : "true" }
|
||||||
```
|
```
|
|
@ -45,7 +45,7 @@ import java.util.HashSet;
|
||||||
@JsonSubTypes.Type(name = "interval", value = IntervalDimFilter.class),
|
@JsonSubTypes.Type(name = "interval", value = IntervalDimFilter.class),
|
||||||
@JsonSubTypes.Type(name = "like", value = LikeDimFilter.class),
|
@JsonSubTypes.Type(name = "like", value = LikeDimFilter.class),
|
||||||
@JsonSubTypes.Type(name = "expression", value = ExpressionDimFilter.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
|
public interface DimFilter extends Cacheable
|
||||||
{
|
{
|
||||||
|
|
|
@ -52,6 +52,7 @@ public class DimFilterUtils
|
||||||
static final byte LIKE_CACHE_ID = 0xC;
|
static final byte LIKE_CACHE_ID = 0xC;
|
||||||
static final byte COLUMN_COMPARISON_CACHE_ID = 0xD;
|
static final byte COLUMN_COMPARISON_CACHE_ID = 0xD;
|
||||||
static final byte EXPRESSION_CACHE_ID = 0xE;
|
static final byte EXPRESSION_CACHE_ID = 0xE;
|
||||||
|
static final byte TRUE_CACHE_ID = 0xF;
|
||||||
public static final byte STRING_SEPARATOR = (byte) 0xFF;
|
public static final byte STRING_SEPARATOR = (byte) 0xFF;
|
||||||
|
|
||||||
static byte[] computeCacheKey(byte cacheIdKey, List<DimFilter> filters)
|
static byte[] computeCacheKey(byte cacheIdKey, List<DimFilter> filters)
|
||||||
|
|
|
@ -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<String> getDimensionRangeSet(String dimension)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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> T getBitmapResult(BitmapIndexSelector selector, BitmapResultFactory<T> 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";
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue