Search in sources :

Example 61 with QueryDataSource

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

the class DataSourceAnalysisTest method testQueryOnLookup.

@Test
public void testQueryOnLookup() {
    final QueryDataSource queryDataSource = subquery(LOOKUP_LOOKYLOO);
    final DataSourceAnalysis analysis = DataSourceAnalysis.forDataSource(queryDataSource);
    Assert.assertTrue(analysis.isConcreteBased());
    Assert.assertFalse(analysis.isConcreteTableBased());
    Assert.assertTrue(analysis.isGlobal());
    Assert.assertTrue(analysis.isQuery());
    Assert.assertEquals(queryDataSource, analysis.getDataSource());
    Assert.assertEquals(LOOKUP_LOOKYLOO, analysis.getBaseDataSource());
    Assert.assertEquals(Optional.empty(), analysis.getBaseTableDataSource());
    Assert.assertEquals(Optional.empty(), analysis.getBaseUnionDataSource());
    Assert.assertEquals(Optional.of(queryDataSource.getQuery()), analysis.getBaseQuery());
    Assert.assertEquals(Optional.of(new MultipleIntervalSegmentSpec(MILLENIUM_INTERVALS)), analysis.getBaseQuerySegmentSpec());
    Assert.assertEquals(Collections.emptyList(), analysis.getPreJoinableClauses());
    Assert.assertFalse(analysis.isJoin());
}
Also used : QueryDataSource(org.apache.druid.query.QueryDataSource) MultipleIntervalSegmentSpec(org.apache.druid.query.spec.MultipleIntervalSegmentSpec) Test(org.junit.Test)

Example 62 with QueryDataSource

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

the class DataSourceAnalysisTest method testQueryOnUnion.

@Test
public void testQueryOnUnion() {
    final UnionDataSource unionDataSource = new UnionDataSource(ImmutableList.of(TABLE_FOO, TABLE_BAR));
    final QueryDataSource queryDataSource = subquery(unionDataSource);
    final DataSourceAnalysis analysis = DataSourceAnalysis.forDataSource(queryDataSource);
    Assert.assertTrue(analysis.isConcreteBased());
    Assert.assertTrue(analysis.isConcreteTableBased());
    Assert.assertFalse(analysis.isGlobal());
    Assert.assertTrue(analysis.isQuery());
    Assert.assertEquals(queryDataSource, analysis.getDataSource());
    Assert.assertEquals(unionDataSource, analysis.getBaseDataSource());
    Assert.assertEquals(Optional.empty(), analysis.getBaseTableDataSource());
    Assert.assertEquals(Optional.of(unionDataSource), analysis.getBaseUnionDataSource());
    Assert.assertEquals(Optional.of(queryDataSource.getQuery()), analysis.getBaseQuery());
    Assert.assertEquals(Optional.of(new MultipleIntervalSegmentSpec(MILLENIUM_INTERVALS)), analysis.getBaseQuerySegmentSpec());
    Assert.assertEquals(Collections.emptyList(), analysis.getPreJoinableClauses());
    Assert.assertFalse(analysis.isJoin());
}
Also used : QueryDataSource(org.apache.druid.query.QueryDataSource) MultipleIntervalSegmentSpec(org.apache.druid.query.spec.MultipleIntervalSegmentSpec) UnionDataSource(org.apache.druid.query.UnionDataSource) Test(org.junit.Test)

Example 63 with QueryDataSource

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

the class ClientQuerySegmentWalkerTest method testTimeseriesOnGroupByOnTable.

