Search in sources :

Example 6 with Filter

use of org.apache.druid.query.filter.Filter in project druid by druid-io.

the class ExtractionDimFilterTest method testNormal.

@Test
public void testNormal() {
    Filter extractionFilter = new SelectorDimFilter("foo", "extractDimVal", DIM_EXTRACTION_FN).toFilter();
    ImmutableBitmap immutableBitmap = extractionFilter.getBitmapIndex(BITMAP_INDEX_SELECTOR);
    Assert.assertEquals(1, immutableBitmap.size());
}
Also used : SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) ExtractionDimFilter(org.apache.druid.query.filter.ExtractionDimFilter) Filter(org.apache.druid.query.filter.Filter) ImmutableBitmap(org.apache.druid.collections.bitmap.ImmutableBitmap) SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) Test(org.junit.Test)

Example 7 with Filter

use of org.apache.druid.query.filter.Filter in project druid by druid-io.

the class FilterCnfConversionTest method testToCnfFilterThatPullCannotConvertToCnfProperly.

@Test
public void testToCnfFilterThatPullCannotConvertToCnfProperly() {
    final Filter filter = FilterTestUtils.or(FilterTestUtils.and(FilterTestUtils.selector("col1", "val1"), FilterTestUtils.selector("col2", "val2")), FilterTestUtils.and(FilterTestUtils.selector("col1", "val1"), FilterTestUtils.selector("col3", "val3"), FilterTestUtils.selector("col4", "val4")));
    final Filter expectedCnf = FilterTestUtils.and(FilterTestUtils.selector("col1", "val1"), FilterTestUtils.or(FilterTestUtils.selector("col2", "val2"), FilterTestUtils.selector("col3", "val3")), FilterTestUtils.or(FilterTestUtils.selector("col2", "val2"), FilterTestUtils.selector("col4", "val4")));
    assertFilter(filter, expectedCnf, Filters.toCnf(filter));
}
Also used : Filter(org.apache.druid.query.filter.Filter) Test(org.junit.Test)

Example 8 with Filter

use of org.apache.druid.query.filter.Filter in project druid by druid-io.

the class FilterCnfConversionTest method testToCnfCollapsibleBigFilter.

@Test
public void testToCnfCollapsibleBigFilter() {
    List<Filter> ands = new ArrayList<>();
    List<Filter> ors = new ArrayList<>();
    for (int i = 0; i < 12; i++) {
        ands.add(FilterTestUtils.and(FilterTestUtils.selector("col3", "val3"), FilterTestUtils.selector("col4", "val4"), FilterTestUtils.selector("col5", StringUtils.format("val%d", i))));
        ors.add(FilterTestUtils.selector("col5", StringUtils.format("val%d", i)));
    }
    final Filter bigFilter = FilterTestUtils.and(new OrFilter(ands), FilterTestUtils.selector("col1", "val1"), FilterTestUtils.selector("col2", "val2"));
    final Filter expectedCnf = FilterTestUtils.and(FilterTestUtils.selector("col3", "val3"), FilterTestUtils.selector("col4", "val4"), new OrFilter(ors), FilterTestUtils.selector("col1", "val1"), FilterTestUtils.selector("col2", "val2"));
    final Filter cnf = Filters.toCnf(bigFilter);
    assertFilter(bigFilter, expectedCnf, cnf);
}
Also used : Filter(org.apache.druid.query.filter.Filter) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 9 with Filter

use of org.apache.druid.query.filter.Filter in project druid by druid-io.

the class FilterCnfConversionTest method testPushDownNotLeafNot.

@Test
public void testPushDownNotLeafNot() {
    final Filter filter = FilterTestUtils.and(FilterTestUtils.selector("col1", "1"), FilterTestUtils.selector("col2", "2"), FilterTestUtils.not(FilterTestUtils.selector("col3", "3")));
    final Filter pushedDown = HiveCnfHelper.pushDownNot(filter);
    assertFilter(filter, filter, pushedDown);
}
Also used : Filter(org.apache.druid.query.filter.Filter) Test(org.junit.Test)

Example 10 with Filter

use of org.apache.druid.query.filter.Filter in project druid by druid-io.

the class FilterCnfConversionTest method testToCnfWithMuchReducibleFilter.

@Test
public void testToCnfWithMuchReducibleFilter() {
    final Filter muchReducible = FilterTestUtils.and(// should be flattened
    FilterTestUtils.and(FilterTestUtils.and(FilterTestUtils.and(FilterTestUtils.selector("col1", "val1")))), // should be flattened
    FilterTestUtils.and(FilterTestUtils.or(FilterTestUtils.and(FilterTestUtils.selector("col1", "val1")))), // should be flattened
    FilterTestUtils.or(FilterTestUtils.and(FilterTestUtils.or(FilterTestUtils.selector("col1", "val1")))), // should eliminate duplicate filters
    FilterTestUtils.selector("col1", "val1"), FilterTestUtils.selector("col2", "val2"), FilterTestUtils.and(FilterTestUtils.selector("col1", "val1"), FilterTestUtils.selector("col2", "val2")), FilterTestUtils.and(FilterTestUtils.selector("col1", "val1"), FilterTestUtils.and(FilterTestUtils.selector("col2", "val2"), FilterTestUtils.selector("col1", "val1"))));
    final Filter expected = FilterTestUtils.and(FilterTestUtils.selector("col1", "val1"), FilterTestUtils.selector("col2", "val2"));
    final Filter cnf = Filters.toCnf(muchReducible);
    assertFilter(muchReducible, expected, cnf);
}
Also used : Filter(org.apache.druid.query.filter.Filter) Test(org.junit.Test)

Aggregations

Filter (org.apache.druid.query.filter.Filter)127 Test (org.junit.Test)88 SelectorFilter (org.apache.druid.segment.filter.SelectorFilter)74 ExpressionDimFilter (org.apache.druid.query.filter.ExpressionDimFilter)64 JoinFilterPreAnalysis (org.apache.druid.segment.join.filter.JoinFilterPreAnalysis)63 OrFilter (org.apache.druid.segment.filter.OrFilter)52 AndFilter (org.apache.druid.segment.filter.AndFilter)47 BoundDimFilter (org.apache.druid.query.filter.BoundDimFilter)43 InDimFilter (org.apache.druid.query.filter.InDimFilter)43 BoundFilter (org.apache.druid.segment.filter.BoundFilter)42 FalseFilter (org.apache.druid.segment.filter.FalseFilter)41 SelectorDimFilter (org.apache.druid.query.filter.SelectorDimFilter)39 OrDimFilter (org.apache.druid.query.filter.OrDimFilter)36 JoinFilterSplit (org.apache.druid.segment.join.filter.JoinFilterSplit)35 ArrayList (java.util.ArrayList)19 DimFilter (org.apache.druid.query.filter.DimFilter)15 IndexedTableJoinable (org.apache.druid.segment.join.table.IndexedTableJoinable)13 AndDimFilter (org.apache.druid.query.filter.AndDimFilter)10 BooleanFilter (org.apache.druid.query.filter.BooleanFilter)10 Cursor (org.apache.druid.segment.Cursor)10