Search in sources :

Example 1 with OrDimFilter

use of io.druid.query.filter.OrDimFilter in project druid by druid-io.

the class FilterPartitionTest method testDistributeOrCNF.

@Test
public void testDistributeOrCNF() {
    DimFilter dimFilter1 = new OrDimFilter(Arrays.<DimFilter>asList(new SelectorDimFilter("dim0", "6", null), new AndDimFilter(Arrays.<DimFilter>asList(new NoBitmapSelectorDimFilter("dim1", "def", null), new SelectorDimFilter("dim2", "c", null)))));
    Filter filter1 = dimFilter1.toFilter();
    Filter filter1CNF = Filters.convertToCNF(filter1);
    Assert.assertEquals(AndFilter.class, filter1CNF.getClass());
    Assert.assertEquals(2, ((AndFilter) filter1CNF).getFilters().size());
    assertFilterMatches(dimFilter1, ImmutableList.of("4", "6"));
    DimFilter dimFilter2 = new OrDimFilter(Arrays.<DimFilter>asList(new SelectorDimFilter("dim0", "2", null), new SelectorDimFilter("dim0", "3", null), new AndDimFilter(Arrays.<DimFilter>asList(new NoBitmapSelectorDimFilter("dim1", "HELLO", null), new SelectorDimFilter("dim2", "foo", null)))));
    assertFilterMatches(dimFilter2, ImmutableList.of("2", "3", "7"));
    DimFilter dimFilter3 = new OrDimFilter(Arrays.<DimFilter>asList(dimFilter1, dimFilter2, new AndDimFilter(Arrays.<DimFilter>asList(new NoBitmapSelectorDimFilter("dim1", "1", null), new SelectorDimFilter("dim2", "foo", null)))));
    assertFilterMatches(dimFilter3, ImmutableList.of("2", "3", "4", "6", "7", "9"));
}
Also used : AndDimFilter(io.druid.query.filter.AndDimFilter) OrDimFilter(io.druid.query.filter.OrDimFilter) SelectorDimFilter(io.druid.query.filter.SelectorDimFilter) DimFilter(io.druid.query.filter.DimFilter) Filter(io.druid.query.filter.Filter) AndDimFilter(io.druid.query.filter.AndDimFilter) SelectorDimFilter(io.druid.query.filter.SelectorDimFilter) OrDimFilter(io.druid.query.filter.OrDimFilter) OrDimFilter(io.druid.query.filter.OrDimFilter) SelectorDimFilter(io.druid.query.filter.SelectorDimFilter) DimFilter(io.druid.query.filter.DimFilter) AndDimFilter(io.druid.query.filter.AndDimFilter) Test(org.junit.Test)

Example 2 with OrDimFilter

use of io.druid.query.filter.OrDimFilter in project druid by druid-io.

the class FilterPartitionTest method testMissingColumnSpecifiedInDimensionList.

