Search in sources :

Example 11 with CountAggregatorFactory

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

the class KafkaSupervisorTest method getDataSchema.

private DataSchema getDataSchema(String dataSource) {
    List<DimensionSchema> dimensions = new ArrayList<>();
    dimensions.add(StringDimensionSchema.create("dim1"));
    dimensions.add(StringDimensionSchema.create("dim2"));
    return new DataSchema(dataSource, objectMapper.convertValue(new StringInputRowParser(new JSONParseSpec(new TimestampSpec("timestamp", "iso", null), new DimensionsSpec(dimensions, null, null), new JSONPathSpec(true, ImmutableList.<JSONPathFieldSpec>of()), ImmutableMap.<String, Boolean>of()), Charsets.UTF_8.name()), Map.class), new AggregatorFactory[] { new CountAggregatorFactory("rows") }, new UniformGranularitySpec(Granularities.HOUR, Granularities.NONE, ImmutableList.<Interval>of()), objectMapper);
}
Also used : ArrayList(java.util.ArrayList) EasyMock.anyString(org.easymock.EasyMock.anyString) StringDimensionSchema(io.druid.data.input.impl.StringDimensionSchema) DimensionSchema(io.druid.data.input.impl.DimensionSchema) DataSchema(io.druid.segment.indexing.DataSchema) UniformGranularitySpec(io.druid.segment.indexing.granularity.UniformGranularitySpec) CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) StringInputRowParser(io.druid.data.input.impl.StringInputRowParser) TimestampSpec(io.druid.data.input.impl.TimestampSpec) DimensionsSpec(io.druid.data.input.impl.DimensionsSpec) JSONPathSpec(io.druid.data.input.impl.JSONPathSpec) JSONParseSpec(io.druid.data.input.impl.JSONParseSpec) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Interval(org.joda.time.Interval)

Example 12 with CountAggregatorFactory

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

the class SameIntervalMergeTaskTest method testRun.

@Test
public void testRun() throws Exception {
    final List<AggregatorFactory> aggregators = ImmutableList.<AggregatorFactory>of(new CountAggregatorFactory("cnt"));
    final SameIntervalMergeTask task = new SameIntervalMergeTask(null, "foo", new Interval("2010-01-01/P1D"), aggregators, true, indexSpec, true, null);
    String newVersion = "newVersion";
    final List<DataSegment> segments = runTask(task, newVersion);
    // the lock is acquired
    Assert.assertEquals(0, isRedayCountDown.getCount());
    // the merged segment is published
    Assert.assertEquals(0, publishCountDown.getCount());
    // the merged segment is the only element
    Assert.assertEquals(1, segments.size());
    DataSegment mergeSegment = segments.get(0);
    Assert.assertEquals("foo", mergeSegment.getDataSource());
    Assert.assertEquals(newVersion, mergeSegment.getVersion());
    // the merged segment's interval is within the requested interval
    Assert.assertTrue(new Interval("2010-01-01/P1D").contains(mergeSegment.getInterval()));
    // the merged segment should be NoneShardSpec
    Assert.assertTrue(mergeSegment.getShardSpec() instanceof NoneShardSpec);
}
Also used : CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) NoneShardSpec(io.druid.timeline.partition.NoneShardSpec) AggregatorFactory(io.druid.query.aggregation.AggregatorFactory) CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) DataSegment(io.druid.timeline.DataSegment) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 13 with CountAggregatorFactory

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

the class TaskSerdeTest method testAppendTaskSerde.

@Test
public void testAppendTaskSerde() throws Exception {
    final List<DataSegment> segments = ImmutableList.of(DataSegment.builder().dataSource("foo").interval(new Interval("2010-01-01/P1D")).version("1234").build(), DataSegment.builder().dataSource("foo").interval(new Interval("2010-01-02/P1D")).version("5678").build());
    final AppendTask task = new AppendTask(null, "foo", segments, ImmutableList.<AggregatorFactory>of(new CountAggregatorFactory("cnt")), indexSpec, true, null);
    final String json = jsonMapper.writeValueAsString(task);
    // Just want to run the clock a bit to make sure the task id doesn't change
    Thread.sleep(100);
    final AppendTask task2 = (AppendTask) jsonMapper.readValue(json, Task.class);
    Assert.assertEquals("foo", task.getDataSource());
    Assert.assertEquals(new Interval("2010-01-01/P2D"), task.getInterval());
    Assert.assertEquals(task.getId(), task2.getId());
    Assert.assertEquals(task.getGroupId(), task2.getGroupId());
    Assert.assertEquals(task.getDataSource(), task2.getDataSource());
    Assert.assertEquals(task.getInterval(), task2.getInterval());
    Assert.assertEquals(task.getSegments(), task2.getSegments());
    final AppendTask task3 = (AppendTask) jsonMapper.readValue(jsonMapper.writeValueAsString(new ClientAppendQuery("foo", segments)), Task.class);
    Assert.assertEquals("foo", task3.getDataSource());
    Assert.assertEquals(new Interval("2010-01-01/P2D"), task3.getInterval());
    Assert.assertEquals(task3.getSegments(), segments);
    Assert.assertEquals(task.getAggregators(), task2.getAggregators());
}
Also used : ClientAppendQuery(io.druid.client.indexing.ClientAppendQuery) CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) DataSegment(io.druid.timeline.DataSegment) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 14 with CountAggregatorFactory

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

the class TaskSerdeTest method testMergeTaskSerde.

