Search in sources :

Example 6 with AggregationTestHelper

use of io.druid.query.aggregation.AggregationTestHelper in project druid by druid-io.

the class SketchAggregationTestWithSimpleData method testSimpleDataIngestAndTimeseriesQuery.

@Test
public void testSimpleDataIngestAndTimeseriesQuery() throws Exception {
    AggregationTestHelper timeseriesQueryAggregationTestHelper = AggregationTestHelper.createTimeseriesQueryAggregationTestHelper(sm.getJacksonModules(), tempFolder);
    Sequence seq = timeseriesQueryAggregationTestHelper.runQueryOnSegments(ImmutableList.of(s1, s2), readFileFromClasspathAsString("timeseries_query.json"));
    Result<TimeseriesResultValue> result = (Result<TimeseriesResultValue>) Iterables.getOnlyElement(Sequences.toList(seq, Lists.newArrayList()));
    Assert.assertEquals(new DateTime("2014-10-20T00:00:00.000Z"), result.getTimestamp());
    Assert.assertEquals(50.0, result.getValue().getDoubleMetric("sketch_count"), 0.01);
    Assert.assertEquals(50.0, result.getValue().getDoubleMetric("sketchEstimatePostAgg"), 0.01);
    Assert.assertEquals(50.0, result.getValue().getDoubleMetric("sketchUnionPostAggEstimate"), 0.01);
    Assert.assertEquals(50.0, result.getValue().getDoubleMetric("sketchIntersectionPostAggEstimate"), 0.01);
    Assert.assertEquals(0.0, result.getValue().getDoubleMetric("sketchAnotBPostAggEstimate"), 0.01);
    Assert.assertEquals(0.0, result.getValue().getDoubleMetric("non_existing_col_validation"), 0.01);
}
Also used : TimeseriesResultValue(io.druid.query.timeseries.TimeseriesResultValue) AggregationTestHelper(io.druid.query.aggregation.AggregationTestHelper) Sequence(io.druid.java.util.common.guava.Sequence) DateTime(org.joda.time.DateTime) Result(io.druid.query.Result) Test(org.junit.Test) GroupByQueryRunnerTest(io.druid.query.groupby.GroupByQueryRunnerTest)

Example 7 with AggregationTestHelper

use of io.druid.query.aggregation.AggregationTestHelper in project druid by druid-io.

the class SketchAggregationTestWithSimpleData method setup.

@Before
public void setup() throws Exception {
    sm = new SketchModule();
    sm.configure(null);
    AggregationTestHelper toolchest = AggregationTestHelper.createGroupByQueryAggregationTestHelper(sm.getJacksonModules(), config, tempFolder);
    s1 = tempFolder.newFolder();
    toolchest.createIndex(new File(this.getClass().getClassLoader().getResource("simple_test_data.tsv").getFile()), readFileFromClasspathAsString("simple_test_data_record_parser.json"), readFileFromClasspathAsString("simple_test_data_aggregators.json"), s1, 0, Granularities.NONE, 5000);
    s2 = tempFolder.newFolder();
    toolchest.createIndex(new File(this.getClass().getClassLoader().getResource("simple_test_data.tsv").getFile()), readFileFromClasspathAsString("simple_test_data_record_parser.json"), readFileFromClasspathAsString("simple_test_data_aggregators.json"), s2, 0, Granularities.NONE, 5000);
}
Also used : AggregationTestHelper(io.druid.query.aggregation.AggregationTestHelper) File(java.io.File) Before(org.junit.Before)

Example 8 with AggregationTestHelper

use of io.druid.query.aggregation.AggregationTestHelper in project druid by druid-io.

the class FinalizingFieldAccessPostAggregatorTest method testIngestAndQueryWithArithmeticPostAggregator.