@Test
public void testMissingColumnSpecifiedInDimensionList() {
    assertFilterMatches(new NoBitmapSelectorDimFilter("dim3", null, null), ImmutableList.of("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"));
    assertFilterMatches(new NoBitmapSelectorDimFilter("dim3", "", null), ImmutableList.of("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"));
    assertFilterMatches(new NoBitmapSelectorDimFilter("dim3", "a", null), ImmutableList.<String>of());
    assertFilterMatches(new NoBitmapSelectorDimFilter("dim3", "b", null), ImmutableList.<String>of());
    assertFilterMatches(new NoBitmapSelectorDimFilter("dim3", "c", null), ImmutableList.<String>of());
    assertFilterMatches(new OrDimFilter(Arrays.<DimFilter>asList(new NoBitmapSelectorDimFilter("dim1", "abc", null), new SelectorDimFilter("dim3", "NOTHERE", null))), ImmutableList.<String>of("5", "8"));
    assertFilterMatches(new OrDimFilter(Arrays.<DimFilter>asList(new NoBitmapSelectorDimFilter("dim1", "abc", null), new SelectorDimFilter("dim3", null, null))), ImmutableList.of("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"));
    assertFilterMatches(new NoBitmapSelectorDimFilter("dim3", "super-null", JS_EXTRACTION_FN), ImmutableList.of("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"));
    assertFilterMatches(new NoBitmapSelectorDimFilter("dim3", "super-null", JS_EXTRACTION_FN), ImmutableList.of("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"));
    assertFilterMatches(new NoBitmapSelectorDimFilter("dim3", "a", JS_EXTRACTION_FN), ImmutableList.<String>of());
    assertFilterMatches(new NoBitmapSelectorDimFilter("dim3", "b", JS_EXTRACTION_FN), ImmutableList.<String>of());
    assertFilterMatches(new NoBitmapSelectorDimFilter("dim3", "c", JS_EXTRACTION_FN), ImmutableList.<String>of());
    assertFilterMatches(new OrDimFilter(Arrays.<DimFilter>asList(new NoBitmapSelectorDimFilter("dim1", "super-abc", JS_EXTRACTION_FN), new SelectorDimFilter("dim3", "NOTHERE", JS_EXTRACTION_FN))), ImmutableList.<String>of("5", "8"));
    assertFilterMatches(new OrDimFilter(Arrays.<DimFilter>asList(new NoBitmapSelectorDimFilter("dim1", "abc", JS_EXTRACTION_FN), new SelectorDimFilter("dim3", "super-null", JS_EXTRACTION_FN))), ImmutableList.of("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"));
}
Also used : SelectorDimFilter(io.druid.query.filter.SelectorDimFilter) OrDimFilter(io.druid.query.filter.OrDimFilter) OrDimFilter(io.druid.query.filter.OrDimFilter) SelectorDimFilter(io.druid.query.filter.SelectorDimFilter) DimFilter(io.druid.query.filter.DimFilter) AndDimFilter(io.druid.query.filter.AndDimFilter) Test(org.junit.Test)

Example 3 with OrDimFilter

use of io.druid.query.filter.OrDimFilter in project druid by druid-io.

the class FilterPartitionTest method testOrPostFilterWithNulls.

@Test
public void testOrPostFilterWithNulls() {
    assertFilterMatches(new OrDimFilter(Arrays.<DimFilter>asList(new SelectorDimFilter("dim2", "a", null), new NoBitmapSelectorDimFilter("dim1", null, null))), ImmutableList.of("0", "3"));
    assertFilterMatches(new OrDimFilter(Arrays.<DimFilter>asList(new SelectorDimFilter("dim1", "abc", null), new NoBitmapSelectorDimFilter("dim2", null, null))), ImmutableList.of("1", "2", "5", "8"));
    assertFilterMatches(new OrDimFilter(Arrays.<DimFilter>asList(new SelectorDimFilter("dim1", "2", null), new NoBitmapSelectorDimFilter("dim2", null, null))), ImmutableList.of("1", "2", "5"));
    assertFilterMatches(new OrDimFilter(Arrays.<DimFilter>asList(new SelectorDimFilter("dim1", "INVALID_VALUE", null), new NoBitmapSelectorDimFilter("dim2", "foo", null))), ImmutableList.of("7", "9"));
    assertFilterMatches(new OrDimFilter(Arrays.<DimFilter>asList(new SelectorDimFilter("dim1", "HELLO", null), new NoBitmapSelectorDimFilter("dim2", "bar", null))), ImmutableList.<String>of("7", "8", "9"));
    assertFilterMatches(new OrDimFilter(Arrays.<DimFilter>asList(new NoBitmapSelectorDimFilter("dim1", "HELLO", null), new SelectorDimFilter("dim2", "NOT_A_VALUE", null))), ImmutableList.<String>of("7"));
    assertFilterMatches(new OrDimFilter(Arrays.<DimFilter>asList(new NoBitmapSelectorDimFilter("dim1", "INVALID", null), new SelectorDimFilter("dim2", "NOT_A_VALUE", null))), ImmutableList.<String>of());
    assertFilterMatches(new OrDimFilter(Arrays.<DimFilter>asList(new SelectorDimFilter("dim2", "super-a", JS_EXTRACTION_FN), new NoBitmapSelectorDimFilter("dim1", "super-null", JS_EXTRACTION_FN))), ImmutableList.of("0", "3"));
    assertFilterMatches(new OrDimFilter(Arrays.<DimFilter>asList(new SelectorDimFilter("dim1", "super-abc", JS_EXTRACTION_FN), new NoBitmapSelectorDimFilter("dim2", "super-null", JS_EXTRACTION_FN))), ImmutableList.of("1", "2", "5", "8"));
    assertFilterMatches(new OrDimFilter(Arrays.<DimFilter>asList(new SelectorDimFilter("dim1", "super-2", JS_EXTRACTION_FN), new NoBitmapSelectorDimFilter("dim2", "super-null", JS_EXTRACTION_FN))), ImmutableList.of("1", "2", "5"));
    assertFilterMatches(new OrDimFilter(Arrays.<DimFilter>asList(new SelectorDimFilter("dim1", "INVALID_VALUE", JS_EXTRACTION_FN), new NoBitmapSelectorDimFilter("dim2", "super-foo", JS_EXTRACTION_FN))), ImmutableList.of("7", "9"));
    assertFilterMatches(new OrDimFilter(Arrays.<DimFilter>asList(new SelectorDimFilter("dim1", "super-HELLO", JS_EXTRACTION_FN), new NoBitmapSelectorDimFilter("dim2", "super-bar", JS_EXTRACTION_FN))), ImmutableList.<String>of("7", "8", "9"));
    assertFilterMatches(new OrDimFilter(Arrays.<DimFilter>asList(new NoBitmapSelectorDimFilter("dim1", "super-HELLO", JS_EXTRACTION_FN), new SelectorDimFilter("dim2", "NOT_A_VALUE", null))), ImmutableList.<String>of("7"));
    assertFilterMatches(new OrDimFilter(Arrays.<DimFilter>asList(new NoBitmapSelectorDimFilter("dim1", "INVALID", JS_EXTRACTION_FN), new SelectorDimFilter("dim2", "NOT_A_VALUE", JS_EXTRACTION_FN))), ImmutableList.<String>of());
}
Also used : SelectorDimFilter(io.druid.query.filter.SelectorDimFilter) OrDimFilter(io.druid.query.filter.OrDimFilter) OrDimFilter(io.druid.query.filter.OrDimFilter) SelectorDimFilter(io.druid.query.filter.SelectorDimFilter) DimFilter(io.druid.query.filter.DimFilter) AndDimFilter(io.druid.query.filter.AndDimFilter) Test(org.junit.Test)

