Search in sources :

Example 1 with LookupDataSource

use of org.apache.druid.query.LookupDataSource in project druid by druid-io.

the class LookupSegmentWrangler method getSegmentsForIntervals.

@Override
public Iterable<Segment> getSegmentsForIntervals(final DataSource dataSource, final Iterable<Interval> intervals) {
    final LookupDataSource lookupDataSource = (LookupDataSource) dataSource;
    final Optional<LookupExtractorFactoryContainer> maybeContainer = lookupProvider.get(lookupDataSource.getLookupName());
    return maybeContainer.map(container -> Collections.<Segment>singletonList(new LookupSegment(lookupDataSource.getLookupName(), container.getLookupExtractorFactory()))).orElse(Collections.emptyList());
}
Also used : Interval(org.joda.time.Interval) LookupDataSource(org.apache.druid.query.LookupDataSource) Inject(com.google.inject.Inject) DataSource(org.apache.druid.query.DataSource) LookupExtractorFactoryContainerProvider(org.apache.druid.query.lookup.LookupExtractorFactoryContainerProvider) Optional(java.util.Optional) JoinableFactory(org.apache.druid.segment.join.JoinableFactory) Collections(java.util.Collections) LookupSegment(org.apache.druid.query.lookup.LookupSegment) LookupExtractorFactoryContainer(org.apache.druid.query.lookup.LookupExtractorFactoryContainer) LookupDataSource(org.apache.druid.query.LookupDataSource) LookupSegment(org.apache.druid.query.lookup.LookupSegment) LookupExtractorFactoryContainer(org.apache.druid.query.lookup.LookupExtractorFactoryContainer) LookupSegment(org.apache.druid.query.lookup.LookupSegment)

Example 2 with LookupDataSource

use of org.apache.druid.query.LookupDataSource in project druid by druid-io.

the class CalciteQueryTest method testGroupByExpressionFromLookup.