@Test
public void testIngestAndQueryWithArithmeticPostAggregator() throws Exception {
    AggregationTestHelper helper = AggregationTestHelper.createGroupByQueryAggregationTestHelper(Lists.newArrayList(new AggregatorsModule()), GroupByQueryRunnerTest.testConfigs().get(0), tempFoler);
    String metricSpec = "[{\"type\": \"hyperUnique\", \"name\": \"hll_market\", \"fieldName\": \"market\"}," + "{\"type\": \"hyperUnique\", \"name\": \"hll_quality\", \"fieldName\": \"quality\"}]";
    String parseSpec = "{" + "\"type\" : \"string\"," + "\"parseSpec\" : {" + "    \"format\" : \"tsv\"," + "    \"timestampSpec\" : {" + "        \"column\" : \"timestamp\"," + "        \"format\" : \"auto\"" + "}," + "    \"dimensionsSpec\" : {" + "        \"dimensions\": []," + "        \"dimensionExclusions\" : []," + "        \"spatialDimensions\" : []" + "    }," + "    \"columns\": [\"timestamp\", \"market\", \"quality\", \"placement\", \"placementish\", \"index\"]" + "  }" + "}";
    String query = "{" + "\"queryType\": \"groupBy\"," + "\"dataSource\": \"test_datasource\"," + "\"granularity\": \"ALL\"," + "\"dimensions\": []," + "\"aggregations\": [" + "  { \"type\": \"hyperUnique\", \"name\": \"hll_market\", \"fieldName\": \"hll_market\" }," + "  { \"type\": \"hyperUnique\", \"name\": \"hll_quality\", \"fieldName\": \"hll_quality\" }" + "]," + "\"postAggregations\": [" + "  { \"type\": \"arithmetic\", \"name\": \"uniq_add\", \"fn\": \"+\", \"fields\":[" + "    { \"type\": \"finalizingFieldAccess\", \"name\": \"uniq_market\", \"fieldName\": \"hll_market\" }," + "    { \"type\": \"finalizingFieldAccess\", \"name\": \"uniq_quality\", \"fieldName\": \"hll_quality\" }]" + "  }" + "]," + "\"intervals\": [ \"1970/2050\" ]" + "}";
    Sequence seq = helper.createIndexAndRunQueryOnSegment(new File(this.getClass().getClassLoader().getResource("druid.sample.tsv").getFile()), parseSpec, metricSpec, 0, Granularities.NONE, 50000, query);
    MapBasedRow row = (MapBasedRow) Sequences.toList(seq, Lists.newArrayList()).get(0);
    Assert.assertEquals(3.0, row.getFloatMetric("hll_market"), 0.1);
    Assert.assertEquals(9.0, row.getFloatMetric("hll_quality"), 0.1);
    Assert.assertEquals(12.0, row.getFloatMetric("uniq_add"), 0.1);
}
Also used : AggregatorsModule(io.druid.jackson.AggregatorsModule) MapBasedRow(io.druid.data.input.MapBasedRow) AggregationTestHelper(io.druid.query.aggregation.AggregationTestHelper) Sequence(io.druid.java.util.common.guava.Sequence) File(java.io.File) Test(org.junit.Test) GroupByQueryRunnerTest(io.druid.query.groupby.GroupByQueryRunnerTest)

Aggregations

AggregationTestHelper (io.druid.query.aggregation.AggregationTestHelper)8 Sequence (io.druid.java.util.common.guava.Sequence)7 GroupByQueryRunnerTest (io.druid.query.groupby.GroupByQueryRunnerTest)7 Test (org.junit.Test)7 MapBasedRow (io.druid.data.input.MapBasedRow)4 File (java.io.File)4 AggregatorsModule (io.druid.jackson.AggregatorsModule)3 Result (io.druid.query.Result)3 DateTime (org.joda.time.DateTime)3 Row (io.druid.data.input.Row)1 SelectResultValue (io.druid.query.select.SelectResultValue)1 TimeseriesResultValue (io.druid.query.timeseries.TimeseriesResultValue)1 DimensionAndMetricValueExtractor (io.druid.query.topn.DimensionAndMetricValueExtractor)1 TopNResultValue (io.druid.query.topn.TopNResultValue)1 Before (org.junit.Before)1