Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions docs/content/querying/filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
```
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
@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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<DimFilter> filters)
Expand Down
54 changes: 54 additions & 0 deletions processing/src/main/java/io/druid/query/filter/TrueDimFilter.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
74 changes: 74 additions & 0 deletions processing/src/main/java/io/druid/segment/filter/TrueFilter.java
Original file line number Diff line number Diff line change
@@ -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";
}
}