Search in sources :

Example 16 with RegexDimFilter

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

the class RegexFilterTest method testMissingColumnSpecifiedInDimensionList.

@Test
public void testMissingColumnSpecifiedInDimensionList() {
    assertFilterMatches(new RegexDimFilter("dim3", "", null), ImmutableList.of());
    assertFilterMatches(new RegexDimFilter("dim3", "a", null), ImmutableList.of());
    assertFilterMatches(new RegexDimFilter("dim3", "b", null), ImmutableList.of());
    assertFilterMatches(new RegexDimFilter("dim3", "c", null), ImmutableList.of());
}
Also used : RegexDimFilter(org.apache.druid.query.filter.RegexDimFilter) Test(org.junit.Test)

Example 17 with RegexDimFilter

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

the class RegexFilterTest method testSingleValueStringColumnWithNulls.

@Test
public void testSingleValueStringColumnWithNulls() {
    // RegexFilter always returns false for null row values.
    if (NullHandling.replaceWithDefault()) {
        assertFilterMatches(new RegexDimFilter("dim1", ".*", null), ImmutableList.of("1", "2", "3", "4", "5"));
    } else {
        assertFilterMatches(new RegexDimFilter("dim1", ".*", null), ImmutableList.of("0", "1", "2", "3", "4", "5"));
    }
    assertFilterMatches(new RegexDimFilter("dim1", "10", null), ImmutableList.of("1"));
    assertFilterMatches(new RegexDimFilter("dim1", "2", null), ImmutableList.of("2"));
    assertFilterMatches(new RegexDimFilter("dim1", "1", null), ImmutableList.of("1", "3"));
    assertFilterMatches(new RegexDimFilter("dim1", ".*def", null), ImmutableList.of("4"));
    assertFilterMatches(new RegexDimFilter("dim1", "abc", null), ImmutableList.of("5"));
    assertFilterMatches(new RegexDimFilter("dim1", "ab.*", null), ImmutableList.of("4", "5"));
}
Also used : RegexDimFilter(org.apache.druid.query.filter.RegexDimFilter) Test(org.junit.Test)

Example 18 with RegexDimFilter

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

the class RegexFilterTest method testRequiredColumnRewrite.

@Test
public void testRequiredColumnRewrite() {
    Filter filter = new RegexDimFilter("dim0", ".*", null).toFilter();
    Filter filter2 = new RegexDimFilter("dim1", ".*", null).toFilter();
    Assert.assertTrue(filter.supportsRequiredColumnRewrite());
    Assert.assertTrue(filter2.supportsRequiredColumnRewrite());
    Filter rewrittenFilter = filter.rewriteRequiredColumns(ImmutableMap.of("dim0", "dim1"));
    Assert.assertEquals(filter2, rewrittenFilter);
    expectedException.expect(IAE.class);
    expectedException.expectMessage("Received a non-applicable rewrite: {invalidName=dim1}, filter's dimension: dim0");
    filter.rewriteRequiredColumns(ImmutableMap.of("invalidName", "dim1"));
}
Also used : RegexDimFilter(org.apache.druid.query.filter.RegexDimFilter) RegexDimFilter(org.apache.druid.query.filter.RegexDimFilter) Filter(org.apache.druid.query.filter.Filter) Test(org.junit.Test)

Example 19 with RegexDimFilter

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

the class RegexFilterTest method testMultiValueStringColumn.

@Test
public void testMultiValueStringColumn() {
    if (NullHandling.replaceWithDefault()) {
        assertFilterMatches(new RegexDimFilter("dim2", ".*", null), ImmutableList.of("0", "3", "4"));
    } else {
        assertFilterMatches(new RegexDimFilter("dim2", ".*", null), ImmutableList.of("0", "2", "3", "4"));
    }
    assertFilterMatches(new RegexDimFilter("dim2", "a", null), ImmutableList.of("0", "3"));
    assertFilterMatches(new RegexDimFilter("dim2", "b", null), ImmutableList.of("0"));
    assertFilterMatches(new RegexDimFilter("dim2", "c", null), ImmutableList.of("4"));
    assertFilterMatches(new RegexDimFilter("dim2", "d", null), ImmutableList.of());
}
Also used : RegexDimFilter(org.apache.druid.query.filter.RegexDimFilter) Test(org.junit.Test)