Example 4 with OrDimFilter

use of io.druid.query.filter.OrDimFilter in project druid by druid-io.

the class FilterPartitionTest method testMissingColumnNotSpecifiedInDimensionList.

@Test
public void testMissingColumnNotSpecifiedInDimensionList() {
    assertFilterMatches(new NoBitmapSelectorDimFilter("dim4", null, null), ImmutableList.of("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"));
    assertFilterMatches(new NoBitmapSelectorDimFilter("dim4", "", null), ImmutableList.of("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"));
    assertFilterMatches(new NoBitmapSelectorDimFilter("dim4", "a", null), ImmutableList.<String>of());
    assertFilterMatches(new NoBitmapSelectorDimFilter("dim4", "b", null), ImmutableList.<String>of());
    assertFilterMatches(new NoBitmapSelectorDimFilter("dim4", "c", null), ImmutableList.<String>of());
    assertFilterMatches(new OrDimFilter(Arrays.<DimFilter>asList(new NoBitmapSelectorDimFilter("dim1", "abc", null), new SelectorDimFilter("dim4", null, null))), ImmutableList.of("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"));
    assertFilterMatches(new OrDimFilter(Arrays.<DimFilter>asList(new NoBitmapSelectorDimFilter("dim4", null, null), new SelectorDimFilter("dim1", "abc", null))), ImmutableList.of("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"));
    assertFilterMatches(new NoBitmapSelectorDimFilter("dim4", "super-null", JS_EXTRACTION_FN), ImmutableList.of("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"));
    assertFilterMatches(new NoBitmapSelectorDimFilter("dim4", "super-null", JS_EXTRACTION_FN), ImmutableList.of("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"));
    assertFilterMatches(new NoBitmapSelectorDimFilter("dim4", "a", JS_EXTRACTION_FN), ImmutableList.<String>of());
    assertFilterMatches(new NoBitmapSelectorDimFilter("dim4", "b", JS_EXTRACTION_FN), ImmutableList.<String>of());
    assertFilterMatches(new NoBitmapSelectorDimFilter("dim4", "c", JS_EXTRACTION_FN), ImmutableList.<String>of());
    assertFilterMatches(new OrDimFilter(Arrays.<DimFilter>asList(new NoBitmapSelectorDimFilter("dim1", "super-abc", JS_EXTRACTION_FN), new SelectorDimFilter("dim4", "super-null", JS_EXTRACTION_FN))), ImmutableList.of("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"));
    assertFilterMatches(new OrDimFilter(Arrays.<DimFilter>asList(new NoBitmapSelectorDimFilter("dim4", "super-null", JS_EXTRACTION_FN), new SelectorDimFilter("dim1", "super-abc", JS_EXTRACTION_FN))), ImmutableList.of("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"));
}
Also used : SelectorDimFilter(io.druid.query.filter.SelectorDimFilter) OrDimFilter(io.druid.query.filter.OrDimFilter) OrDimFilter(io.druid.query.filter.OrDimFilter) SelectorDimFilter(io.druid.query.filter.SelectorDimFilter) DimFilter(io.druid.query.filter.DimFilter) AndDimFilter(io.druid.query.filter.AndDimFilter) Test(org.junit.Test)

