Package org.apache.druid.query.filter
Class InDimFilter
- java.lang.Object
-
- org.apache.druid.query.filter.AbstractOptimizableDimFilter
-
- org.apache.druid.query.filter.InDimFilter
-
public class InDimFilter extends AbstractOptimizableDimFilter implements Filter
Approximately like the SQL 'IN' filter, with the main difference being that this will match NULL values if contained in the values list instead of ignoring them.This filter specifies all match values as a sorted string set; matching against other column types must incur the cost of converting values to check for matches. For the most part,
TypedInFiltershould be used instead.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classInDimFilter.InFilterDruidPredicateFactorystatic classInDimFilter.ValuesSet-
Nested classes/interfaces inherited from interface org.apache.druid.query.filter.DimFilter
DimFilter.DimFilterToStringBuilder
-
-
Constructor Summary
Constructors Constructor Description InDimFilter(String dimension, Collection<String> values, ExtractionFn extractionFn)Creates a new filter without an extraction function or any special filter tuning.InDimFilter(String dimension, Set<String> values)Creates a new filter without an extraction function or any special filter tuning.InDimFilter(String dimension, InDimFilter.ValuesSet values, ExtractionFn extractionFn, FilterTuning filterTuning)Creates a new filter.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanVectorizeMatcher(ColumnInspector inspector)Returns true if this filter can produce a vectorized matcher from its "makeVectorMatcher" method.booleanequals(Object o)BitmapColumnIndexgetBitmapColumnIndex(ColumnIndexSelector selector)Returns aBitmapColumnIndexif this filter supports using a bitmap index for filtering for the given inputColumnIndexSelector.byte[]getCacheKey()Get a byte array used as a cache key.StringgetDimension()com.google.common.collect.RangeSet<String>getDimensionRangeSet(String dimension)Returns a RangeSet that represents the possible range of the input dimension for this DimFilter.This is applicable to filters that use dimensions such as select, in, bound, and logical filters such as and, or, not.ExtractionFngetExtractionFn()FilterTuninggetFilterTuning()Set<String>getRequiredColumns()Set of columns used by a filter.SortedSet<String>getValues()inthashCode()ValueMatchermakeMatcher(ColumnSelectorFactory factory)Get aValueMatcherthat applies this filter to row values.VectorValueMatchermakeVectorMatcher(VectorColumnSelectorFactory factory)Get aVectorValueMatcherthat applies this filter to row vectors.DimFilteroptimize(boolean mayIncludeUnknown)Returns an optimized version of this filter.static InDimFilter.ValuesSetoptimizeLookup(InDimFilter inFilter, boolean mayIncludeUnknown)If the provided "in" filter uses aLookupExtractionFnthat can be reversed, then return the matching set of keys as aInDimFilter.ValuesSet.static InDimFilter.ValuesSetoptimizeLookup(InDimFilter inFilter, boolean mayIncludeUnknown, int maxSize)If the provided "in" filter uses aLookupExtractionFnthat can be reversed, then return the matching set of keys as aInDimFilter.ValuesSet.FilterrewriteRequiredColumns(Map<String,String> columnRewrites)Return a copy of this filter that is identical to the this filter except that it operates on different columns, based on a renaming map where the key is the column to be renamed in the filter, and the value is the new column name.booleansupportsRequiredColumnRewrite()Returns true is this filter is able to return a copy of this filter that is identical to this filter except that it operates on different columns, based on a renaming map.FiltertoFilter()Returns a Filter that implements this DimFilter.StringtoString()-
Methods inherited from class org.apache.druid.query.filter.AbstractOptimizableDimFilter
toOptimizedFilter
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.druid.query.filter.Filter
makeFilterBundle
-
-
-
-
Constructor Detail
-
InDimFilter
public InDimFilter(String dimension, InDimFilter.ValuesSet values, @Nullable ExtractionFn extractionFn, @Nullable FilterTuning filterTuning)
Creates a new filter.- Parameters:
dimension- column to searchvalues- set of values to match. This collection may be reused to avoid copying a big collection. Therefore, callers should not modify the collection after it is passed to this constructor.extractionFn- extraction function to apply to the column before checking against "values"filterTuning- optional tuning
-
InDimFilter
public InDimFilter(String dimension, Set<String> values)
Creates a new filter without an extraction function or any special filter tuning.- Parameters:
dimension- column to searchvalues- set of values to match. If this collection is aSortedSet, it may be reused to avoid copying a big collection. Therefore, callers should not modify the collection after it is passed to this constructor.
-
InDimFilter
public InDimFilter(String dimension, Collection<String> values, @Nullable ExtractionFn extractionFn)
Creates a new filter without an extraction function or any special filter tuning.- Parameters:
dimension- column to searchvalues- set of values to match. If this collection is aSortedSet, it may be reused to avoid copying a big collection. Therefore, callers should not modify the collection after it is passed to this constructor.extractionFn- extraction function to apply to the column before checking against "values"
-
-
Method Detail
-
getDimension
public String getDimension()
-
getExtractionFn
@Nullable public ExtractionFn getExtractionFn()
-
getFilterTuning
@Nullable public FilterTuning getFilterTuning()
-
getCacheKey
public byte[] getCacheKey()
Description copied from interface:CacheableGet a byte array used as a cache key.- Specified by:
getCacheKeyin interfaceCacheable- Returns:
- a cache key
-
optimize
public DimFilter optimize(boolean mayIncludeUnknown)
Description copied from interface:DimFilterReturns an optimized version of this filter.- Specified by:
optimizein interfaceDimFilter- Overrides:
optimizein classAbstractOptimizableDimFilter- Parameters:
mayIncludeUnknown- whether the optimized filter may need to operate in "includeUnknown" mode. SeeNullHandling.useThreeValueLogic().
-
toFilter
public Filter toFilter()
Description copied from interface:DimFilterReturns a Filter that implements this DimFilter. This does not generally involve optimizing the DimFilter, so it does make sense to optimize first and then call toFilter on the resulting DimFilter.
-
getDimensionRangeSet
@Nullable public com.google.common.collect.RangeSet<String> getDimensionRangeSet(String dimension)
Description copied from interface:DimFilterReturns a RangeSet that represents the possible range of the input dimension for this DimFilter.This is applicable to filters that use dimensions such as select, in, bound, and logical filters such as and, or, not. Null represents that the range cannot be determined, and will be returned for filters such as javascript and regex where there's no easy way to determine the filtered range. It is treated the same way as an all range in most cases, however there are some subtle difference at logical filters such as not filter, where complement of all is nothing while complement of null is still null.- Specified by:
getDimensionRangeSetin interfaceDimFilter- Parameters:
dimension- name of the dimension to get range for- Returns:
- a RangeSet that represent the possible range of the input dimension, or null if it is not possible to determine for this DimFilter.
-
getRequiredColumns
public Set<String> getRequiredColumns()
Description copied from interface:FilterSet of columns used by a filter.- Specified by:
getRequiredColumnsin interfaceDimFilter- Specified by:
getRequiredColumnsin interfaceFilter- Returns:
- a HashSet that represents all columns' name which the DimFilter required to do filter.
-
getBitmapColumnIndex
@Nullable public BitmapColumnIndex getBitmapColumnIndex(ColumnIndexSelector selector)
Description copied from interface:FilterReturns aBitmapColumnIndexif this filter supports using a bitmap index for filtering for the given inputColumnIndexSelector. TheBitmapColumnIndexcan be used to compute into a bitmap indicating rows that match this filter resultBitmapColumnIndex.computeBitmapResult(BitmapResultFactory, boolean), or examine details about the index prior to computing it, viaBitmapColumnIndex.getIndexCapabilities().- Specified by:
getBitmapColumnIndexin interfaceFilter- Parameters:
selector- Object used to create BitmapColumnIndex- Returns:
- BitmapColumnIndex that can build ImmutableBitmap of matched row numbers
-
makeMatcher
public ValueMatcher makeMatcher(ColumnSelectorFactory factory)
Description copied from interface:FilterGet aValueMatcherthat applies this filter to row values.- Specified by:
makeMatcherin interfaceFilter- Parameters:
factory- Object used to create ValueMatchers- Returns:
- ValueMatcher that applies this filter to row values.
-
makeVectorMatcher
public VectorValueMatcher makeVectorMatcher(VectorColumnSelectorFactory factory)
Description copied from interface:FilterGet aVectorValueMatcherthat applies this filter to row vectors.- Specified by:
makeVectorMatcherin interfaceFilter- Parameters:
factory- Object used to create ValueMatchers- Returns:
- VectorValueMatcher that applies this filter to row vectors.
-
canVectorizeMatcher
public boolean canVectorizeMatcher(ColumnInspector inspector)
Description copied from interface:FilterReturns true if this filter can produce a vectorized matcher from its "makeVectorMatcher" method.- Specified by:
canVectorizeMatcherin interfaceFilter- Parameters:
inspector- Supplies type information for the selectors this filter will match against
-
supportsRequiredColumnRewrite
public boolean supportsRequiredColumnRewrite()
Description copied from interface:FilterReturns true is this filter is able to return a copy of this filter that is identical to this filter except that it operates on different columns, based on a renaming map.- Specified by:
supportsRequiredColumnRewritein interfaceFilter
-
rewriteRequiredColumns
public Filter rewriteRequiredColumns(Map<String,String> columnRewrites)
Description copied from interface:FilterReturn a copy of this filter that is identical to the this filter except that it operates on different columns, based on a renaming map where the key is the column to be renamed in the filter, and the value is the new column name. For example, if I have a filter (A = hello), and I have a renaming map (A -> B), this should return the filter (B = hello)- Specified by:
rewriteRequiredColumnsin interfaceFilter- Parameters:
columnRewrites- Column rewrite map- Returns:
- Copy of this filter that operates on new columns based on the rewrite map
-
optimizeLookup
public static InDimFilter.ValuesSet optimizeLookup(InDimFilter inFilter, boolean mayIncludeUnknown)
If the provided "in" filter uses aLookupExtractionFnthat can be reversed, then return the matching set of keys as aInDimFilter.ValuesSet. Otherwise return null.- Parameters:
inFilter- in filtermayIncludeUnknown- same as the argument tooptimize(boolean)
-
optimizeLookup
@Nullable public static InDimFilter.ValuesSet optimizeLookup(InDimFilter inFilter, boolean mayIncludeUnknown, int maxSize)
If the provided "in" filter uses aLookupExtractionFnthat can be reversed, then return the matching set of keys as aInDimFilter.ValuesSet. Otherwise return null.- Parameters:
inFilter- in filtermayIncludeUnknown- same as the argument tooptimize(boolean)maxSize- maximum number of values in the returned filter
-
-