Search in sources :

Example 1 with ArbitraryGranularitySpec

use of io.druid.segment.indexing.granularity.ArbitraryGranularitySpec in project druid by druid-io.

the class DataSchemaTest method testExplicitInclude.

@Test
public void testExplicitInclude() throws Exception {
    Map<String, Object> parser = jsonMapper.convertValue(new StringInputRowParser(new JSONParseSpec(new TimestampSpec("time", "auto", null), new DimensionsSpec(DimensionsSpec.getDefaultSchemas(ImmutableList.of("time", "dimA", "dimB", "col2")), ImmutableList.of("dimC"), null), null, null), null), new TypeReference<Map<String, Object>>() {
    });
    DataSchema schema = new DataSchema("test", parser, new AggregatorFactory[] { new DoubleSumAggregatorFactory("metric1", "col1"), new DoubleSumAggregatorFactory("metric2", "col2") }, new ArbitraryGranularitySpec(Granularities.DAY, ImmutableList.of(Interval.parse("2014/2015"))), jsonMapper);
    Assert.assertEquals(ImmutableSet.of("dimC", "col1", "metric1", "metric2"), schema.getParser().getParseSpec().getDimensionsSpec().getDimensionExclusions());
}
Also used : DoubleSumAggregatorFactory(io.druid.query.aggregation.DoubleSumAggregatorFactory) StringInputRowParser(io.druid.data.input.impl.StringInputRowParser) TimestampSpec(io.druid.data.input.impl.TimestampSpec) DimensionsSpec(io.druid.data.input.impl.DimensionsSpec) JSONParseSpec(io.druid.data.input.impl.JSONParseSpec) Map(java.util.Map) ArbitraryGranularitySpec(io.druid.segment.indexing.granularity.ArbitraryGranularitySpec) Test(org.junit.Test)

Example 2 with ArbitraryGranularitySpec

use of io.druid.segment.indexing.granularity.ArbitraryGranularitySpec in project druid by druid-io.

the class DataSchemaTest method testSerde.

@Test
public void testSerde() throws Exception {
    String jsonStr = "{" + "\"dataSource\":\"test\"," + "\"parser\":{" + "\"type\":\"string\"," + "\"parseSpec\":{" + "\"format\":\"json\"," + "\"timestampSpec\":{\"column\":\"xXx\", \"format\": \"auto\", \"missingValue\": null}," + "\"dimensionsSpec\":{\"dimensions\":[], \"dimensionExclusions\":[]}," + "\"flattenSpec\":{\"useFieldDiscovery\":true, \"fields\":[]}," + "\"featureSpec\":{}}," + "\"encoding\":\"UTF-8\"" + "}," + "\"metricsSpec\":[{\"type\":\"doubleSum\",\"name\":\"metric1\",\"fieldName\":\"col1\"}]," + "\"granularitySpec\":{" + "\"type\":\"arbitrary\"," + "\"queryGranularity\":{\"type\":\"duration\",\"duration\":86400000,\"origin\":\"1970-01-01T00:00:00.000Z\"}," + "\"intervals\":[\"2014-01-01T00:00:00.000Z/2015-01-01T00:00:00.000Z\"]}}";
    DataSchema actual = jsonMapper.readValue(jsonMapper.writeValueAsString(jsonMapper.readValue(jsonStr, DataSchema.class)), DataSchema.class);
    Assert.assertEquals(actual.getDataSource(), "test");
    Assert.assertEquals(actual.getParser().getParseSpec(), new JSONParseSpec(new TimestampSpec("xXx", null, null), new DimensionsSpec(null, Arrays.asList("metric1", "xXx", "col1"), null), null, null));
    Assert.assertEquals(actual.getAggregators(), new AggregatorFactory[] { new DoubleSumAggregatorFactory("metric1", "col1") });
    Assert.assertEquals(actual.getGranularitySpec(), new ArbitraryGranularitySpec(new DurationGranularity(86400000, null), ImmutableList.of(Interval.parse("2014/2015"))));
}
Also used : DoubleSumAggregatorFactory(io.druid.query.aggregation.DoubleSumAggregatorFactory) TimestampSpec(io.druid.data.input.impl.TimestampSpec) DimensionsSpec(io.druid.data.input.impl.DimensionsSpec) DurationGranularity(io.druid.java.util.common.granularity.DurationGranularity) JSONParseSpec(io.druid.data.input.impl.JSONParseSpec) ArbitraryGranularitySpec(io.druid.segment.indexing.granularity.ArbitraryGranularitySpec) Test(org.junit.Test)

Example 3 with ArbitraryGranularitySpec

use of io.druid.segment.indexing.granularity.ArbitraryGranularitySpec in project druid by druid-io.

the class DataSchemaTest method testOverlapMetricNameAndDim.