Example 5 with OrDimFilter

use of io.druid.query.filter.OrDimFilter in project druid by druid-io.

the class Expressions method toFilter.

/**
   * Translates "condition" to a Druid filter, or returns null if we cannot translate the condition.
   *
   * @param plannerContext planner context
   * @param rowSignature   row signature of the dataSource to be filtered
   * @param expression     Calcite row expression
   */
public static DimFilter toFilter(final DruidOperatorTable operatorTable, final PlannerContext plannerContext, final RowSignature rowSignature, final RexNode expression) {
    if (expression.getKind() == SqlKind.AND || expression.getKind() == SqlKind.OR || expression.getKind() == SqlKind.NOT) {
        final List<DimFilter> filters = Lists.newArrayList();
        for (final RexNode rexNode : ((RexCall) expression).getOperands()) {
            final DimFilter nextFilter = toFilter(operatorTable, plannerContext, rowSignature, rexNode);
            if (nextFilter == null) {
                return null;
            }
            filters.add(nextFilter);
        }
        if (expression.getKind() == SqlKind.AND) {
            return new AndDimFilter(filters);
        } else if (expression.getKind() == SqlKind.OR) {
            return new OrDimFilter(filters);
        } else {
            assert expression.getKind() == SqlKind.NOT;
            return new NotDimFilter(Iterables.getOnlyElement(filters));
        }
    } else {
        // Handle filter conditions on everything else.
        return toLeafFilter(operatorTable, plannerContext, rowSignature, expression);
    }
}
Also used : RexCall(org.apache.calcite.rex.RexCall) NotDimFilter(io.druid.query.filter.NotDimFilter) AndDimFilter(io.druid.query.filter.AndDimFilter) OrDimFilter(io.druid.query.filter.OrDimFilter) LikeDimFilter(io.druid.query.filter.LikeDimFilter) OrDimFilter(io.druid.query.filter.OrDimFilter) DimFilter(io.druid.query.filter.DimFilter) NotDimFilter(io.druid.query.filter.NotDimFilter) AndDimFilter(io.druid.query.filter.AndDimFilter) RexNode(org.apache.calcite.rex.RexNode)

Aggregations

OrDimFilter (io.druid.query.filter.OrDimFilter)23 DimFilter (io.druid.query.filter.DimFilter)18 AndDimFilter (io.druid.query.filter.AndDimFilter)17 SelectorDimFilter (io.druid.query.filter.SelectorDimFilter)15 BoundDimFilter (io.druid.query.filter.BoundDimFilter)13 Test (org.junit.Test)12 List (java.util.List)8 DefaultDimensionSpec (io.druid.query.dimension.DefaultDimensionSpec)7 ExtractionDimensionSpec (io.druid.query.dimension.ExtractionDimensionSpec)6 InDimFilter (io.druid.query.filter.InDimFilter)6 NotDimFilter (io.druid.query.filter.NotDimFilter)6 ArrayList (java.util.ArrayList)6 Row (io.druid.data.input.Row)5 JavaScriptDimFilter (io.druid.query.filter.JavaScriptDimFilter)5 RegexDimFilter (io.druid.query.filter.RegexDimFilter)5 SearchQueryDimFilter (io.druid.query.filter.SearchQueryDimFilter)5 TimeFormatExtractionFn (io.druid.query.extraction.TimeFormatExtractionFn)4 LongSumAggregatorFactory (io.druid.query.aggregation.LongSumAggregatorFactory)3 DimensionSpec (io.druid.query.dimension.DimensionSpec)3 ListFilteredDimensionSpec (io.druid.query.dimension.ListFilteredDimensionSpec)3