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());
}
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 }));
}
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 }));
}
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" }));
}
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 }));
}
Aggregations