use of org.apache.druid.query.filter.JavaScriptDimFilter in project druid by druid-io.
the class IncrementalIndexReadBenchmark method readWithFilters.
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public void readWithFilters(Blackhole blackhole) {
DimFilter filter = new OrDimFilter(Arrays.asList(new BoundDimFilter("dimSequential", "-1", "-1", true, true, null, null, StringComparators.ALPHANUMERIC), new JavaScriptDimFilter("dimSequential", "function(x) { return false }", null, JavaScriptConfig.getEnabledInstance()), new RegexDimFilter("dimSequential", "X", null), new SearchQueryDimFilter("dimSequential", new ContainsSearchQuerySpec("X", false), null), new InDimFilter("dimSequential", Collections.singletonList("X"), null)));
IncrementalIndexStorageAdapter sa = new IncrementalIndexStorageAdapter(incIndex);
Sequence<Cursor> cursors = makeCursors(sa, filter);
Cursor cursor = cursors.limit(1).toList().get(0);
List<DimensionSelector> selectors = new ArrayList<>();
selectors.add(makeDimensionSelector(cursor, "dimSequential"));
selectors.add(makeDimensionSelector(cursor, "dimZipf"));
selectors.add(makeDimensionSelector(cursor, "dimUniform"));
selectors.add(makeDimensionSelector(cursor, "dimSequentialHalfNull"));
cursor.reset();
while (!cursor.isDone()) {
for (DimensionSelector selector : selectors) {
IndexedInts row = selector.getRow();
blackhole.consume(selector.lookupName(row.get(0)));
}
cursor.advance();
}
}
use of org.apache.druid.query.filter.JavaScriptDimFilter in project druid by druid-io.
the class NestedQueryPushDownTest method testDimensionFilterOnOuterQuery.
@Test
public void testDimensionFilterOnOuterQuery() {
QuerySegmentSpec intervalSpec = new MultipleIntervalSegmentSpec(Collections.singletonList(Intervals.utc(1500000000000L, 1600000000000L)));
GroupByQuery query = GroupByQuery.builder().setDataSource("blah").setDimensions(new DefaultDimensionSpec("dimA", "dimA"), new DefaultDimensionSpec("dimB", "dimB")).setAggregatorSpecs(new LongSumAggregatorFactory("metASum", "metA"), new LongSumAggregatorFactory("metBSum", "metB")).setGranularity(Granularities.ALL).setQuerySegmentSpec(intervalSpec).build();
GroupByQuery nestedQuery = GroupByQuery.builder().setDataSource(query).setDimensions(new DefaultDimensionSpec("dimA", "newDimA")).setAggregatorSpecs(new LongSumAggregatorFactory("finalSum", "metASum")).setContext(ImmutableMap.of(GroupByQueryConfig.CTX_KEY_FORCE_PUSH_DOWN_NESTED_QUERY, true)).setGranularity(Granularities.ALL).setDimFilter(new JavaScriptDimFilter("dimA", "function(dim){ return dim == 'mango' }", null, JavaScriptConfig.getEnabledInstance())).setQuerySegmentSpec(intervalSpec).build();
ResultRow expectedRow0 = GroupByQueryRunnerTestHelper.createExpectedRow(nestedQuery, "2017-07-14T02:40:00.000Z", "finalSum", 4000L, "newDimA", "mango");
Sequence<ResultRow> queryResult = runNestedQueryWithForcePushDown(nestedQuery);
List<ResultRow> results = queryResult.toList();
Assert.assertEquals(1, results.size());
Assert.assertEquals(expectedRow0, results.get(0));
}
use of org.apache.druid.query.filter.JavaScriptDimFilter in project druid by druid-io.
the class GroupByQueryRunnerTest method testSubqueryWithMultipleIntervalsInOuterQuery.
@Test
public void testSubqueryWithMultipleIntervalsInOuterQuery() {
GroupByQuery subquery = makeQueryBuilder().setDataSource(QueryRunnerTestHelper.DATA_SOURCE).setQuerySegmentSpec(QueryRunnerTestHelper.FIRST_TO_THIRD).setDimensions(new DefaultDimensionSpec("quality", "alias")).setDimFilter(new JavaScriptDimFilter("quality", "function(dim){ return true; }", null, JavaScriptConfig.getEnabledInstance())).setAggregatorSpecs(QueryRunnerTestHelper.ROWS_COUNT, new LongSumAggregatorFactory("idx", "index"), new LongSumAggregatorFactory("indexMaxPlusTen", "indexMaxPlusTen")).setGranularity(QueryRunnerTestHelper.DAY_GRAN).build();
GroupByQuery query = makeQueryBuilder().setDataSource(subquery).setQuerySegmentSpec(new MultipleIntervalSegmentSpec(ImmutableList.of(Intervals.of("2011-04-01T00:00:00.000Z/2011-04-01T23:58:00.000Z"), Intervals.of("2011-04-02T00:00:00.000Z/2011-04-03T00:00:00.000Z")))).setDimensions(new DefaultDimensionSpec("alias", "alias")).setAggregatorSpecs(new LongSumAggregatorFactory("rows", "rows"), new LongSumAggregatorFactory("idx", "idx")).setGranularity(QueryRunnerTestHelper.DAY_GRAN).build();
List<ResultRow> expectedResults = Arrays.asList(makeRow(query, "2011-04-01", "alias", "automotive", "rows", 1L, "idx", 135L), makeRow(query, "2011-04-01", "alias", "business", "rows", 1L, "idx", 118L), makeRow(query, "2011-04-01", "alias", "entertainment", "rows", 1L, "idx", 158L), makeRow(query, "2011-04-01", "alias", "health", "rows", 1L, "idx", 120L), makeRow(query, "2011-04-01", "alias", "mezzanine", "rows", 3L, "idx", 2870L), makeRow(query, "2011-04-01", "alias", "news", "rows", 1L, "idx", 121L), makeRow(query, "2011-04-01", "alias", "premium", "rows", 3L, "idx", 2900L), makeRow(query, "2011-04-01", "alias", "technology", "rows", 1L, "idx", 78L), makeRow(query, "2011-04-01", "alias", "travel", "rows", 1L, "idx", 119L), makeRow(query, "2011-04-02", "alias", "automotive", "rows", 1L, "idx", 147L), makeRow(query, "2011-04-02", "alias", "business", "rows", 1L, "idx", 112L), makeRow(query, "2011-04-02", "alias", "entertainment", "rows", 1L, "idx", 166L), makeRow(query, "2011-04-02", "alias", "health", "rows", 1L, "idx", 113L), makeRow(query, "2011-04-02", "alias", "mezzanine", "rows", 3L, "idx", 2447L), makeRow(query, "2011-04-02", "alias", "news", "rows", 1L, "idx", 114L), makeRow(query, "2011-04-02", "alias", "premium", "rows", 3L, "idx", 2505L), makeRow(query, "2011-04-02", "alias", "technology", "rows", 1L, "idx", 97L), makeRow(query, "2011-04-02", "alias", "travel", "rows", 1L, "idx", 126L));
// Subqueries are handled by the ToolChest
Iterable<ResultRow> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
TestHelper.assertExpectedObjects(expectedResults, results, "subquery-multiple-intervals");
}
use of org.apache.druid.query.filter.JavaScriptDimFilter in project druid by druid-io.
the class GroupByQueryRunnerTest method testSubqueryWithExtractionFnInOuterQuery.
@Test
public void testSubqueryWithExtractionFnInOuterQuery() {
// https://github.com/apache/druid/issues/2556
GroupByQuery subquery = makeQueryBuilder().setDataSource(QueryRunnerTestHelper.DATA_SOURCE).setQuerySegmentSpec(QueryRunnerTestHelper.FIRST_TO_THIRD).setDimensions(new DefaultDimensionSpec("quality", "alias")).setDimFilter(new JavaScriptDimFilter("quality", "function(dim){ return true; }", null, JavaScriptConfig.getEnabledInstance())).setAggregatorSpecs(QueryRunnerTestHelper.ROWS_COUNT, new LongSumAggregatorFactory("idx", "index"), new LongSumAggregatorFactory("indexMaxPlusTen", "indexMaxPlusTen")).setGranularity(QueryRunnerTestHelper.DAY_GRAN).build();
GroupByQuery query = makeQueryBuilder().setDataSource(subquery).setQuerySegmentSpec(new MultipleIntervalSegmentSpec(ImmutableList.of(Intervals.of("2011-04-01T00:00:00.000Z/2011-04-03T00:00:00.000Z")))).setDimensions(new ExtractionDimensionSpec("alias", "alias", new RegexDimExtractionFn("(a).*", true, "a"))).setAggregatorSpecs(new LongSumAggregatorFactory("rows", "rows"), new LongSumAggregatorFactory("idx", "idx")).setGranularity(QueryRunnerTestHelper.DAY_GRAN).build();
List<ResultRow> expectedResults = Arrays.asList(makeRow(query, "2011-04-01", "alias", "a", "rows", 13L, "idx", 6619L), makeRow(query, "2011-04-02", "alias", "a", "rows", 13L, "idx", 5827L));
// Subqueries are handled by the ToolChest
Iterable<ResultRow> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
TestHelper.assertExpectedObjects(expectedResults, results, "subquery-extractionfn");
}
use of org.apache.druid.query.filter.JavaScriptDimFilter in project druid by druid-io.
the class GroupByQueryRunnerTest method testSubqueryWithMultipleIntervalsInOuterQueryWithLimitPushDown.
@Test
public void testSubqueryWithMultipleIntervalsInOuterQueryWithLimitPushDown() {
GroupByQuery subquery = makeQueryBuilder().setDataSource(QueryRunnerTestHelper.DATA_SOURCE).setQuerySegmentSpec(QueryRunnerTestHelper.FIRST_TO_THIRD).setDimensions(new DefaultDimensionSpec("quality", "alias")).setDimFilter(new JavaScriptDimFilter("quality", "function(dim){ return true; }", null, JavaScriptConfig.getEnabledInstance())).setLimitSpec(new DefaultLimitSpec(Collections.singletonList(new OrderByColumnSpec("alias", OrderByColumnSpec.Direction.DESCENDING)), 12)).setAggregatorSpecs(QueryRunnerTestHelper.ROWS_COUNT, new LongSumAggregatorFactory("idx", "index"), new LongSumAggregatorFactory("indexMaxPlusTen", "indexMaxPlusTen")).setGranularity(QueryRunnerTestHelper.DAY_GRAN).build();
GroupByQuery query = makeQueryBuilder().setDataSource(subquery).setQuerySegmentSpec(new MultipleIntervalSegmentSpec(ImmutableList.of(Intervals.of("2011-04-01T00:00:00.000Z/2011-04-01T23:58:00.000Z"), Intervals.of("2011-04-02T00:00:00.000Z/2011-04-03T00:00:00.000Z")))).setDimensions(new DefaultDimensionSpec("alias", "alias")).setLimitSpec(new DefaultLimitSpec(Collections.singletonList(new OrderByColumnSpec("alias", OrderByColumnSpec.Direction.DESCENDING)), 15)).setAggregatorSpecs(new LongSumAggregatorFactory("rows", "rows"), new LongSumAggregatorFactory("idx", "idx")).setGranularity(QueryRunnerTestHelper.DAY_GRAN).build();
List<ResultRow> expectedResults = Arrays.asList(makeRow(query, "2011-04-01", "alias", "travel", "rows", 1L, "idx", 119L), makeRow(query, "2011-04-01", "alias", "technology", "rows", 1L, "idx", 78L), makeRow(query, "2011-04-01", "alias", "premium", "rows", 3L, "idx", 2900L), makeRow(query, "2011-04-01", "alias", "news", "rows", 1L, "idx", 121L), makeRow(query, "2011-04-01", "alias", "mezzanine", "rows", 3L, "idx", 2870L), makeRow(query, "2011-04-01", "alias", "health", "rows", 1L, "idx", 120L), makeRow(query, "2011-04-01", "alias", "entertainment", "rows", 1L, "idx", 158L), makeRow(query, "2011-04-01", "alias", "business", "rows", 1L, "idx", 118L), makeRow(query, "2011-04-01", "alias", "automotive", "rows", 1L, "idx", 135L), makeRow(query, "2011-04-02", "alias", "travel", "rows", 1L, "idx", 126L), makeRow(query, "2011-04-02", "alias", "technology", "rows", 1L, "idx", 97L), makeRow(query, "2011-04-02", "alias", "premium", "rows", 3L, "idx", 2505L));
// Subqueries are handled by the ToolChest
Iterable<ResultRow> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
TestHelper.assertExpectedObjects(expectedResults, results, "limit-pushdown");
}
Aggregations