use of io.druid.query.filter.SelectorDimFilter in project druid by druid-io.
the class GroupByQueryRunnerTest method testSubqueryWithOuterTimeFilter.
@Test
public void testSubqueryWithOuterTimeFilter() {
final GroupByQuery subquery = GroupByQuery.builder().setDataSource(QueryRunnerTestHelper.dataSource).setQuerySegmentSpec(QueryRunnerTestHelper.fullOnInterval).setDimensions(Lists.<DimensionSpec>newArrayList(new DefaultDimensionSpec("market", "market"), new DefaultDimensionSpec("quality", "quality"))).setAggregatorSpecs(Arrays.asList(QueryRunnerTestHelper.rowsCount, new LongSumAggregatorFactory("index", "index"))).setGranularity(QueryRunnerTestHelper.dayGran).build();
final DimFilter fridayFilter = new SelectorDimFilter(Column.TIME_COLUMN_NAME, "Friday", new TimeFormatExtractionFn("EEEE", null, null, null, false));
final DimFilter firstDaysFilter = new InDimFilter(Column.TIME_COLUMN_NAME, ImmutableList.of("1", "2", "3"), new TimeFormatExtractionFn("d", null, null, null, false));
final GroupByQuery query = GroupByQuery.builder().setDataSource(subquery).setQuerySegmentSpec(QueryRunnerTestHelper.fullOnInterval).setDimensions(Lists.<DimensionSpec>newArrayList()).setDimFilter(firstDaysFilter).setAggregatorSpecs(ImmutableList.<AggregatorFactory>of(new FilteredAggregatorFactory(QueryRunnerTestHelper.rowsCount, fridayFilter))).setGranularity(QueryRunnerTestHelper.dayGran).build();
List<Row> expectedResults = Arrays.asList(GroupByQueryRunnerTestHelper.createExpectedRow("2011-02-01", "rows", 0L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-02-02", "rows", 0L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-02-03", "rows", 0L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-03-01", "rows", 0L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-03-02", "rows", 0L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-03-03", "rows", 0L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "rows", 13L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-02", "rows", 0L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-03", "rows", 0L));
Iterable<Row> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
TestHelper.assertExpectedObjects(expectedResults, results, "");
}
use of io.druid.query.filter.SelectorDimFilter in project druid by druid-io.
the class GroupByQueryRunnerTest method testBySegmentResultsWithAllFiltersWithExtractionFns.
@Test
public void testBySegmentResultsWithAllFiltersWithExtractionFns() {
int segmentCount = 32;
Result<BySegmentResultValue> singleSegmentResult = new Result<BySegmentResultValue>(new DateTime("2011-01-12T00:00:00.000Z"), new BySegmentResultValueClass(Arrays.asList(GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "alias", "mezzanine", "rows", 6L, "idx", 4420L)), "testSegment", new Interval("2011-04-02T00:00:00.000Z/2011-04-04T00:00:00.000Z")));
List<Result> bySegmentResults = Lists.newArrayList();
for (int i = 0; i < segmentCount; i++) {
bySegmentResults.add(singleSegmentResult);
}
String extractionJsFn = "function(str) { return 'super-' + str; }";
String jsFn = "function(x) { return(x === 'super-mezzanine') }";
ExtractionFn extractionFn = new JavaScriptExtractionFn(extractionJsFn, false, JavaScriptConfig.getEnabledInstance());
List<DimFilter> superFilterList = new ArrayList<>();
superFilterList.add(new SelectorDimFilter("quality", "super-mezzanine", extractionFn));
superFilterList.add(new InDimFilter("quality", Arrays.asList("not-super-mezzanine", "FOOBAR", "super-mezzanine"), extractionFn));
superFilterList.add(new BoundDimFilter("quality", "super-mezzanine", "super-mezzanine", false, false, true, extractionFn, StringComparators.ALPHANUMERIC));
superFilterList.add(new RegexDimFilter("quality", "super-mezzanine", extractionFn));
superFilterList.add(new SearchQueryDimFilter("quality", new ContainsSearchQuerySpec("super-mezzanine", true), extractionFn));
superFilterList.add(new JavaScriptDimFilter("quality", jsFn, extractionFn, JavaScriptConfig.getEnabledInstance()));
DimFilter superFilter = new AndDimFilter(superFilterList);
GroupByQuery.Builder builder = GroupByQuery.builder().setDataSource(QueryRunnerTestHelper.dataSource).setInterval("2011-04-02/2011-04-04").setDimensions(Lists.<DimensionSpec>newArrayList(new DefaultDimensionSpec("quality", "alias"))).setAggregatorSpecs(Arrays.asList(QueryRunnerTestHelper.rowsCount, new LongSumAggregatorFactory("idx", "index"))).setGranularity(new PeriodGranularity(new Period("P1M"), null, null)).setDimFilter(superFilter).setContext(ImmutableMap.<String, Object>of("bySegment", true));
final GroupByQuery fullQuery = builder.build();
QueryToolChest toolChest = factory.getToolchest();
List<QueryRunner<Row>> singleSegmentRunners = Lists.newArrayList();
for (int i = 0; i < segmentCount; i++) {
singleSegmentRunners.add(toolChest.preMergeQueryDecoration(runner));
}
ExecutorService exec = Executors.newCachedThreadPool();
QueryRunner theRunner = toolChest.postMergeQueryDecoration(new FinalizeResultsQueryRunner<>(toolChest.mergeResults(factory.mergeRunners(Executors.newCachedThreadPool(), singleSegmentRunners)), toolChest));
TestHelper.assertExpectedObjects(bySegmentResults, theRunner.run(fullQuery, Maps.newHashMap()), "");
exec.shutdownNow();
}
use of io.druid.query.filter.SelectorDimFilter in project druid by druid-io.
the class DimFilterHavingSpecTest method testConcurrentUsage.
@Test(timeout = 60_000L)
// Doesn't always pass. The check in "eval" is best effort and not guaranteed to detect concurrent usage.
@Ignore
public void testConcurrentUsage() throws Exception {
final ExecutorService exec = Executors.newFixedThreadPool(2);
final DimFilterHavingSpec havingSpec = new DimFilterHavingSpec(new SelectorDimFilter("foo", "1", null));
final List<Future<?>> futures = new ArrayList<>();
for (int i = 0; i < 2; i++) {
final MapBasedRow row = new MapBasedRow(0, ImmutableMap.<String, Object>of("foo", String.valueOf(i)));
futures.add(exec.submit(new Runnable() {
@Override
public void run() {
havingSpec.setRowSignature(null);
while (!Thread.interrupted()) {
havingSpec.eval(row);
}
}
}));
}
expectedException.expect(ExecutionException.class);
expectedException.expectCause(CoreMatchers.<IllegalStateException>instanceOf(IllegalStateException.class));
expectedException.expectCause(ThrowableMessageMatcher.hasMessage(CoreMatchers.containsString("concurrent 'eval' calls not permitted")));
try {
for (Future<?> future : futures) {
future.get();
}
} finally {
exec.shutdownNow();
}
// Not reached
Assert.assertTrue(false);
}
use of io.druid.query.filter.SelectorDimFilter in project druid by druid-io.
the class DimFilterHavingSpecTest method testSerde.
@Test
public void testSerde() throws Exception {
final DimFilterHavingSpec havingSpec = new DimFilterHavingSpec(new SelectorDimFilter("foo", "1", null));
final ObjectMapper objectMapper = new DefaultObjectMapper();
Assert.assertEquals(havingSpec, objectMapper.readValue(objectMapper.writeValueAsBytes(havingSpec), HavingSpec.class));
}
use of io.druid.query.filter.SelectorDimFilter in project druid by druid-io.
the class SearchQueryRunnerTest method testSearchWithSingleFilter1.
@Test
public void testSearchWithSingleFilter1() {
List<SearchHit> expectedHits = Lists.newLinkedList();
expectedHits.add(new SearchHit(QueryRunnerTestHelper.qualityDimension, "mezzanine", 93));
checkSearchQuery(Druids.newSearchQueryBuilder().dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.allGran).filters(new AndDimFilter(Arrays.<DimFilter>asList(new SelectorDimFilter(QueryRunnerTestHelper.marketDimension, "total_market", null), new SelectorDimFilter(QueryRunnerTestHelper.qualityDimension, "mezzanine", null)))).intervals(QueryRunnerTestHelper.fullOnInterval).dimensions(QueryRunnerTestHelper.qualityDimension).query("a").build(), expectedHits);
}
Aggregations