@Test
public void testTimeseriesOnGroupByOnTable() {
    final GroupByQuery subquery = GroupByQuery.builder().setDataSource(FOO).setGranularity(Granularities.ALL).setInterval(Collections.singletonList(INTERVAL)).setDimensions(DefaultDimensionSpec.of("s")).build();
    final TimeseriesQuery query = (TimeseriesQuery) Druids.newTimeseriesQueryBuilder().dataSource(new QueryDataSource(subquery)).granularity(Granularities.ALL).intervals(Intervals.ONLY_ETERNITY).aggregators(new CountAggregatorFactory("cnt")).build().withId(DUMMY_QUERY_ID);
    testQuery(query, ImmutableList.of(ExpectedQuery.cluster(subquery.withId(DUMMY_QUERY_ID).withSubQueryId("1.1")), ExpectedQuery.local(query.withDataSource(InlineDataSource.fromIterable(ImmutableList.of(new Object[] { "x" }, new Object[] { "y" }, new Object[] { "z" }), RowSignature.builder().add("s", ColumnType.STRING).build())))), ImmutableList.of(new Object[] { Intervals.ETERNITY.getStartMillis(), 3L }));
    // note: this should really be 1, but in the interim queries that are composed of multiple queries count each
    // invocation of either the cluster or local walker in ClientQuerySegmentWalker
    Assert.assertEquals(2, scheduler.getTotalRun().get());
    Assert.assertEquals(1, scheduler.getTotalPrioritizedAndLaned().get());
    Assert.assertEquals(2, scheduler.getTotalAcquired().get());
    Assert.assertEquals(2, scheduler.getTotalReleased().get());
}
Also used : GroupByQuery(org.apache.druid.query.groupby.GroupByQuery) TimeseriesQuery(org.apache.druid.query.timeseries.TimeseriesQuery) QueryDataSource(org.apache.druid.query.QueryDataSource) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) Test(org.junit.Test)

Example 64 with QueryDataSource

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

the class CalciteQueryTest method testAvgDailyCountDistinct.

@Test
public void testAvgDailyCountDistinct() throws Exception {
    // Cannot vectorize outer query due to inlined inner query.
    cannotVectorize();
    testQuery("SELECT\n" + "  AVG(u)\n" + "FROM (SELECT FLOOR(__time TO DAY), APPROX_COUNT_DISTINCT(cnt) AS u FROM druid.foo GROUP BY 1)", ImmutableList.of(GroupByQuery.builder().setDataSource(new QueryDataSource(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(querySegmentSpec(Filtration.eternity())).granularity(new PeriodGranularity(Period.days(1), null, DateTimeZone.UTC)).aggregators(new CardinalityAggregatorFactory("a0:a", null, dimensions(new DefaultDimensionSpec("cnt", "cnt", ColumnType.LONG)), false, true)).postAggregators(ImmutableList.of(new HyperUniqueFinalizingPostAggregator("a0", "a0:a"))).context(getTimeseriesContextWithFloorTime(TIMESERIES_CONTEXT_BY_GRAN, "d0")).build())).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setAggregatorSpecs(useDefault ? aggregators(new LongSumAggregatorFactory("_a0:sum", "a0"), new CountAggregatorFactory("_a0:count")) : aggregators(new LongSumAggregatorFactory("_a0:sum", "a0"), new FilteredAggregatorFactory(new CountAggregatorFactory("_a0:count"), not(selector("a0", null, null))))).setPostAggregatorSpecs(ImmutableList.of(new ArithmeticPostAggregator("_a0", "quotient", ImmutableList.of(new FieldAccessPostAggregator(null, "_a0:sum"), new FieldAccessPostAggregator(null, "_a0:count"))))).setContext(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(new Object[] { 1L }));
}
Also used : FilteredAggregatorFactory(org.apache.druid.query.aggregation.FilteredAggregatorFactory) ArithmeticPostAggregator(org.apache.druid.query.aggregation.post.ArithmeticPostAggregator) FinalizingFieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FinalizingFieldAccessPostAggregator) FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) QueryDataSource(org.apache.druid.query.QueryDataSource) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) PeriodGranularity(org.apache.druid.java.util.common.granularity.PeriodGranularity) LongSumAggregatorFactory(org.apache.druid.query.aggregation.LongSumAggregatorFactory) HyperUniqueFinalizingPostAggregator(org.apache.druid.query.aggregation.hyperloglog.HyperUniqueFinalizingPostAggregator) CardinalityAggregatorFactory(org.apache.druid.query.aggregation.cardinality.CardinalityAggregatorFactory) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Test(org.junit.Test)

