From ebd100cbb01e442c6d34eda7983270ba943115c2 Mon Sep 17 00:00:00 2001 From: Jihoon Son Date: Thu, 23 Feb 2017 10:38:43 +0900 Subject: [PATCH] Set default query granularity for null value (#3965) --- docs/content/ingestion/index.md | 5 ++--- .../granularity/ArbitraryGranularitySpec.java | 5 ++--- .../granularity/ArbitraryGranularityTest.java | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/docs/content/ingestion/index.md b/docs/content/ingestion/index.md index 117e54009bd..fe381953828 100644 --- a/docs/content/ingestion/index.md +++ b/docs/content/ingestion/index.md @@ -175,7 +175,8 @@ handle all formatting decisions on their own, without using the ParseSpec. ## GranularitySpec -The default granularity spec is `uniform`. +The default granularity spec is `uniform`, and can be changed by setting the `type` field. +Currently, `uniform` and `arbitrary` types are supported. ### Uniform Granularity Spec @@ -183,7 +184,6 @@ This spec is used to generated segments with uniform intervals. | Field | Type | Description | Required | |-------|------|-------------|----------| -| type | string | The type of granularity spec. | no (default == 'uniform') | | segmentGranularity | string | The granularity to create segments at. | no (default == 'DAY') | | queryGranularity | string | The minimum granularity to be able to query results at and the granularity of the data inside the segment. E.g. a value of "minute" will mean that data is aggregated at minutely granularity. That is, if there are collisions in the tuple (minute(timestamp), dimensions), then it will aggregate values together using the aggregators instead of storing individual rows. | no (default == 'NONE') | | rollup | boolean | rollup or not | no (default == true) | @@ -196,7 +196,6 @@ This spec is used to generate segments with arbitrary intervals (it tries to cre | Field | Type | Description | Required | |-------|------|-------------|----------| -| type | string | The type of granularity spec. | no (default == 'uniform') | | queryGranularity | string | The minimum granularity to be able to query results at and the granularity of the data inside the segment. E.g. a value of "minute" will mean that data is aggregated at minutely granularity. That is, if there are collisions in the tuple (minute(timestamp), dimensions), then it will aggregate values together using the aggregators instead of storing individual rows. | no (default == 'NONE') | | rollup | boolean | rollup or not | no (default == true) | | intervals | string | A list of intervals for the raw data being ingested. Ignored for real-time ingestion. | yes for batch, no for real-time | diff --git a/server/src/main/java/io/druid/segment/indexing/granularity/ArbitraryGranularitySpec.java b/server/src/main/java/io/druid/segment/indexing/granularity/ArbitraryGranularitySpec.java index e946be6d9e2..54a3e3cf7e8 100644 --- a/server/src/main/java/io/druid/segment/indexing/granularity/ArbitraryGranularitySpec.java +++ b/server/src/main/java/io/druid/segment/indexing/granularity/ArbitraryGranularitySpec.java @@ -27,12 +27,11 @@ import com.google.common.collect.Iterators; import com.google.common.collect.Lists; import com.google.common.collect.PeekingIterator; import com.google.common.collect.Sets; - import io.druid.common.utils.JodaUtils; +import io.druid.granularity.QueryGranularities; import io.druid.granularity.QueryGranularity; import io.druid.java.util.common.Granularity; import io.druid.java.util.common.guava.Comparators; - import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.joda.time.Interval; @@ -57,7 +56,7 @@ public class ArbitraryGranularitySpec implements GranularitySpec ) { - this.queryGranularity = queryGranularity; + this.queryGranularity = queryGranularity == null ? QueryGranularities.NONE : queryGranularity; this.rollup = rollup == null ? Boolean.TRUE : rollup; this.intervals = Sets.newTreeSet(Comparators.intervalsByStartThenEnd()); this.timezone = timezone; diff --git a/server/src/test/java/io/druid/segment/indexing/granularity/ArbitraryGranularityTest.java b/server/src/test/java/io/druid/segment/indexing/granularity/ArbitraryGranularityTest.java index e2fb8bfa1dc..a711a44d06f 100644 --- a/server/src/test/java/io/druid/segment/indexing/granularity/ArbitraryGranularityTest.java +++ b/server/src/test/java/io/druid/segment/indexing/granularity/ArbitraryGranularityTest.java @@ -40,6 +40,21 @@ public class ArbitraryGranularityTest { private static final ObjectMapper jsonMapper = new DefaultObjectMapper(); + @Test + public void testDefaultQueryGranularity() + { + final GranularitySpec spec = new ArbitraryGranularitySpec( + null, + Lists.newArrayList( + new Interval("2012-01-08T00Z/2012-01-11T00Z"), + new Interval("2012-02-01T00Z/2012-03-01T00Z"), + new Interval("2012-01-07T00Z/2012-01-08T00Z"), + new Interval("2012-01-03T00Z/2012-01-04T00Z"), + new Interval("2012-01-01T00Z/2012-01-03T00Z") + )); + Assert.assertNotNull(spec.getQueryGranularity()); + } + @Test public void testSimple() {