@Test
public void testGroupByExpressionFromLookup() throws Exception {
    // Cannot vectorize direct queries on lookup tables.
    cannotVectorize();
    testQuery("SELECT SUBSTRING(v, 1, 1), COUNT(*) FROM lookup.lookyloo GROUP BY 1", ImmutableList.of(GroupByQuery.builder().setDataSource(new LookupDataSource("lookyloo")).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setDimensions(dimensions(new ExtractionDimensionSpec("v", "d0", new SubstringDimExtractionFn(0, 1)))).setAggregatorSpecs(aggregators(new CountAggregatorFactory("a0"))).setContext(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(new Object[] { "m", 1L }, new Object[] { "x", 3L }));
}
Also used : SubstringDimExtractionFn(org.apache.druid.query.extraction.SubstringDimExtractionFn) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) LookupDataSource(org.apache.druid.query.LookupDataSource) ExtractionDimensionSpec(org.apache.druid.query.dimension.ExtractionDimensionSpec) Test(org.junit.Test)

Example 3 with LookupDataSource

use of org.apache.druid.query.LookupDataSource in project druid by druid-io.

the class CalciteJoinQueryTest method testUnionAllTwoQueriesBothQueriesAreJoin.

@Test
public void testUnionAllTwoQueriesBothQueriesAreJoin() throws Exception {
    cannotVectorize();
    testQuery("(" + "SELECT COUNT(*) FROM foo LEFT JOIN lookup.lookyloo ON foo.dim1 = lookyloo.k " + "                               UNION ALL                                       " + "SELECT COUNT(*) FROM foo INNER JOIN lookup.lookyloo ON foo.dim1 = lookyloo.k" + ") ", ImmutableList.of(Druids.newTimeseriesQueryBuilder().dataSource(join(new TableDataSource(CalciteTests.DATASOURCE1), new LookupDataSource("lookyloo"), "j0.", equalsCondition(makeColumnExpression("dim1"), makeColumnExpression("j0.k")), JoinType.LEFT)).intervals(querySegmentSpec(Filtration.eternity())).granularity(Granularities.ALL).aggregators(aggregators(new CountAggregatorFactory("a0"))).context(QUERY_CONTEXT_DEFAULT).build(), Druids.newTimeseriesQueryBuilder().dataSource(join(new TableDataSource(CalciteTests.DATASOURCE1), new LookupDataSource("lookyloo"), "j0.", equalsCondition(makeColumnExpression("dim1"), makeColumnExpression("j0.k")), JoinType.INNER)).intervals(querySegmentSpec(Filtration.eternity())).granularity(Granularities.ALL).aggregators(aggregators(new CountAggregatorFactory("a0"))).context(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(new Object[] { 6L }, new Object[] { 1L }));
}
Also used : GlobalTableDataSource(org.apache.druid.query.GlobalTableDataSource) TableDataSource(org.apache.druid.query.TableDataSource) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) LookupDataSource(org.apache.druid.query.LookupDataSource) Test(org.junit.Test)

Example 4 with LookupDataSource

use of org.apache.druid.query.LookupDataSource in project druid by druid-io.

the class CalciteJoinQueryTest method testLeftJoinSubqueryWithSelectorFilter.

@Test
@Parameters(source = QueryContextForJoinProvider.class)
public void testLeftJoinSubqueryWithSelectorFilter(Map<String, Object> queryContext) throws Exception {
    // Cannot vectorize due to 'concat' expression.
    cannotVectorize();
    // disable the cost model where inner join is treated like a filter
    // this leads to cost(left join) < cost(converted inner join) for the below query
    queryContext = QueryContextForJoinProvider.withOverrides(queryContext, ImmutableMap.of("computeInnerJoinCostAsFilter", "false"));
    testQuery("SELECT dim1, l1.k\n" + "FROM foo\n" + "LEFT JOIN (select k || '' as k from lookup.lookyloo group by 1) l1 ON foo.dim1 = l1.k\n" + "WHERE l1.k = 'abc'\n", queryContext, ImmutableList.of(newScanQueryBuilder().dataSource(join(new TableDataSource(CalciteTests.DATASOURCE1), new QueryDataSource(GroupByQuery.builder().setDataSource(new LookupDataSource("lookyloo")).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setVirtualColumns(expressionVirtualColumn("v0", "concat(\"k\",'')", ColumnType.STRING)).setDimensions(new DefaultDimensionSpec("v0", "d0")).build()), "j0.", equalsCondition(makeColumnExpression("dim1"), makeColumnExpression("j0.d0")), JoinType.LEFT)).intervals(querySegmentSpec(Filtration.eternity())).columns("dim1", "j0.d0").filters(selector("j0.d0", "abc", null)).context(queryContext).build()), ImmutableList.of(new Object[] { "abc", "abc" }));
}
Also used : GlobalTableDataSource(org.apache.druid.query.GlobalTableDataSource) TableDataSource(org.apache.druid.query.TableDataSource) QueryDataSource(org.apache.druid.query.QueryDataSource) LookupDataSource(org.apache.druid.query.LookupDataSource) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 5 with LookupDataSource

use of org.apache.druid.query.LookupDataSource in project druid by druid-io.

the class CalciteJoinQueryTest method testCountDistinctOfLookupUsingJoinOperator.

@Test
@Parameters(source = QueryContextForJoinProvider.class)
public void testCountDistinctOfLookupUsingJoinOperator(Map<String, Object> queryContext) throws Exception {
    // Cannot yet vectorize the JOIN operator.
    cannotVectorize();
    testQuery("SELECT COUNT(DISTINCT lookyloo.v)\n" + "FROM foo LEFT JOIN lookup.lookyloo ON foo.dim1 = lookyloo.k", queryContext, ImmutableList.of(Druids.newTimeseriesQueryBuilder().dataSource(join(new TableDataSource(CalciteTests.DATASOURCE1), new LookupDataSource("lookyloo"), "j0.", equalsCondition(makeColumnExpression("dim1"), makeColumnExpression("j0.k")), JoinType.LEFT)).intervals(querySegmentSpec(Filtration.eternity())).granularity(Granularities.ALL).aggregators(aggregators(new CardinalityAggregatorFactory("a0", null, ImmutableList.of(DefaultDimensionSpec.of("j0.v")), false, true))).context(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(new Object[] { NullHandling.replaceWithDefault() ? 2L : 1L }));
}
Also used : GlobalTableDataSource(org.apache.druid.query.GlobalTableDataSource) TableDataSource(org.apache.druid.query.TableDataSource) LookupDataSource(org.apache.druid.query.LookupDataSource) CardinalityAggregatorFactory(org.apache.druid.query.aggregation.cardinality.CardinalityAggregatorFactory) Parameters(junitparams.Parameters) Test(org.junit.Test)

Aggregations

LookupDataSource (org.apache.druid.query.LookupDataSource)27 Test (org.junit.Test)25 Parameters (junitparams.Parameters)19 GlobalTableDataSource (org.apache.druid.query.GlobalTableDataSource)19 TableDataSource (org.apache.druid.query.TableDataSource)19 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)14 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)14 QueryDataSource (org.apache.druid.query.QueryDataSource)12 NullHandlingTest (org.apache.druid.common.config.NullHandlingTest)3 DataSource (org.apache.druid.query.DataSource)3 PreJoinableClause (org.apache.druid.query.planning.PreJoinableClause)3 Optional (java.util.Optional)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 DoubleSumAggregatorFactory (org.apache.druid.query.aggregation.DoubleSumAggregatorFactory)2 ExtractionDimensionSpec (org.apache.druid.query.dimension.ExtractionDimensionSpec)2 SubstringDimExtractionFn (org.apache.druid.query.extraction.SubstringDimExtractionFn)2 DefaultLimitSpec (org.apache.druid.query.groupby.orderby.DefaultLimitSpec)2 OrderByColumnSpec (org.apache.druid.query.groupby.orderby.OrderByColumnSpec)2 SegmentReference (org.apache.druid.segment.SegmentReference)2 Inject (com.google.inject.Inject)1