use of org.apache.druid.query.filter.SelectorDimFilter 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"));
if (NullHandling.replaceWithDefault()) {
assertFilterMatches(new NoBitmapSelectorDimFilter("dim3", "", null), ImmutableList.of("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"));
} else {
assertFilterMatches(new NoBitmapSelectorDimFilter("dim3", "", null), ImmutableList.of());
}
assertFilterMatches(new NoBitmapSelectorDimFilter("dim3", "a", null), ImmutableList.of());
assertFilterMatches(new NoBitmapSelectorDimFilter("dim3", "b", null), ImmutableList.of());
assertFilterMatches(new NoBitmapSelectorDimFilter("dim3", "c", null), ImmutableList.of());
assertFilterMatches(new OrDimFilter(Arrays.asList(new NoBitmapSelectorDimFilter("dim1", "abc", null), new SelectorDimFilter("dim3", "NOTHERE", null))), ImmutableList.of("5", "8"));
assertFilterMatches(new OrDimFilter(Arrays.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.of());
assertFilterMatches(new NoBitmapSelectorDimFilter("dim3", "b", JS_EXTRACTION_FN), ImmutableList.of());
assertFilterMatches(new NoBitmapSelectorDimFilter("dim3", "c", JS_EXTRACTION_FN), ImmutableList.of());
assertFilterMatches(new OrDimFilter(Arrays.asList(new NoBitmapSelectorDimFilter("dim1", "super-abc", JS_EXTRACTION_FN), new SelectorDimFilter("dim3", "NOTHERE", JS_EXTRACTION_FN))), ImmutableList.of("5", "8"));
assertFilterMatches(new OrDimFilter(Arrays.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"));
}
use of org.apache.druid.query.filter.SelectorDimFilter in project druid by druid-io.
the class FilterPartitionTest method testDistributeOrCNFExtractionFn.
@Test
public void testDistributeOrCNFExtractionFn() {
DimFilter dimFilter1 = new OrDimFilter(Arrays.asList(new SelectorDimFilter("dim0", "super-6", JS_EXTRACTION_FN), new AndDimFilter(Arrays.asList(new NoBitmapSelectorDimFilter("dim1", "super-abdef", JS_EXTRACTION_FN), new SelectorDimFilter("dim2", "super-c", JS_EXTRACTION_FN)))));
Filter filter1 = dimFilter1.toFilter();
Filter filter1CNF = Filters.toCnf(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.asList(new SelectorDimFilter("dim0", "super-2", JS_EXTRACTION_FN), new SelectorDimFilter("dim0", "super-3", JS_EXTRACTION_FN), new AndDimFilter(Arrays.asList(new NoBitmapSelectorDimFilter("dim1", "super-HELLO", JS_EXTRACTION_FN), new SelectorDimFilter("dim2", "super-foo", JS_EXTRACTION_FN)))));
assertFilterMatches(dimFilter2, ImmutableList.of("2", "3", "7"));
DimFilter dimFilter3 = new OrDimFilter(dimFilter1, dimFilter2, new AndDimFilter(new NoBitmapSelectorDimFilter("dim1", "super-1", JS_EXTRACTION_FN), new SelectorDimFilter("dim2", "super-foo", JS_EXTRACTION_FN)));
assertFilterMatches(dimFilter3, ImmutableList.of("2", "3", "4", "6", "7", "9"));
}
use of org.apache.druid.query.filter.SelectorDimFilter in project druid by druid-io.
the class LongFilteringTest method testLongFilterWithExtractionFn.
@Test
public void testLongFilterWithExtractionFn() {
final Map<String, String> stringMap = new HashMap<>();
stringMap.put("1", "Monday");
stringMap.put("2", "Tuesday");
stringMap.put("3", "Wednesday");
stringMap.put("4", "Thursday");
stringMap.put("5", "Friday");
stringMap.put("6", "Saturday");
LookupExtractor mapExtractor = new MapLookupExtractor(stringMap, false);
LookupExtractionFn exfn = new LookupExtractionFn(mapExtractor, false, "UNKNOWN", false, true);
assertFilterMatches(new SelectorDimFilter(LONG_COLUMN, "Monday", exfn), ImmutableList.of("1"));
assertFilterMatches(new SelectorDimFilter(LONG_COLUMN, "Notaday", exfn), ImmutableList.of());
assertFilterMatches(new BoundDimFilter(LONG_COLUMN, "Fridax", "Fridaz", false, false, null, exfn, StringComparators.ALPHANUMERIC), ImmutableList.of("5"));
assertFilterMatches(new BoundDimFilter(LONG_COLUMN, "Friday", "Friday", true, true, null, exfn, StringComparators.ALPHANUMERIC), ImmutableList.of());
assertFilterMatches(new InDimFilter(LONG_COLUMN, Arrays.asList("Caturday", "Saturday", "Tuesday"), exfn), ImmutableList.of("2", "6"));
// test InFilter HashSet implementation
List<String> bigList = Arrays.asList("Saturday", "Tuesday", "Caturday", "Xanaday", "Vojuday", "Gribaday", "Kipoday", "Dheferday", "Fakeday", "Qeearaday", "Hello", "World", "1", "2", "3", "4", "5", "6", "7");
assertFilterMatches(new InDimFilter(LONG_COLUMN, bigList, exfn), ImmutableList.of("2", "6"));
String jsFn = "function(x) { return(x === 'Wednesday' || x === 'Thursday') }";
assertFilterMatchesSkipVectorize(new JavaScriptDimFilter(LONG_COLUMN, jsFn, exfn, JavaScriptConfig.getEnabledInstance()), ImmutableList.of("3", "4"));
assertFilterMatches(new RegexDimFilter(LONG_COLUMN, ".*day", exfn), ImmutableList.of("1", "2", "3", "4", "5", "6"));
assertFilterMatches(new SearchQueryDimFilter(LONG_COLUMN, new ContainsSearchQuerySpec("s", true), exfn), ImmutableList.of("2", "3", "4"));
}
use of org.apache.druid.query.filter.SelectorDimFilter in project druid by druid-io.
the class AndFilterTest method testAnd.
@Test
public void testAnd() {
assertFilterMatches(new AndDimFilter(ImmutableList.of(new SelectorDimFilter("dim0", "0", null), new SelectorDimFilter("dim1", "0", null))), ImmutableList.of("0"));
assertFilterMatches(new AndDimFilter(ImmutableList.of(new SelectorDimFilter("dim0", "0", null), new SelectorDimFilter("dim1", "1", null))), ImmutableList.of());
assertFilterMatches(new AndDimFilter(ImmutableList.of(new SelectorDimFilter("dim0", "1", null), new SelectorDimFilter("dim1", "0", null))), ImmutableList.of("1"));
assertFilterMatches(new AndDimFilter(ImmutableList.of(new SelectorDimFilter("dim0", "1", null), new SelectorDimFilter("dim1", "1", null))), ImmutableList.of());
assertFilterMatches(new AndDimFilter(ImmutableList.of(new NotDimFilter(new SelectorDimFilter("dim0", "1", null)), new NotDimFilter(new SelectorDimFilter("dim1", "1", null)))), ImmutableList.of("0", "2", "3", "4", "5"));
assertFilterMatches(new AndDimFilter(ImmutableList.of(new NotDimFilter(new SelectorDimFilter("dim0", "0", null)), new NotDimFilter(new SelectorDimFilter("dim1", "0", null)))), ImmutableList.of());
}
use of org.apache.druid.query.filter.SelectorDimFilter in project druid by druid-io.
the class AndFilterTest method testNotAnd.
@Test
public void testNotAnd() {
assertFilterMatches(new NotDimFilter(new AndDimFilter(ImmutableList.of(new SelectorDimFilter("dim0", "0", null), new SelectorDimFilter("dim1", "0", null)))), ImmutableList.of("1", "2", "3", "4", "5"));
assertFilterMatches(new NotDimFilter(new AndDimFilter(ImmutableList.of(new SelectorDimFilter("dim0", "0", null), new SelectorDimFilter("dim1", "1", null)))), ImmutableList.of("0", "1", "2", "3", "4", "5"));
assertFilterMatches(new NotDimFilter(new AndDimFilter(ImmutableList.of(new SelectorDimFilter("dim0", "1", null), new SelectorDimFilter("dim1", "0", null)))), ImmutableList.of("0", "2", "3", "4", "5"));
assertFilterMatches(new NotDimFilter(new AndDimFilter(ImmutableList.of(new SelectorDimFilter("dim0", "1", null), new SelectorDimFilter("dim1", "1", null)))), ImmutableList.of("0", "1", "2", "3", "4", "5"));
assertFilterMatches(new NotDimFilter(new AndDimFilter(ImmutableList.of(new NotDimFilter(new SelectorDimFilter("dim0", "1", null)), new NotDimFilter(new SelectorDimFilter("dim1", "1", null))))), ImmutableList.of("1"));
assertFilterMatches(new NotDimFilter(new AndDimFilter(ImmutableList.of(new NotDimFilter(new SelectorDimFilter("dim0", "0", null)), new NotDimFilter(new SelectorDimFilter("dim1", "0", null))))), ImmutableList.of("0", "1", "2", "3", "4", "5"));
}
Aggregations