@Test(expected = IAE.class)
public void testOverlapMetricNameAndDim() throws Exception {
    Map<String, Object> parser = jsonMapper.convertValue(new StringInputRowParser(new JSONParseSpec(new TimestampSpec("time", "auto", null), new DimensionsSpec(DimensionsSpec.getDefaultSchemas(ImmutableList.of("time", "dimA", "dimB", "metric1")), ImmutableList.of("dimC"), null), null, null), null), new TypeReference<Map<String, Object>>() {
    });
    DataSchema schema = new DataSchema("test", parser, new AggregatorFactory[] { new DoubleSumAggregatorFactory("metric1", "col1"), new DoubleSumAggregatorFactory("metric2", "col2") }, new ArbitraryGranularitySpec(Granularities.DAY, ImmutableList.of(Interval.parse("2014/2015"))), jsonMapper);
    schema.getParser();
}
Also used : DoubleSumAggregatorFactory(io.druid.query.aggregation.DoubleSumAggregatorFactory) StringInputRowParser(io.druid.data.input.impl.StringInputRowParser) TimestampSpec(io.druid.data.input.impl.TimestampSpec) DimensionsSpec(io.druid.data.input.impl.DimensionsSpec) JSONParseSpec(io.druid.data.input.impl.JSONParseSpec) Map(java.util.Map) ArbitraryGranularitySpec(io.druid.segment.indexing.granularity.ArbitraryGranularitySpec) Test(org.junit.Test)

Example 4 with ArbitraryGranularitySpec

use of io.druid.segment.indexing.granularity.ArbitraryGranularitySpec in project druid by druid-io.

the class DataSchemaTest method testDuplicateAggregators.

@Test(expected = IAE.class)
public void testDuplicateAggregators() throws Exception {
    Map<String, Object> parser = jsonMapper.convertValue(new StringInputRowParser(new JSONParseSpec(new TimestampSpec("time", "auto", null), new DimensionsSpec(DimensionsSpec.getDefaultSchemas(ImmutableList.of("time")), ImmutableList.of("dimC"), null), null, null), null), new TypeReference<Map<String, Object>>() {
    });
    DataSchema schema = new DataSchema("test", parser, new AggregatorFactory[] { new DoubleSumAggregatorFactory("metric1", "col1"), new DoubleSumAggregatorFactory("metric2", "col2"), new DoubleSumAggregatorFactory("metric1", "col3") }, new ArbitraryGranularitySpec(Granularities.DAY, ImmutableList.of(Interval.parse("2014/2015"))), jsonMapper);
    schema.getParser();
}
Also used : DoubleSumAggregatorFactory(io.druid.query.aggregation.DoubleSumAggregatorFactory) StringInputRowParser(io.druid.data.input.impl.StringInputRowParser) TimestampSpec(io.druid.data.input.impl.TimestampSpec) DimensionsSpec(io.druid.data.input.impl.DimensionsSpec) JSONParseSpec(io.druid.data.input.impl.JSONParseSpec) Map(java.util.Map) ArbitraryGranularitySpec(io.druid.segment.indexing.granularity.ArbitraryGranularitySpec) Test(org.junit.Test)

Example 5 with ArbitraryGranularitySpec

use of io.druid.segment.indexing.granularity.ArbitraryGranularitySpec in project druid by druid-io.

the class IndexTaskTest method testWithArbitraryGranularity.

@Test
public void testWithArbitraryGranularity() throws Exception {
    File tmpDir = temporaryFolder.newFolder();
    File tmpFile = File.createTempFile("druid", "index", tmpDir);
    PrintWriter writer = new PrintWriter(tmpFile);
    writer.println("2014-01-01T00:00:10Z,a,1");
    writer.println("2014-01-01T01:00:20Z,b,1");
    writer.println("2014-01-01T02:00:30Z,c,1");
    writer.close();
    IndexTask indexTask = new IndexTask(null, null, createIngestionSpec(tmpDir, new ArbitraryGranularitySpec(Granularities.MINUTE, Arrays.asList(new Interval("2014/2015"))), 10, null, false, false), null, jsonMapper);
    List<DataSegment> segments = runTask(indexTask);
    Assert.assertEquals(1, segments.size());
}
Also used : File(java.io.File) ArbitraryGranularitySpec(io.druid.segment.indexing.granularity.ArbitraryGranularitySpec) DataSegment(io.druid.timeline.DataSegment) PrintWriter(java.io.PrintWriter) Interval(org.joda.time.Interval) Test(org.junit.Test)

Aggregations

ArbitraryGranularitySpec (io.druid.segment.indexing.granularity.ArbitraryGranularitySpec)6 Test (org.junit.Test)6 DimensionsSpec (io.druid.data.input.impl.DimensionsSpec)5 JSONParseSpec (io.druid.data.input.impl.JSONParseSpec)5 TimestampSpec (io.druid.data.input.impl.TimestampSpec)5 DoubleSumAggregatorFactory (io.druid.query.aggregation.DoubleSumAggregatorFactory)5 StringInputRowParser (io.druid.data.input.impl.StringInputRowParser)4 Map (java.util.Map)4 DurationGranularity (io.druid.java.util.common.granularity.DurationGranularity)1 DataSegment (io.druid.timeline.DataSegment)1 File (java.io.File)1 PrintWriter (java.io.PrintWriter)1 Interval (org.joda.time.Interval)1