Search in sources :

Example 36 with MultipleIntervalSegmentSpec

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

the class QueryContextsTest method testEnableQueryDebuggingSetToTrue.

@Test
public void testEnableQueryDebuggingSetToTrue() {
    Query<?> query = new TestQuery(new TableDataSource("test"), new MultipleIntervalSegmentSpec(ImmutableList.of(Intervals.of("0/100"))), false, ImmutableMap.of(QueryContexts.ENABLE_DEBUG, true));
    Assert.assertTrue(QueryContexts.isDebug(query));
    Assert.assertTrue(QueryContexts.isDebug(query.getContext()));
}
Also used : MultipleIntervalSegmentSpec(org.apache.druid.query.spec.MultipleIntervalSegmentSpec) Test(org.junit.Test)

Example 37 with MultipleIntervalSegmentSpec

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

the class QueryContextsTest method testDefaultQueryTimeout.

@Test
public void testDefaultQueryTimeout() {
    final Query<?> query = new TestQuery(new TableDataSource("test"), new MultipleIntervalSegmentSpec(ImmutableList.of(Intervals.of("0/100"))), false, new HashMap());
    Assert.assertEquals(300_000, QueryContexts.getDefaultTimeout(query));
}
Also used : HashMap(java.util.HashMap) MultipleIntervalSegmentSpec(org.apache.druid.query.spec.MultipleIntervalSegmentSpec) Test(org.junit.Test)

Example 38 with MultipleIntervalSegmentSpec

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

the class QueryContextsTest method testDisableSegmentPruning.

@Test
public void testDisableSegmentPruning() {
    Query<?> query = new TestQuery(new TableDataSource("test"), new MultipleIntervalSegmentSpec(ImmutableList.of(Intervals.of("0/100"))), false, ImmutableMap.of(QueryContexts.SECONDARY_PARTITION_PRUNING_KEY, false));
    Assert.assertFalse(QueryContexts.isSecondaryPartitionPruningEnabled(query));
}
Also used : MultipleIntervalSegmentSpec(org.apache.druid.query.spec.MultipleIntervalSegmentSpec) Test(org.junit.Test)

Example 39 with MultipleIntervalSegmentSpec

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

the class VarianceSqlAggregatorTest method testStdDevWithVirtualColumns.

@Test
public void testStdDevWithVirtualColumns() throws Exception {
    VarianceAggregatorCollector holder1 = new VarianceAggregatorCollector();
    VarianceAggregatorCollector holder2 = new VarianceAggregatorCollector();
    VarianceAggregatorCollector holder3 = new VarianceAggregatorCollector();
    for (InputRow row : CalciteTests.ROWS1_WITH_NUMERIC_DIMS) {
        Object raw1 = row.getRaw("d1");
        Object raw2 = row.getRaw("f1");
        Object raw3 = row.getRaw("l1");
        addToHolder(holder1, raw1, 7);
        addToHolder(holder2, raw2, 7);
        addToHolder(holder3, raw3, 7);
    }
    final List<Object[]> expectedResults = ImmutableList.of(new Object[] { Math.sqrt(holder1.getVariance(false)), (float) Math.sqrt(holder2.getVariance(false)), (long) Math.sqrt(holder3.getVariance(false)) });
    testQuery("SELECT\n" + "STDDEV(d1*7),\n" + "STDDEV(f1*7),\n" + "STDDEV(l1*7)\n" + "FROM numfoo", ImmutableList.of(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE3).intervals(new MultipleIntervalSegmentSpec(ImmutableList.of(Filtration.eternity()))).granularity(Granularities.ALL).virtualColumns(BaseCalciteQueryTest.expressionVirtualColumn("v0", "(\"d1\" * 7)", ColumnType.DOUBLE), BaseCalciteQueryTest.expressionVirtualColumn("v1", "(\"f1\" * 7)", ColumnType.FLOAT), BaseCalciteQueryTest.expressionVirtualColumn("v2", "(\"l1\" * 7)", ColumnType.LONG)).aggregators(ImmutableList.of(new VarianceAggregatorFactory("a0:agg", "v0", "sample", "double"), new VarianceAggregatorFactory("a1:agg", "v1", "sample", "float"), new VarianceAggregatorFactory("a2:agg", "v2", "sample", "long"))).postAggregators(new StandardDeviationPostAggregator("a0", "a0:agg", "sample"), new StandardDeviationPostAggregator("a1", "a1:agg", "sample"), new StandardDeviationPostAggregator("a2", "a2:agg", "sample")).context(BaseCalciteQueryTest.QUERY_CONTEXT_DEFAULT).build()), expectedResults);
}
Also used : VarianceAggregatorCollector(org.apache.druid.query.aggregation.variance.VarianceAggregatorCollector) StandardDeviationPostAggregator(org.apache.druid.query.aggregation.variance.StandardDeviationPostAggregator) InputRow(org.apache.druid.data.input.InputRow) MultipleIntervalSegmentSpec(org.apache.druid.query.spec.MultipleIntervalSegmentSpec) VarianceAggregatorFactory(org.apache.druid.query.aggregation.variance.VarianceAggregatorFactory) BaseCalciteQueryTest(org.apache.druid.sql.calcite.BaseCalciteQueryTest) Test(org.junit.Test)

