use of io.druid.query.filter.RegexDimFilter in project druid by druid-io.
the class TimeFilteringTest method testTimeFilterAsLong.
@Test
public void testTimeFilterAsLong() {
assertFilterMatches(new SelectorDimFilter(Column.TIME_COLUMN_NAME, "0", null), ImmutableList.<String>of("0"));
assertFilterMatches(new SelectorDimFilter(Column.TIME_COLUMN_NAME, "9000", null), ImmutableList.<String>of());
assertFilterMatches(new BoundDimFilter(Column.TIME_COLUMN_NAME, "0", "4", false, false, null, null, StringComparators.NUMERIC), ImmutableList.<String>of("0", "1", "2", "3", "4"));
assertFilterMatches(new BoundDimFilter(Column.TIME_COLUMN_NAME, "0", "4", true, true, null, null, StringComparators.NUMERIC), ImmutableList.<String>of("1", "2", "3"));
assertFilterMatches(new InDimFilter(Column.TIME_COLUMN_NAME, Arrays.asList("2", "4", "8"), null), ImmutableList.<String>of("2", "4"));
// cross the hashing threshold to test hashset implementation, filter on even values
List<String> infilterValues = new ArrayList<>(InDimFilter.NUMERIC_HASHING_THRESHOLD * 2);
for (int i = 0; i < InDimFilter.NUMERIC_HASHING_THRESHOLD * 2; i++) {
infilterValues.add(String.valueOf(i * 2));
}
assertFilterMatches(new InDimFilter(Column.TIME_COLUMN_NAME, infilterValues, null), ImmutableList.<String>of("0", "2", "4"));
String jsFn = "function(x) { return(x === 3 || x === 5) }";
assertFilterMatches(new JavaScriptDimFilter(Column.TIME_COLUMN_NAME, jsFn, null, JavaScriptConfig.getEnabledInstance()), ImmutableList.<String>of("3", "5"));
assertFilterMatches(new RegexDimFilter(Column.TIME_COLUMN_NAME, "4", null), ImmutableList.<String>of("4"));
assertFilterMatches(new SearchQueryDimFilter(Column.TIME_COLUMN_NAME, new ContainsSearchQuerySpec("2", true), null), ImmutableList.<String>of("2"));
}
use of io.druid.query.filter.RegexDimFilter in project druid by druid-io.
the class FloatFilteringTest method testFloatColumnFiltering.
@Test
public void testFloatColumnFiltering() {
assertFilterMatches(new SelectorDimFilter(FLOAT_COLUMN, "0", null), ImmutableList.<String>of());
assertFilterMatches(new SelectorDimFilter(FLOAT_COLUMN, "0.0", null), ImmutableList.<String>of());
assertFilterMatches(new SelectorDimFilter(FLOAT_COLUMN, "3", null), ImmutableList.<String>of("3"));
assertFilterMatches(new SelectorDimFilter(FLOAT_COLUMN, "3.0", null), ImmutableList.<String>of("3"));
assertFilterMatches(new BoundDimFilter(FLOAT_COLUMN, "2", "5", false, false, null, null, StringComparators.NUMERIC), ImmutableList.<String>of("2", "3", "4", "5"));
assertFilterMatches(new BoundDimFilter(FLOAT_COLUMN, "2.0", "5.0", false, false, null, null, StringComparators.NUMERIC), ImmutableList.<String>of("2", "3", "4", "5"));
assertFilterMatches(new BoundDimFilter(FLOAT_COLUMN, "1", "4", true, true, null, null, StringComparators.NUMERIC), ImmutableList.<String>of("2", "3"));
assertFilterMatches(new BoundDimFilter(FLOAT_COLUMN, "1.0", "4.0", true, true, null, null, StringComparators.NUMERIC), ImmutableList.<String>of("2", "3"));
assertFilterMatches(new InDimFilter(FLOAT_COLUMN, Arrays.asList("2", "4", "8"), null), ImmutableList.<String>of("2", "4"));
assertFilterMatches(new InDimFilter(FLOAT_COLUMN, Arrays.asList("2.0", "4.0", "8.0"), null), ImmutableList.<String>of("2", "4"));
// cross the hashing threshold to test hashset implementation, filter on even values
List<String> infilterValues = new ArrayList<>(InDimFilter.NUMERIC_HASHING_THRESHOLD * 2);
for (int i = 0; i < InDimFilter.NUMERIC_HASHING_THRESHOLD * 2; i++) {
infilterValues.add(String.valueOf(i * 2));
}
assertFilterMatches(new InDimFilter(FLOAT_COLUMN, infilterValues, null), ImmutableList.<String>of("2", "4", "6"));
String jsFn = "function(x) { return(x === 3 || x === 5) }";
assertFilterMatches(new JavaScriptDimFilter(FLOAT_COLUMN, jsFn, null, JavaScriptConfig.getEnabledInstance()), ImmutableList.<String>of("3", "5"));
String jsFn2 = "function(x) { return(x === 3.0 || x === 5.0) }";
assertFilterMatches(new JavaScriptDimFilter(FLOAT_COLUMN, jsFn2, null, JavaScriptConfig.getEnabledInstance()), ImmutableList.<String>of("3", "5"));
assertFilterMatches(new RegexDimFilter(FLOAT_COLUMN, "4", null), ImmutableList.<String>of("4"));
assertFilterMatches(new RegexDimFilter(FLOAT_COLUMN, "4.0", null), ImmutableList.<String>of("4"));
assertFilterMatches(new SearchQueryDimFilter(FLOAT_COLUMN, new ContainsSearchQuerySpec("2", true), null), ImmutableList.<String>of("2"));
assertFilterMatches(new SearchQueryDimFilter(FLOAT_COLUMN, new ContainsSearchQuerySpec("2", true), null), ImmutableList.<String>of("2"));
}
use of io.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.<String>of());
assertFilterMatches(new RegexDimFilter("dim3", "a", null), ImmutableList.<String>of());
assertFilterMatches(new RegexDimFilter("dim3", "b", null), ImmutableList.<String>of());
assertFilterMatches(new RegexDimFilter("dim3", "c", null), ImmutableList.<String>of());
}
use of io.druid.query.filter.RegexDimFilter in project druid by druid-io.
the class GroupByQueryRunnerTest method testGroupByWithRegEx.
@Test
public void testGroupByWithRegEx() throws Exception {
GroupByQuery.Builder builder = GroupByQuery.builder().setDataSource(QueryRunnerTestHelper.dataSource).setInterval("2011-04-02/2011-04-04").setDimFilter(new RegexDimFilter("quality", "auto.*", null)).setDimensions(Lists.<DimensionSpec>newArrayList(new DefaultDimensionSpec("quality", "quality"))).setAggregatorSpecs(Arrays.<AggregatorFactory>asList(QueryRunnerTestHelper.rowsCount)).setGranularity(new PeriodGranularity(new Period("P1M"), null, null));
final GroupByQuery query = builder.build();
List<Row> expectedResults = Arrays.asList(GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "quality", "automotive", "rows", 2L));
QueryRunner<Row> mergeRunner = factory.getToolchest().mergeResults(runner);
Map<String, Object> context = Maps.newHashMap();
TestHelper.assertExpectedObjects(expectedResults, mergeRunner.run(query, context), "no-limit");
}
Aggregations