use of org.apache.druid.query.topn.TopNQueryBuilder in project druid by druid-io.
the class ClientQuerySegmentWalkerTest method testTopNOnArraysUnknownDoubles.
@Test
public void testTopNOnArraysUnknownDoubles() {
final TopNQuery query = (TopNQuery) new TopNQueryBuilder().dataSource(ARRAY_UNKNOWN).granularity(Granularities.ALL).intervals(Intervals.ONLY_ETERNITY).dimension(DefaultDimensionSpec.of("ad")).metric("sum_n").threshold(1000).aggregators(new LongSumAggregatorFactory("sum_n", "n")).build().withId(DUMMY_QUERY_ID);
// 'unknown' is treated as ColumnType.STRING. this might not always be the case, so this is a test case of wacky
// behavior of sorts
testQuery(query, ImmutableList.of(ExpectedQuery.cluster(query)), ImmutableList.of(new Object[] { 946684800000L, "4.0", 6L }, new Object[] { 946684800000L, "8.0", 4L }, new Object[] { 946684800000L, "2.0", 3L }, new Object[] { 946684800000L, "3.0", 3L }, new Object[] { 946684800000L, "6.0", 3L }, new Object[] { 946684800000L, "1.0", 1L }));
Assert.assertEquals(1, scheduler.getTotalRun().get());
Assert.assertEquals(1, scheduler.getTotalPrioritizedAndLaned().get());
Assert.assertEquals(1, scheduler.getTotalAcquired().get());
Assert.assertEquals(1, scheduler.getTotalReleased().get());
}
use of org.apache.druid.query.topn.TopNQueryBuilder in project druid by druid-io.
the class ClientQuerySegmentWalkerTest method testTopNOnArraysLongs.
@Test
public void testTopNOnArraysLongs() {
final TopNQuery query = (TopNQuery) new TopNQueryBuilder().dataSource(ARRAY).granularity(Granularities.ALL).intervals(Intervals.ONLY_ETERNITY).dimension(DefaultDimensionSpec.of("al")).metric("sum_n").threshold(1000).aggregators(new LongSumAggregatorFactory("sum_n", "n")).build().withId(DUMMY_QUERY_ID);
// group by cannot handle true array types, expect this, RuntimeExeception with IAE in stack trace
expectedException.expect(RuntimeException.class);
expectedException.expectMessage("Cannot create query type helper from invalid type [ARRAY<LONG>]");
testQuery(query, ImmutableList.of(ExpectedQuery.cluster(query)), ImmutableList.of());
}
use of org.apache.druid.query.topn.TopNQueryBuilder in project druid by druid-io.
the class ClientQuerySegmentWalkerTest method testTopNArraysDoubles.
@Test
public void testTopNArraysDoubles() {
final TopNQuery query = (TopNQuery) new TopNQueryBuilder().dataSource(ARRAY).granularity(Granularities.ALL).intervals(Intervals.ONLY_ETERNITY).dimension(DefaultDimensionSpec.of("ad")).metric("sum_n").threshold(1000).aggregators(new LongSumAggregatorFactory("sum_n", "n")).build().withId(DUMMY_QUERY_ID);
// group by cannot handle true array types, expect this, RuntimeExeception with IAE in stack trace
expectedException.expect(RuntimeException.class);
expectedException.expectMessage("Cannot create query type helper from invalid type [ARRAY<DOUBLE>]");
testQuery(query, ImmutableList.of(ExpectedQuery.cluster(query)), ImmutableList.of());
}
use of org.apache.druid.query.topn.TopNQueryBuilder in project druid by druid-io.
the class CalciteQueryTest method testNullDoubleTopN.
@Test
public void testNullDoubleTopN() throws Exception {
List<Object[]> expected;
if (useDefault) {
expected = ImmutableList.of(new Object[] { 1.7, 1L }, new Object[] { 1.0, 1L }, new Object[] { 0.0, 4L });
} else {
expected = ImmutableList.of(new Object[] { null, 3L }, new Object[] { 1.7, 1L }, new Object[] { 1.0, 1L }, new Object[] { 0.0, 1L });
}
testQuery("SELECT d1, COUNT(*) FROM druid.numfoo GROUP BY d1 ORDER BY d1 DESC LIMIT 10", QUERY_CONTEXT_DEFAULT, ImmutableList.of(new TopNQueryBuilder().dataSource(CalciteTests.DATASOURCE3).intervals(querySegmentSpec(Filtration.eternity())).dimension(new DefaultDimensionSpec("d1", "_d0", ColumnType.DOUBLE)).threshold(10).aggregators(aggregators(new CountAggregatorFactory("a0"))).metric(new InvertedTopNMetricSpec(new DimensionTopNMetricSpec(null, StringComparators.NUMERIC))).context(QUERY_CONTEXT_DEFAULT).build()), expected);
}
use of org.apache.druid.query.topn.TopNQueryBuilder in project druid by druid-io.
the class CalciteQueryTest method testOrderByAnyFloat.
@Test
public void testOrderByAnyFloat() throws Exception {
List<Object[]> expected;
if (NullHandling.replaceWithDefault()) {
expected = ImmutableList.of(new Object[] { "1", 0.0f }, new Object[] { "2", 0.0f }, new Object[] { "abc", 0.0f }, new Object[] { "def", 0.0f }, new Object[] { "10.1", 0.1f }, new Object[] { "", 1.0f });
} else {
expected = ImmutableList.of(new Object[] { "2", 0.0f }, new Object[] { "10.1", 0.1f }, new Object[] { "", 1.0f }, // reversed by TopNNumericResultBuilder.build()
new Object[] { "1", null }, new Object[] { "abc", null }, new Object[] { "def", null });
}
testQuery("SELECT dim1, ANY_VALUE(f1) FROM druid.numfoo GROUP BY 1 ORDER BY 2 LIMIT 10", ImmutableList.of(new TopNQueryBuilder().dataSource(CalciteTests.DATASOURCE3).intervals(querySegmentSpec(Filtration.eternity())).granularity(Granularities.ALL).dimension(new DefaultDimensionSpec("dim1", "_d0")).aggregators(aggregators(new FloatAnyAggregatorFactory("a0", "f1"))).metric(new InvertedTopNMetricSpec(new NumericTopNMetricSpec("a0"))).threshold(10).context(QUERY_CONTEXT_DEFAULT).build()), expected);
}
Aggregations