Example 40 with MultipleIntervalSegmentSpec

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

the class VarianceSqlAggregatorTest method testVarSamp.

@Test
public void testVarSamp() throws Exception {
    VarianceAggregatorCollector holder1 = new VarianceAggregatorCollector();
    VarianceAggregatorCollector holder2 = new VarianceAggregatorCollector();
    VarianceAggregatorCollector holder3 = new VarianceAggregatorCollector();
    for (InputRow row : CalciteTests.ROWS1_WITH_NUMERIC_DIMS) {
        Object raw1 = row.getRaw("d1");
        Object raw2 = row.getRaw("f1");
        Object raw3 = row.getRaw("l1");
        addToHolder(holder1, raw1);
        addToHolder(holder2, raw2);
        addToHolder(holder3, raw3);
    }
    final List<Object[]> expectedResults = ImmutableList.of(new Object[] { holder1.getVariance(false), holder2.getVariance(false).floatValue(), holder3.getVariance(false).longValue() });
    testQuery("SELECT\n" + "VAR_SAMP(d1),\n" + "VAR_SAMP(f1),\n" + "VAR_SAMP(l1)\n" + "FROM numfoo", ImmutableList.of(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE3).intervals(new MultipleIntervalSegmentSpec(ImmutableList.of(Filtration.eternity()))).granularity(Granularities.ALL).aggregators(ImmutableList.of(new VarianceAggregatorFactory("a0:agg", "d1", "sample", "double"), new VarianceAggregatorFactory("a1:agg", "f1", "sample", "float"), new VarianceAggregatorFactory("a2:agg", "l1", "sample", "long"))).context(BaseCalciteQueryTest.QUERY_CONTEXT_DEFAULT).build()), expectedResults);
}
Also used : VarianceAggregatorCollector(org.apache.druid.query.aggregation.variance.VarianceAggregatorCollector) InputRow(org.apache.druid.data.input.InputRow) MultipleIntervalSegmentSpec(org.apache.druid.query.spec.MultipleIntervalSegmentSpec) VarianceAggregatorFactory(org.apache.druid.query.aggregation.variance.VarianceAggregatorFactory) BaseCalciteQueryTest(org.apache.druid.sql.calcite.BaseCalciteQueryTest) Test(org.junit.Test)

Aggregations

MultipleIntervalSegmentSpec (org.apache.druid.query.spec.MultipleIntervalSegmentSpec)142 Test (org.junit.Test)115 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)53 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)44 BaseCalciteQueryTest (org.apache.druid.sql.calcite.BaseCalciteQueryTest)39 QuerySegmentSpec (org.apache.druid.query.spec.QuerySegmentSpec)28 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)25 ResponseContext (org.apache.druid.query.context.ResponseContext)22 QueryRunner (org.apache.druid.query.QueryRunner)21 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)21 QueryPlus (org.apache.druid.query.QueryPlus)20 TableDataSource (org.apache.druid.query.TableDataSource)19 FinalizeResultsQueryRunner (org.apache.druid.query.FinalizeResultsQueryRunner)18 ArrayList (java.util.ArrayList)17 QueryDataSource (org.apache.druid.query.QueryDataSource)15 DefaultLimitSpec (org.apache.druid.query.groupby.orderby.DefaultLimitSpec)15 OrderByColumnSpec (org.apache.druid.query.groupby.orderby.OrderByColumnSpec)15 Sequence (org.apache.druid.java.util.common.guava.Sequence)14 FieldAccessPostAggregator (org.apache.druid.query.aggregation.post.FieldAccessPostAggregator)14 Result (org.apache.druid.query.Result)13