@Test
public void testMergeTaskSerde() throws Exception {
    final List<DataSegment> segments = ImmutableList.<DataSegment>of(DataSegment.builder().dataSource("foo").interval(new Interval("2010-01-01/P1D")).version("1234").build());
    final List<AggregatorFactory> aggregators = ImmutableList.<AggregatorFactory>of(new CountAggregatorFactory("cnt"));
    final MergeTask task = new MergeTask(null, "foo", segments, aggregators, true, indexSpec, true, null);
    final String json = jsonMapper.writeValueAsString(task);
    // Just want to run the clock a bit to make sure the task id doesn't change
    Thread.sleep(100);
    final MergeTask task2 = (MergeTask) jsonMapper.readValue(json, Task.class);
    Assert.assertEquals("foo", task.getDataSource());
    Assert.assertEquals(new Interval("2010-01-01/P1D"), task.getInterval());
    Assert.assertEquals(task.getId(), task2.getId());
    Assert.assertEquals(task.getGroupId(), task2.getGroupId());
    Assert.assertEquals(task.getDataSource(), task2.getDataSource());
    Assert.assertEquals(task.getInterval(), task2.getInterval());
    Assert.assertEquals(task.getSegments(), task2.getSegments());
    Assert.assertEquals(task.getAggregators().get(0).getName(), task2.getAggregators().get(0).getName());
    final MergeTask task3 = (MergeTask) jsonMapper.readValue(jsonMapper.writeValueAsString(new ClientMergeQuery("foo", segments, aggregators)), Task.class);
    Assert.assertEquals("foo", task3.getDataSource());
    Assert.assertEquals(new Interval("2010-01-01/P1D"), task3.getInterval());
    Assert.assertEquals(segments, task3.getSegments());
    Assert.assertEquals(aggregators, task3.getAggregators());
}
Also used : CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) ClientMergeQuery(io.druid.client.indexing.ClientMergeQuery) AggregatorFactory(io.druid.query.aggregation.AggregatorFactory) CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) DoubleSumAggregatorFactory(io.druid.query.aggregation.DoubleSumAggregatorFactory) DataSegment(io.druid.timeline.DataSegment) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 15 with CountAggregatorFactory

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

the class TaskSerdeTest method testSameIntervalMergeTaskSerde.

@Test
public void testSameIntervalMergeTaskSerde() throws Exception {
    final List<AggregatorFactory> aggregators = ImmutableList.<AggregatorFactory>of(new CountAggregatorFactory("cnt"));
    final SameIntervalMergeTask task = new SameIntervalMergeTask(null, "foo", new Interval("2010-01-01/P1D"), aggregators, true, indexSpec, true, null);
    final String json = jsonMapper.writeValueAsString(task);
    // Just want to run the clock a bit to make sure the task id doesn't change
    Thread.sleep(100);
    final SameIntervalMergeTask task2 = (SameIntervalMergeTask) jsonMapper.readValue(json, Task.class);
    Assert.assertEquals("foo", task.getDataSource());
    Assert.assertEquals(new Interval("2010-01-01/P1D"), task.getInterval());
    Assert.assertEquals(task.getId(), task2.getId());
    Assert.assertEquals(task.getGroupId(), task2.getGroupId());
    Assert.assertEquals(task.getDataSource(), task2.getDataSource());
    Assert.assertEquals(task.getInterval(), task2.getInterval());
    Assert.assertEquals(task.getRollup(), task2.getRollup());
    Assert.assertEquals(task.getBuildV9Directly(), task2.getBuildV9Directly());
    Assert.assertEquals(task.getIndexSpec(), task2.getIndexSpec());
    Assert.assertEquals(task.getAggregators().get(0).getName(), task2.getAggregators().get(0).getName());
}
Also used : CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) AggregatorFactory(io.druid.query.aggregation.AggregatorFactory) CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) DoubleSumAggregatorFactory(io.druid.query.aggregation.DoubleSumAggregatorFactory) Interval(org.joda.time.Interval) Test(org.junit.Test)

Aggregations

CountAggregatorFactory (io.druid.query.aggregation.CountAggregatorFactory)102 Test (org.junit.Test)81 AggregatorFactory (io.druid.query.aggregation.AggregatorFactory)54 Interval (org.joda.time.Interval)35 LongSumAggregatorFactory (io.druid.query.aggregation.LongSumAggregatorFactory)33 DateTime (org.joda.time.DateTime)30 Result (io.druid.query.Result)27 OnheapIncrementalIndex (io.druid.segment.incremental.OnheapIncrementalIndex)25 IncrementalIndex (io.druid.segment.incremental.IncrementalIndex)23 DoubleSumAggregatorFactory (io.druid.query.aggregation.DoubleSumAggregatorFactory)19 FilteredAggregatorFactory (io.druid.query.aggregation.FilteredAggregatorFactory)18 DefaultDimensionSpec (io.druid.query.dimension.DefaultDimensionSpec)16 TimeseriesQuery (io.druid.query.timeseries.TimeseriesQuery)16 TimeseriesResultValue (io.druid.query.timeseries.TimeseriesResultValue)16 File (java.io.File)15 TimeseriesQueryEngine (io.druid.query.timeseries.TimeseriesQueryEngine)14 TimeseriesQueryRunnerFactory (io.druid.query.timeseries.TimeseriesQueryRunnerFactory)14 QueryRunner (io.druid.query.QueryRunner)13 TimeseriesQueryQueryToolChest (io.druid.query.timeseries.TimeseriesQueryQueryToolChest)13 MapBasedInputRow (io.druid.data.input.MapBasedInputRow)12