Example 65 with QueryDataSource

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

the class CalciteQueryTest method testMultipleExactCountDistinctWithGroupingAndOtherAggregators.

@Test
public void testMultipleExactCountDistinctWithGroupingAndOtherAggregators() throws Exception {
    requireMergeBuffers(4);
    testQuery(PLANNER_CONFIG_NO_HLL.withOverrides(ImmutableMap.of(PlannerConfig.CTX_KEY_USE_GROUPING_SET_FOR_EXACT_DISTINCT, "true")), "SELECT FLOOR(__time to day), COUNT(distinct city), COUNT(distinct user) FROM druid.visits GROUP BY 1", CalciteTests.REGULAR_USER_AUTH_RESULT, ImmutableList.of(GroupByQuery.builder().setDataSource(new QueryDataSource(GroupByQuery.builder().setDataSource(CalciteTests.USERVISITDATASOURCE).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setVirtualColumns(expressionVirtualColumn("v0", "timestamp_floor(\"__time\",'P1D',null,'UTC')", ColumnType.LONG)).setDimensions(dimensions(new DefaultDimensionSpec("v0", "d0", ColumnType.LONG), new DefaultDimensionSpec("city", "d1"), new DefaultDimensionSpec("user", "d2"))).setAggregatorSpecs(aggregators(new GroupingAggregatorFactory("a0", Arrays.asList("v0", "city", "user")))).setSubtotalsSpec(ImmutableList.of(ImmutableList.of("d0", "d1"), ImmutableList.of("d0", "d2"))).setContext(withTimestampResultContext(QUERY_CONTEXT_DEFAULT, "d0", 0, Granularities.DAY)).build())).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setDimensions(dimensions(new DefaultDimensionSpec("d0", "_d0", ColumnType.LONG))).setAggregatorSpecs(aggregators(new FilteredAggregatorFactory(new CountAggregatorFactory("_a0"), and(not(selector("d1", null, null)), selector("a0", "1", null))), new FilteredAggregatorFactory(new CountAggregatorFactory("_a1"), and(not(selector("d2", null, null)), selector("a0", "2", null))))).setContext(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(new Object[] { 1609459200000L, 3L, 2L }, new Object[] { 1609545600000L, 3L, 4L }, new Object[] { 1609632000000L, 1L, 1L }));
}
Also used : FilteredAggregatorFactory(org.apache.druid.query.aggregation.FilteredAggregatorFactory) QueryDataSource(org.apache.druid.query.QueryDataSource) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) GroupingAggregatorFactory(org.apache.druid.query.aggregation.GroupingAggregatorFactory) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Test(org.junit.Test)

Aggregations

QueryDataSource (org.apache.druid.query.QueryDataSource)95 Test (org.junit.Test)81 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)51 TableDataSource (org.apache.druid.query.TableDataSource)44 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)41 Parameters (junitparams.Parameters)30 GlobalTableDataSource (org.apache.druid.query.GlobalTableDataSource)29 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)23 FilteredAggregatorFactory (org.apache.druid.query.aggregation.FilteredAggregatorFactory)14 MultipleIntervalSegmentSpec (org.apache.druid.query.spec.MultipleIntervalSegmentSpec)14 LookupDataSource (org.apache.druid.query.LookupDataSource)13 SelectorDimFilter (org.apache.druid.query.filter.SelectorDimFilter)11 GroupByQuery (org.apache.druid.query.groupby.GroupByQuery)11 ArithmeticPostAggregator (org.apache.druid.query.aggregation.post.ArithmeticPostAggregator)10 FieldAccessPostAggregator (org.apache.druid.query.aggregation.post.FieldAccessPostAggregator)10 DataSource (org.apache.druid.query.DataSource)8 DoubleSumAggregatorFactory (org.apache.druid.query.aggregation.DoubleSumAggregatorFactory)8 LongMaxAggregatorFactory (org.apache.druid.query.aggregation.LongMaxAggregatorFactory)8 ExpressionVirtualColumn (org.apache.druid.segment.virtual.ExpressionVirtualColumn)8 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)8