use of org.apache.druid.query.search.ContainsSearchQuerySpec in project druid by druid-io.
the class FilteredAggregatorTest method testAggregateWithPredicateFilters.
@Test
public void testAggregateWithPredicateFilters() {
final float[] values = { 0.15f, 0.27f };
TestFloatColumnSelector selector;
FilteredAggregatorFactory factory;
factory = new FilteredAggregatorFactory(new DoubleSumAggregatorFactory("billy", "value"), new BoundDimFilter("dim", "a", "a", false, false, true, null, StringComparators.ALPHANUMERIC));
selector = new TestFloatColumnSelector(values);
validateFilteredAggs(factory, values, selector);
factory = new FilteredAggregatorFactory(new DoubleSumAggregatorFactory("billy", "value"), new RegexDimFilter("dim", "a", null));
selector = new TestFloatColumnSelector(values);
validateFilteredAggs(factory, values, selector);
factory = new FilteredAggregatorFactory(new DoubleSumAggregatorFactory("billy", "value"), new SearchQueryDimFilter("dim", new ContainsSearchQuerySpec("a", true), null));
selector = new TestFloatColumnSelector(values);
validateFilteredAggs(factory, values, selector);
String jsFn = "function(x) { return(x === 'a') }";
factory = new FilteredAggregatorFactory(new DoubleSumAggregatorFactory("billy", "value"), new JavaScriptDimFilter("dim", jsFn, null, JavaScriptConfig.getEnabledInstance()));
selector = new TestFloatColumnSelector(values);
validateFilteredAggs(factory, values, selector);
}
use of org.apache.druid.query.search.ContainsSearchQuerySpec in project druid by druid-io.
the class FilteredAggregatorBenchmark method setup.
/**
* Setup everything common for benchmarking both the incremental-index and the queriable-index.
*/
@Setup
public void setup() {
log.info("SETUP CALLED AT " + System.currentTimeMillis());
ComplexMetrics.registerSerde("hyperUnique", new HyperUniquesSerde());
schemaInfo = GeneratorBasicSchemas.SCHEMA_MAP.get(schema);
generator = new DataGenerator(schemaInfo.getColumnSchemas(), RNG_SEED, schemaInfo.getDataInterval(), rowsPerSegment);
filter = new OrDimFilter(Arrays.asList(new BoundDimFilter("dimSequential", "-1", "-1", true, true, null, null, StringComparators.ALPHANUMERIC), new RegexDimFilter("dimSequential", "X", null), new SearchQueryDimFilter("dimSequential", new ContainsSearchQuerySpec("X", false), null), new InDimFilter("dimSequential", Collections.singletonList("X"), null)));
filteredMetric = new FilteredAggregatorFactory(new CountAggregatorFactory("rows"), filter);
factory = new TimeseriesQueryRunnerFactory(new TimeseriesQueryQueryToolChest(), new TimeseriesQueryEngine(), QueryBenchmarkUtil.NOOP_QUERYWATCHER);
GeneratorSchemaInfo basicSchema = GeneratorBasicSchemas.SCHEMA_MAP.get("basic");
QuerySegmentSpec intervalSpec = new MultipleIntervalSegmentSpec(Collections.singletonList(basicSchema.getDataInterval()));
List<AggregatorFactory> queryAggs = Collections.singletonList(filteredMetric);
query = Druids.newTimeseriesQueryBuilder().dataSource("blah").granularity(Granularities.ALL).intervals(intervalSpec).aggregators(queryAggs).descending(descending).build();
}
use of org.apache.druid.query.search.ContainsSearchQuerySpec 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.search.ContainsSearchQuerySpec in project druid by druid-io.
the class GroupByQueryRunnerTest method testGroupByNestedWithInnerQueryOutputNullNumerics.
@Test
public void testGroupByNestedWithInnerQueryOutputNullNumerics() {
cannotVectorize();
if (config.getDefaultStrategy().equals(GroupByStrategySelector.STRATEGY_V1)) {
expectedException.expect(UnsupportedOperationException.class);
expectedException.expectMessage("GroupBy v1 only supports dimensions with an outputType of STRING.");
}
// Following extractionFn will generate null value for one kind of quality
ExtractionFn extractionFn = new SearchQuerySpecDimExtractionFn(new ContainsSearchQuerySpec("1200", false));
GroupByQuery subquery = makeQueryBuilder().setDataSource(QueryRunnerTestHelper.DATA_SOURCE).setQuerySegmentSpec(QueryRunnerTestHelper.FIRST_TO_THIRD).setDimensions(new DefaultDimensionSpec("quality", "alias"), new ExtractionDimensionSpec("qualityLong", "ql_alias", ColumnType.LONG, extractionFn), new ExtractionDimensionSpec("qualityFloat", "qf_alias", ColumnType.FLOAT, extractionFn), new ExtractionDimensionSpec("qualityDouble", "qd_alias", ColumnType.DOUBLE, extractionFn)).setDimFilter(new InDimFilter("quality", Arrays.asList("entertainment", "business"), null)).setAggregatorSpecs(QueryRunnerTestHelper.ROWS_COUNT, new LongSumAggregatorFactory("idx", "index")).setGranularity(QueryRunnerTestHelper.DAY_GRAN).build();
GroupByQuery outerQuery = makeQueryBuilder().setDataSource(subquery).setQuerySegmentSpec(QueryRunnerTestHelper.FIRST_TO_THIRD).setDimensions(new DefaultDimensionSpec("ql_alias", "quallong", ColumnType.LONG), new DefaultDimensionSpec("qf_alias", "qualfloat", ColumnType.FLOAT), new DefaultDimensionSpec("qd_alias", "qualdouble", ColumnType.DOUBLE)).setAggregatorSpecs(new LongSumAggregatorFactory("ql_alias_sum", "ql_alias"), new DoubleSumAggregatorFactory("qf_alias_sum", "qf_alias"), new DoubleSumAggregatorFactory("qd_alias_sum", "qd_alias")).setGranularity(QueryRunnerTestHelper.ALL_GRAN).build();
List<ResultRow> expectedResults = Arrays.asList(makeRow(outerQuery, "2011-04-01", "quallong", NullHandling.defaultLongValue(), "qualfloat", NullHandling.defaultFloatValue(), "qualdouble", NullHandling.defaultDoubleValue(), "ql_alias_sum", NullHandling.defaultLongValue(), "qf_alias_sum", NullHandling.defaultFloatValue(), "qd_alias_sum", NullHandling.defaultDoubleValue()), makeRow(outerQuery, "2011-04-01", "quallong", 1200L, "qualfloat", 12000.0, "qualdouble", 12000.0, "ql_alias_sum", 2400L, "qf_alias_sum", 24000.0, "qd_alias_sum", 24000.0));
Iterable<ResultRow> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, outerQuery);
TestHelper.assertExpectedObjects(expectedResults, results, "numerics");
}
use of org.apache.druid.query.search.ContainsSearchQuerySpec in project druid by druid-io.
the class TimeFilteringTest method testTimeFilterWithExtractionFn.
@Test
public void testTimeFilterWithExtractionFn() {
final Map<String, String> stringMap = new HashMap<>();
stringMap.put("0", "Monday");
stringMap.put("1", "Tuesday");
stringMap.put("2", "Wednesday");
stringMap.put("3", "Thursday");
stringMap.put("4", "Friday");
stringMap.put("5", "Saturday");
LookupExtractor mapExtractor = new MapLookupExtractor(stringMap, false);
LookupExtractionFn exfn = new LookupExtractionFn(mapExtractor, false, "UNKNOWN", false, true);
assertFilterMatches(new SelectorDimFilter(ColumnHolder.TIME_COLUMN_NAME, "Monday", exfn), ImmutableList.of("0"));
assertFilterMatches(new SelectorDimFilter(ColumnHolder.TIME_COLUMN_NAME, "Notaday", exfn), ImmutableList.of());
assertFilterMatches(new BoundDimFilter(ColumnHolder.TIME_COLUMN_NAME, "Fridax", "Fridaz", false, false, null, exfn, StringComparators.ALPHANUMERIC), ImmutableList.of("4"));
assertFilterMatches(new BoundDimFilter(ColumnHolder.TIME_COLUMN_NAME, "Friday", "Friday", true, true, null, exfn, StringComparators.ALPHANUMERIC), ImmutableList.of());
assertFilterMatches(new InDimFilter(ColumnHolder.TIME_COLUMN_NAME, Arrays.asList("Caturday", "Saturday", "Tuesday"), exfn), ImmutableList.of("1", "5"));
// 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(ColumnHolder.TIME_COLUMN_NAME, bigList, exfn), ImmutableList.of("1", "5"));
String jsFn = "function(x) { return(x === 'Wednesday' || x === 'Thursday') }";
assertFilterMatchesSkipVectorize(new JavaScriptDimFilter(ColumnHolder.TIME_COLUMN_NAME, jsFn, exfn, JavaScriptConfig.getEnabledInstance()), ImmutableList.of("2", "3"));
assertFilterMatches(new RegexDimFilter(ColumnHolder.TIME_COLUMN_NAME, ".*day", exfn), ImmutableList.of("0", "1", "2", "3", "4", "5"));
assertFilterMatches(new SearchQueryDimFilter(ColumnHolder.TIME_COLUMN_NAME, new ContainsSearchQuerySpec("s", true), exfn), ImmutableList.of("1", "2", "3"));
}
Aggregations