use of org.apache.druid.query.extraction.SubstringDimExtractionFn in project druid by druid-io.
the class CalciteQueryTest method testViewAndJoin.
@Test
public void testViewAndJoin() throws Exception {
cannotVectorize();
Map<String, Object> queryContext = withLeftDirectAccessEnabled(QUERY_CONTEXT_DEFAULT);
testQuery("SELECT COUNT(*) FROM view.cview as a INNER JOIN druid.foo d on d.dim2 = a.dim2 WHERE a.dim1_firstchar <> 'z' ", queryContext, ImmutableList.of(Druids.newTimeseriesQueryBuilder().dataSource(join(join(new TableDataSource(CalciteTests.DATASOURCE1), new QueryDataSource(newScanQueryBuilder().dataSource(CalciteTests.DATASOURCE3).intervals(querySegmentSpec(Filtration.eternity())).columns("dim2").context(queryContext).build()), "j0.", "(\"dim2\" == \"j0.dim2\")", JoinType.INNER, bound("dim2", "a", "a", false, false, null, null)), new QueryDataSource(newScanQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(querySegmentSpec(Filtration.eternity())).columns("dim2").context(queryContext).build()), "_j0.", "('a' == \"_j0.dim2\")", JoinType.INNER)).intervals(querySegmentSpec(Filtration.eternity())).filters(not(selector("dim1", "z", new SubstringDimExtractionFn(0, 1)))).granularity(Granularities.ALL).aggregators(aggregators(new CountAggregatorFactory("a0"))).context(withLeftDirectAccessEnabled(QUERY_CONTEXT_DEFAULT)).build()), ImmutableList.of(new Object[] { 8L }));
}
use of org.apache.druid.query.extraction.SubstringDimExtractionFn in project druid by druid-io.
the class CalciteQueryTest method testGroupByLimitPushdownExtraction.
@Test
public void testGroupByLimitPushdownExtraction() throws Exception {
cannotVectorize();
testQuery("SELECT dim4, substring(dim5, 1, 1), count(*) FROM druid.numfoo WHERE dim4 = 'a' GROUP BY 1,2 LIMIT 2", ImmutableList.of(GroupByQuery.builder().setDataSource(CalciteTests.DATASOURCE3).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setDimensions(dimensions(new DefaultDimensionSpec("v0", "_d0"), new ExtractionDimensionSpec("dim5", "_d1", new SubstringDimExtractionFn(0, 1)))).setVirtualColumns(expressionVirtualColumn("v0", "'a'", ColumnType.STRING)).setDimFilter(selector("dim4", "a", null)).setAggregatorSpecs(aggregators(new CountAggregatorFactory("a0"))).setLimitSpec(new DefaultLimitSpec(ImmutableList.of(), 2)).setContext(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(new Object[] { "a", "a", 2L }, new Object[] { "a", "b", 1L }));
}
use of org.apache.druid.query.extraction.SubstringDimExtractionFn in project druid by druid-io.
the class LikeDimFilterTest method testSerde.
@Test
public void testSerde() throws IOException {
final ObjectMapper objectMapper = new DefaultObjectMapper();
final DimFilter filter = new LikeDimFilter("foo", "bar%", "@", new SubstringDimExtractionFn(1, 2));
final DimFilter filter2 = objectMapper.readValue(objectMapper.writeValueAsString(filter), DimFilter.class);
Assert.assertEquals(filter, filter2);
}
use of org.apache.druid.query.extraction.SubstringDimExtractionFn in project druid by druid-io.
the class LikeDimFilterTest method testGetRequiredColumns.
@Test
public void testGetRequiredColumns() {
final DimFilter filter = new LikeDimFilter("foo", "bar%", "@", new SubstringDimExtractionFn(1, 2));
Assert.assertEquals(filter.getRequiredColumns(), Sets.newHashSet("foo"));
}
use of org.apache.druid.query.extraction.SubstringDimExtractionFn in project druid by druid-io.
the class GroupByQueryRunnerTest method testExtractionStringArraySpecWithMultiValueVirtualDimAsInput.
@Test
public void testExtractionStringArraySpecWithMultiValueVirtualDimAsInput() {
if (config.getDefaultStrategy().equals(GroupByStrategySelector.STRATEGY_V1)) {
expectedException.expect(UnsupportedOperationException.class);
expectedException.expectMessage("GroupBy v1 only supports dimensions with an outputType of STRING");
} else if (!vectorize) {
expectedException.expect(RuntimeException.class);
expectedException.expectMessage("Not supported for multi-value dimensions");
}
cannotVectorize();
GroupByQuery query = makeQueryBuilder().setDataSource(QueryRunnerTestHelper.DATA_SOURCE).setQuerySegmentSpec(QueryRunnerTestHelper.FIRST_TO_THIRD).setVirtualColumns(new ExpressionVirtualColumn("v0", "mv_to_array(placementish)", ColumnType.STRING_ARRAY, ExprMacroTable.nil())).setDimensions(new ExtractionDimensionSpec("v0", "alias", ColumnType.STRING_ARRAY, new SubstringDimExtractionFn(1, 1))).setAggregatorSpecs(QueryRunnerTestHelper.ROWS_COUNT, new LongSumAggregatorFactory("idx", "index")).setGranularity(QueryRunnerTestHelper.ALL_GRAN).build();
GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
}
Aggregations