Example 20 with RegexDimFilter

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

the class LongFilteringTest method testLongColumnFiltering.

@Test
public void testLongColumnFiltering() {
    assertFilterMatches(new SelectorDimFilter(LONG_COLUMN, "0", null), ImmutableList.of());
    assertFilterMatches(new SelectorDimFilter(LONG_COLUMN, "3", null), ImmutableList.of("3"));
    assertFilterMatches(new SelectorDimFilter(LONG_COLUMN, "3.0", null), ImmutableList.of("3"));
    assertFilterMatches(new SelectorDimFilter(LONG_COLUMN, "3.00000000000000000000001", null), ImmutableList.of());
    assertFilterMatches(new SelectorDimFilter(LONG_COLUMN, "100000001.0", null), ImmutableList.of("8"));
    assertFilterMatches(new SelectorDimFilter(LONG_COLUMN, "-100000001.0", null), ImmutableList.of("10"));
    assertFilterMatches(new SelectorDimFilter(LONG_COLUMN, "111119223372036854775807.674398674398", null), ImmutableList.of());
    assertFilterMatches(new BoundDimFilter(LONG_COLUMN, "2", "5", false, false, null, null, StringComparators.NUMERIC), ImmutableList.of("2", "3", "4", "5"));
    assertFilterMatches(new BoundDimFilter(LONG_COLUMN, "1", "4", true, true, null, null, StringComparators.NUMERIC), ImmutableList.of("2", "3"));
    assertFilterMatches(new BoundDimFilter(LONG_COLUMN, "2.0", "5.0", false, false, null, null, StringComparators.NUMERIC), ImmutableList.of("2", "3", "4", "5"));
    assertFilterMatches(new BoundDimFilter(LONG_COLUMN, "2.0", "5.0", true, true, null, null, StringComparators.NUMERIC), ImmutableList.of("3", "4"));
    assertFilterMatches(new BoundDimFilter(LONG_COLUMN, "1.9", "5.9", true, true, null, null, StringComparators.NUMERIC), ImmutableList.of("2", "3", "4", "5"));
    assertFilterMatches(new BoundDimFilter(LONG_COLUMN, "2.1", "5.9", false, false, null, null, StringComparators.NUMERIC), ImmutableList.of("3", "4", "5"));
    assertFilterMatches(new BoundDimFilter(LONG_COLUMN, "111119223372036854775807.67", "5.9", false, false, null, null, StringComparators.NUMERIC), ImmutableList.of());
    assertFilterMatches(new BoundDimFilter(LONG_COLUMN, "-111119223372036854775807.67", "5.9", false, false, null, null, StringComparators.NUMERIC), ImmutableList.of("1", "2", "3", "4", "5", "9", "10"));
    assertFilterMatches(new BoundDimFilter(LONG_COLUMN, "2.1", "111119223372036854775807.67", false, false, null, null, StringComparators.NUMERIC), ImmutableList.of("3", "4", "5", "6", "7", "8"));
    assertFilterMatches(new BoundDimFilter(LONG_COLUMN, "2.1", "-111119223372036854775807.67", false, false, null, null, StringComparators.NUMERIC), ImmutableList.of());
    assertFilterMatches(new BoundDimFilter(LONG_COLUMN, "100000000.0", "100000001.0", true, true, null, null, StringComparators.NUMERIC), ImmutableList.of());
    assertFilterMatches(new BoundDimFilter(LONG_COLUMN, "100000000.0", "100000001.0", false, false, null, null, StringComparators.NUMERIC), ImmutableList.of("7", "8"));
    assertFilterMatches(new InDimFilter(LONG_COLUMN, Arrays.asList("2", "4", "8"), null), ImmutableList.of("2", "4"));
    assertFilterMatches(new InDimFilter(LONG_COLUMN, Arrays.asList("1.999999999999999999", "4.00000000000000000000001"), null), ImmutableList.of());
    assertFilterMatches(new InDimFilter(LONG_COLUMN, Arrays.asList("100000001.0", "99999999.999999999"), null), ImmutableList.of("8"));
    assertFilterMatches(new InDimFilter(LONG_COLUMN, Arrays.asList("-25.0", "-99999999.999999999"), null), ImmutableList.of("9"));
    // cross the hashing threshold to test hashset implementation, filter on even values
    List<String> infilterValues = new ArrayList<>(NUM_FILTER_VALUES);
    for (int i = 0; i < NUM_FILTER_VALUES; i++) {
        infilterValues.add(String.valueOf(i * 2));
    }
    assertFilterMatches(new InDimFilter(LONG_COLUMN, infilterValues, null), ImmutableList.of("2", "4", "6"));
    String jsFn = "function(x) { return(x === 3 || x === 5) }";
    assertFilterMatchesSkipVectorize(new JavaScriptDimFilter(LONG_COLUMN, jsFn, null, JavaScriptConfig.getEnabledInstance()), ImmutableList.of("3", "5"));
    assertFilterMatches(new RegexDimFilter(LONG_COLUMN, "4", null), ImmutableList.of("4"));
    assertFilterMatches(new SearchQueryDimFilter(LONG_COLUMN, new ContainsSearchQuerySpec("2", true), null), ImmutableList.of("2", "9"));
}
Also used : RegexDimFilter(org.apache.druid.query.filter.RegexDimFilter) BoundDimFilter(org.apache.druid.query.filter.BoundDimFilter) ContainsSearchQuerySpec(org.apache.druid.query.search.ContainsSearchQuerySpec) SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) InDimFilter(org.apache.druid.query.filter.InDimFilter) ArrayList(java.util.ArrayList) SearchQueryDimFilter(org.apache.druid.query.filter.SearchQueryDimFilter) JavaScriptDimFilter(org.apache.druid.query.filter.JavaScriptDimFilter) Test(org.junit.Test)

