Search in sources :

Example 6 with SubstringDimExtractionFn

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 }));
}
Also used : SubstringDimExtractionFn(org.apache.druid.query.extraction.SubstringDimExtractionFn) TableDataSource(org.apache.druid.query.TableDataSource) QueryDataSource(org.apache.druid.query.QueryDataSource) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) Test(org.junit.Test)

Example 7 with SubstringDimExtractionFn

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 }));
}
Also used : SubstringDimExtractionFn(org.apache.druid.query.extraction.SubstringDimExtractionFn) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) DefaultLimitSpec(org.apache.druid.query.groupby.orderby.DefaultLimitSpec) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) ExtractionDimensionSpec(org.apache.druid.query.dimension.ExtractionDimensionSpec) Test(org.junit.Test)

Example 8 with SubstringDimExtractionFn

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);
}
Also used : SubstringDimExtractionFn(org.apache.druid.query.extraction.SubstringDimExtractionFn) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 9 with SubstringDimExtractionFn

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"));
}
Also used : SubstringDimExtractionFn(org.apache.druid.query.extraction.SubstringDimExtractionFn) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 10 with SubstringDimExtractionFn

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);
}
Also used : ExpressionVirtualColumn(org.apache.druid.segment.virtual.ExpressionVirtualColumn) SubstringDimExtractionFn(org.apache.druid.query.extraction.SubstringDimExtractionFn) LongSumAggregatorFactory(org.apache.druid.query.aggregation.LongSumAggregatorFactory) ExtractionDimensionSpec(org.apache.druid.query.dimension.ExtractionDimensionSpec) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Aggregations

SubstringDimExtractionFn (org.apache.druid.query.extraction.SubstringDimExtractionFn)21 Test (org.junit.Test)19 ExtractionDimensionSpec (org.apache.druid.query.dimension.ExtractionDimensionSpec)12 QueryDataSource (org.apache.druid.query.QueryDataSource)6 TableDataSource (org.apache.druid.query.TableDataSource)6 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)6 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)6 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)6 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)5 Parameters (junitparams.Parameters)3 GlobalTableDataSource (org.apache.druid.query.GlobalTableDataSource)3 LookupDataSource (org.apache.druid.query.LookupDataSource)2 CardinalityAggregatorFactory (org.apache.druid.query.aggregation.cardinality.CardinalityAggregatorFactory)2 LikeDimFilter (org.apache.druid.query.filter.LikeDimFilter)2 MultipleIntervalSegmentSpec (org.apache.druid.query.spec.MultipleIntervalSegmentSpec)2 ExpressionVirtualColumn (org.apache.druid.segment.virtual.ExpressionVirtualColumn)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayList (java.util.ArrayList)1 RexCall (org.apache.calcite.rex.RexCall)1 InputRow (org.apache.druid.data.input.InputRow)1