Search in sources :

Example 41 with Result

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);
}
Also used : LongSumAggregatorFactory(org.apache.druid.query.aggregation.LongSumAggregatorFactory) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Result(org.apache.druid.query.Result) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 42 with Result

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);
}
Also used : DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) ExtractionDimensionSpec(org.apache.druid.query.dimension.ExtractionDimensionSpec) DimensionSpec(org.apache.druid.query.dimension.DimensionSpec) ListFilteredDimensionSpec(org.apache.druid.query.dimension.ListFilteredDimensionSpec) JavaScriptExtractionFn(org.apache.druid.query.extraction.JavaScriptExtractionFn) Result(org.apache.druid.query.Result) ExtractionFn(org.apache.druid.query.extraction.ExtractionFn) DimExtractionFn(org.apache.druid.query.extraction.DimExtractionFn) RegexDimExtractionFn(org.apache.druid.query.extraction.RegexDimExtractionFn) StringFormatExtractionFn(org.apache.druid.query.extraction.StringFormatExtractionFn) JavaScriptExtractionFn(org.apache.druid.query.extraction.JavaScriptExtractionFn) LookupExtractionFn(org.apache.druid.query.lookup.LookupExtractionFn) TimeFormatExtractionFn(org.apache.druid.query.extraction.TimeFormatExtractionFn) StrlenExtractionFn(org.apache.druid.query.extraction.StrlenExtractionFn) CardinalityAggregatorFactory(org.apache.druid.query.aggregation.cardinality.CardinalityAggregatorFactory) ExtractionDimensionSpec(org.apache.druid.query.dimension.ExtractionDimensionSpec) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 43 with Result

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);
}
Also used : CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) StringFormatExtractionFn(org.apache.druid.query.extraction.StringFormatExtractionFn) ExtractionDimensionSpec(org.apache.druid.query.dimension.ExtractionDimensionSpec) Result(org.apache.druid.query.Result) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 44 with Result

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);
}
Also used : RegexDimExtractionFn(org.apache.druid.query.extraction.RegexDimExtractionFn) ExtractionDimensionSpec(org.apache.druid.query.dimension.ExtractionDimensionSpec) Result(org.apache.druid.query.Result) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 45 with Result

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);
}
Also used : DoubleMaxAggregatorFactory(org.apache.druid.query.aggregation.DoubleMaxAggregatorFactory) JavaScriptExtractionFn(org.apache.druid.query.extraction.JavaScriptExtractionFn) DoubleMinAggregatorFactory(org.apache.druid.query.aggregation.DoubleMinAggregatorFactory) Result(org.apache.druid.query.Result) ExtractionFn(org.apache.druid.query.extraction.ExtractionFn) DimExtractionFn(org.apache.druid.query.extraction.DimExtractionFn) RegexDimExtractionFn(org.apache.druid.query.extraction.RegexDimExtractionFn) StringFormatExtractionFn(org.apache.druid.query.extraction.StringFormatExtractionFn) JavaScriptExtractionFn(org.apache.druid.query.extraction.JavaScriptExtractionFn) LookupExtractionFn(org.apache.druid.query.lookup.LookupExtractionFn) TimeFormatExtractionFn(org.apache.druid.query.extraction.TimeFormatExtractionFn) StrlenExtractionFn(org.apache.druid.query.extraction.StrlenExtractionFn) ExtractionDimensionSpec(org.apache.druid.query.dimension.ExtractionDimensionSpec) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Aggregations

Result (org.apache.druid.query.Result)252 Test (org.junit.Test)181 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)143 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)46 TimeseriesResultValue (org.apache.druid.query.timeseries.TimeseriesResultValue)44 TimeseriesQuery (org.apache.druid.query.timeseries.TimeseriesQuery)41 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)40 QueryRunner (org.apache.druid.query.QueryRunner)37 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)36 DoubleMaxAggregatorFactory (org.apache.druid.query.aggregation.DoubleMaxAggregatorFactory)34 DoubleMinAggregatorFactory (org.apache.druid.query.aggregation.DoubleMinAggregatorFactory)34 ArrayList (java.util.ArrayList)33 FinalizeResultsQueryRunner (org.apache.druid.query.FinalizeResultsQueryRunner)32 ExtractionDimensionSpec (org.apache.druid.query.dimension.ExtractionDimensionSpec)32 SelectorDimFilter (org.apache.druid.query.filter.SelectorDimFilter)31 TopNResultValue (org.apache.druid.query.topn.TopNResultValue)28 DateTime (org.joda.time.DateTime)28 Benchmark (org.openjdk.jmh.annotations.Benchmark)28 BenchmarkMode (org.openjdk.jmh.annotations.BenchmarkMode)28 OutputTimeUnit (org.openjdk.jmh.annotations.OutputTimeUnit)28