Aggregations

RegexDimFilter (org.apache.druid.query.filter.RegexDimFilter)24 Test (org.junit.Test)18 BoundDimFilter (org.apache.druid.query.filter.BoundDimFilter)12 SearchQueryDimFilter (org.apache.druid.query.filter.SearchQueryDimFilter)12 ContainsSearchQuerySpec (org.apache.druid.query.search.ContainsSearchQuerySpec)12 InDimFilter (org.apache.druid.query.filter.InDimFilter)11 JavaScriptDimFilter (org.apache.druid.query.filter.JavaScriptDimFilter)11 SelectorDimFilter (org.apache.druid.query.filter.SelectorDimFilter)9 ArrayList (java.util.ArrayList)6 LookupExtractionFn (org.apache.druid.query.lookup.LookupExtractionFn)5 HashMap (java.util.HashMap)4 MapLookupExtractor (org.apache.druid.query.extraction.MapLookupExtractor)4 OrDimFilter (org.apache.druid.query.filter.OrDimFilter)4 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)4 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)3 ExtractionFn (org.apache.druid.query.extraction.ExtractionFn)3 JavaScriptExtractionFn (org.apache.druid.query.extraction.JavaScriptExtractionFn)3 DimFilter (org.apache.druid.query.filter.DimFilter)3 LookupExtractor (org.apache.druid.query.lookup.LookupExtractor)3 PeriodGranularity (org.apache.druid.java.util.common.granularity.PeriodGranularity)2