use of org.apache.druid.query.Result in project druid by druid-io.
the class TopNQueryRunnerTest method test_topN_orderByLongNumericColumnWithNulls_returnsDescendingResults.
@Test
public void test_topN_orderByLongNumericColumnWithNulls_returnsDescendingResults() {
TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.DATA_SOURCE).granularity(QueryRunnerTestHelper.ALL_GRAN).dimension(new DefaultDimensionSpec("index", "index_alias", ColumnType.LONG)).metric(new NumericTopNMetricSpec("longNumericNull")).threshold(10000).aggregators(new LongSumAggregatorFactory("longNumericNull", "longNumericNull")).intervals(QueryRunnerTestHelper.SECOND_ONLY).build();
List<Result<TopNResultValue>> expectedResults = Collections.singletonList(new Result<>(DateTimes.of("2011-04-02T00:00:00.000Z"), new TopNResultValue(Arrays.asList(ImmutableMap.<String, Object>builder().put("index_alias", 97L).put("longNumericNull", 80L).build(), ImmutableMap.<String, Object>builder().put("index_alias", 135L).put("longNumericNull", 70L).build(), ImmutableMap.<String, Object>builder().put("index_alias", 1049L).put("longNumericNull", 70L).build(), ImmutableMap.<String, Object>builder().put("index_alias", 1321L).put("longNumericNull", 70L).build(), ImmutableMap.<String, Object>builder().put("index_alias", 110L).put("longNumericNull", 50L).build(), ImmutableMap.<String, Object>builder().put("index_alias", 1144L).put("longNumericNull", 50L).build(), ImmutableMap.<String, Object>builder().put("index_alias", 1193L).put("longNumericNull", 50L).build(), ImmutableMap.<String, Object>builder().put("index_alias", 113L).put("longNumericNull", 40L).build(), ImmutableMap.<String, Object>builder().put("index_alias", 112L).put("longNumericNull", 20L).build(), ImmutableMap.<String, Object>builder().put("index_alias", 147L).put("longNumericNull", 10L).build(), makeRowWithNulls("index_alias", 114L, "longNumericNull", NullHandling.defaultLongValue()), makeRowWithNulls("index_alias", 126L, "longNumericNull", NullHandling.defaultLongValue()), makeRowWithNulls("index_alias", 166L, "longNumericNull", NullHandling.defaultLongValue())))));
assertExpectedResults(expectedResults, query);
}
use of org.apache.druid.query.Result in project druid by druid-io.
the class TopNQueryRunnerTest method testTopNQueryCardinalityAggregatorWithExtractionFn.
@Test
public void testTopNQueryCardinalityAggregatorWithExtractionFn() {
String helloJsFn = "function(str) { return 'hello' }";
ExtractionFn helloFn = new JavaScriptExtractionFn(helloJsFn, false, JavaScriptConfig.getEnabledInstance());
DimensionSpec dimSpec = new ExtractionDimensionSpec(QueryRunnerTestHelper.MARKET_DIMENSION, QueryRunnerTestHelper.MARKET_DIMENSION, helloFn);
ImmutableList<DimensionSpec> aggregatorDimensionSpecs = ImmutableList.of(new ExtractionDimensionSpec(QueryRunnerTestHelper.QUALITY_DIMENSION, QueryRunnerTestHelper.QUALITY_DIMENSION, helloFn));
TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.DATA_SOURCE).granularity(QueryRunnerTestHelper.ALL_GRAN).dimension(dimSpec).metric(new NumericTopNMetricSpec("numVals")).threshold(10).intervals(QueryRunnerTestHelper.FIRST_TO_THIRD).aggregators(duplicateAggregators(new CardinalityAggregatorFactory("numVals", aggregatorDimensionSpecs, false), new CardinalityAggregatorFactory("numVals1", aggregatorDimensionSpecs, false))).build();
List<Result<TopNResultValue>> expectedResults = Collections.singletonList(new Result<>(DateTimes.of("2011-04-01T00:00:00.000Z"), new TopNResultValue(withDuplicateResults(Collections.singletonList(ImmutableMap.of("market", "hello", "numVals", 1.0002442201269182d)), "numVals", "numVals1"))));
assertExpectedResults(expectedResults, query);
}
use of org.apache.druid.query.Result in project druid by druid-io.
the class TopNQueryRunnerTest method testTopNOnMissingColumnWithExtractionFn.
@Test
public void testTopNOnMissingColumnWithExtractionFn() {
TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.DATA_SOURCE).granularity(QueryRunnerTestHelper.ALL_GRAN).dimension(new ExtractionDimensionSpec("nonexistentColumn", "alias", new StringFormatExtractionFn("theValue"))).metric("rows").threshold(4).intervals(QueryRunnerTestHelper.FULL_ON_INTERVAL_SPEC).aggregators(new CountAggregatorFactory("rows")).build();
List<Result<TopNResultValue>> expectedResults = Collections.singletonList(new Result<>(DateTimes.of("2011-01-12T00:00:00.000Z"), new TopNResultValue(Collections.<Map<String, Object>>singletonList(ImmutableMap.<String, Object>builder().put("alias", "theValue").put("rows", 1209L).build()))));
assertExpectedResults(expectedResults, query);
}
use of org.apache.druid.query.Result in project druid by druid-io.
the class TopNQueryRunnerTest method testTopNLexicographicDimExtraction.
@Test
public void testTopNLexicographicDimExtraction() {
TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.DATA_SOURCE).granularity(QueryRunnerTestHelper.ALL_GRAN).dimension(new ExtractionDimensionSpec(QueryRunnerTestHelper.MARKET_DIMENSION, QueryRunnerTestHelper.MARKET_DIMENSION, new RegexDimExtractionFn("(.)", false, null))).metric(new DimensionTopNMetricSpec(null, StringComparators.LEXICOGRAPHIC)).threshold(4).intervals(QueryRunnerTestHelper.FIRST_TO_THIRD).aggregators(commonAggregators).postAggregators(QueryRunnerTestHelper.ADD_ROWS_INDEX_CONSTANT).build();
List<Result<TopNResultValue>> expectedResults = Collections.singletonList(new Result<>(DateTimes.of("2011-04-01T00:00:00.000Z"), new TopNResultValue(Arrays.<Map<String, Object>>asList(ImmutableMap.of(QueryRunnerTestHelper.MARKET_DIMENSION, "s", "rows", 18L, "index", 2231.876812D, "addRowsIndexConstant", 2250.876812D, "uniques", QueryRunnerTestHelper.UNIQUES_9), ImmutableMap.of(QueryRunnerTestHelper.MARKET_DIMENSION, "t", "rows", 4L, "index", 5351.814783D, "addRowsIndexConstant", 5356.814783D, "uniques", QueryRunnerTestHelper.UNIQUES_2), ImmutableMap.of(QueryRunnerTestHelper.MARKET_DIMENSION, "u", "rows", 4L, "index", 4875.669692D, "addRowsIndexConstant", 4880.669692D, "uniques", QueryRunnerTestHelper.UNIQUES_2)))));
assertExpectedResults(expectedResults, query);
}
use of org.apache.druid.query.Result in project druid by druid-io.
the class TopNQueryRunnerTest method testFullOnTopNLongColumnWithExFn.
@Test
public void testFullOnTopNLongColumnWithExFn() {
String jsFn = "function(str) { return 'super-' + str; }";
ExtractionFn jsExtractionFn = new JavaScriptExtractionFn(jsFn, false, JavaScriptConfig.getEnabledInstance());
TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.DATA_SOURCE).granularity(QueryRunnerTestHelper.ALL_GRAN).dimension(new ExtractionDimensionSpec("qualityLong", "ql_alias", jsExtractionFn)).metric("maxIndex").threshold(4).intervals(QueryRunnerTestHelper.FULL_ON_INTERVAL_SPEC).aggregators(Lists.newArrayList(Iterables.concat(commonAggregators, Lists.newArrayList(new DoubleMaxAggregatorFactory("maxIndex", "index"), new DoubleMinAggregatorFactory("minIndex", "index"))))).postAggregators(QueryRunnerTestHelper.ADD_ROWS_INDEX_CONSTANT).build();
List<Result<TopNResultValue>> expectedResults = Collections.singletonList(new Result<>(DateTimes.of("2011-01-12T00:00:00.000Z"), new TopNResultValue(Arrays.<Map<String, Object>>asList(ImmutableMap.<String, Object>builder().put("ql_alias", "super-1400").put(QueryRunnerTestHelper.INDEX_METRIC, 217725.41940800005D).put("rows", 279L).put("addRowsIndexConstant", 218005.41940800005D).put("uniques", QueryRunnerTestHelper.UNIQUES_1).put("maxIndex", 1870.061029D).put("minIndex", 91.270553D).build(), ImmutableMap.<String, Object>builder().put("ql_alias", "super-1600").put(QueryRunnerTestHelper.INDEX_METRIC, 210865.67977600006D).put("rows", 279L).put("addRowsIndexConstant", 211145.67977600006D).put("uniques", QueryRunnerTestHelper.UNIQUES_1).put("maxIndex", 1862.737933D).put("minIndex", 99.284525D).build(), ImmutableMap.<String, Object>builder().put("ql_alias", "super-1000").put(QueryRunnerTestHelper.INDEX_METRIC, 12270.807093D).put("rows", 93L).put("addRowsIndexConstant", 12364.807093D).put("uniques", QueryRunnerTestHelper.UNIQUES_1).put("maxIndex", 277.273533D).put("minIndex", 71.315931D).build(), ImmutableMap.<String, Object>builder().put("ql_alias", "super-1200").put(QueryRunnerTestHelper.INDEX_METRIC, 12086.472791D).put("rows", 93L).put("addRowsIndexConstant", 12180.472791D).put("uniques", QueryRunnerTestHelper.UNIQUES_1).put("maxIndex", 193.787574D).put("minIndex", 84.710523D).build()))));
assertExpectedResults(expectedResults, query);
}
Aggregations