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 dd1a5b4bbde..807764e515c 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 @@ -21,6 +21,7 @@ package io.druid.segment.indexing.granularity; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.api.client.util.Lists; import com.google.common.base.Optional; import com.google.common.collect.Iterators; import com.google.common.collect.PeekingIterator; @@ -38,13 +39,16 @@ import java.util.TreeSet; public class ArbitraryGranularitySpec implements GranularitySpec { private final TreeSet intervals; + private final QueryGranularity queryGranularity; @JsonCreator public ArbitraryGranularitySpec( + @JsonProperty("queryGranularity") QueryGranularity queryGranularity, @JsonProperty("intervals") List inputIntervals ) { - intervals = Sets.newTreeSet(Comparators.intervalsByStartThenEnd()); + this.queryGranularity = queryGranularity; + this.intervals = Sets.newTreeSet(Comparators.intervalsByStartThenEnd()); // Insert all intervals for (final Interval inputInterval : inputIntervals) { @@ -98,14 +102,18 @@ public class ArbitraryGranularitySpec implements GranularitySpec } @Override + @JsonProperty("queryGranularity") public QueryGranularity getQueryGranularity() { - throw new UnsupportedOperationException(); + return queryGranularity; } @Override public GranularitySpec withQueryGranularity(QueryGranularity queryGranularity) { - throw new UnsupportedOperationException(); + return new ArbitraryGranularitySpec( + queryGranularity, + Lists.newArrayList(intervals) + ); } } diff --git a/server/src/main/java/io/druid/segment/indexing/granularity/UniformGranularitySpec.java b/server/src/main/java/io/druid/segment/indexing/granularity/UniformGranularitySpec.java index d494eb2ee47..d83f824366e 100644 --- a/server/src/main/java/io/druid/segment/indexing/granularity/UniformGranularitySpec.java +++ b/server/src/main/java/io/druid/segment/indexing/granularity/UniformGranularitySpec.java @@ -68,7 +68,7 @@ public class UniformGranularitySpec implements GranularitySpec Iterables.addAll(granularIntervals, this.segmentGranularity.getIterable(inputInterval)); } this.inputIntervals = ImmutableList.copyOf(inputIntervals); - this.wrappedSpec = new ArbitraryGranularitySpec(granularIntervals); + this.wrappedSpec = new ArbitraryGranularitySpec(queryGranularity, granularIntervals); } else { this.inputIntervals = null; this.wrappedSpec = null; 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 910bdfe0df8..ad8f4c721db 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 @@ -23,6 +23,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.base.Optional; import com.google.common.base.Throwables; import com.google.common.collect.Lists; +import io.druid.granularity.QueryGranularity; import io.druid.jackson.DefaultObjectMapper; import org.joda.time.DateTime; import org.joda.time.Interval; @@ -38,7 +39,9 @@ public class ArbitraryGranularityTest @Test public void testSimple() { - final GranularitySpec spec = new ArbitraryGranularitySpec(Lists.newArrayList( + final GranularitySpec spec = new ArbitraryGranularitySpec( + QueryGranularity.NONE, + 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"), @@ -111,7 +114,7 @@ public class ArbitraryGranularityTest boolean thrown = false; try { - final GranularitySpec spec = new ArbitraryGranularitySpec(intervals); + final GranularitySpec spec = new ArbitraryGranularitySpec(QueryGranularity.NONE, intervals); } catch(IllegalArgumentException e) { thrown = true; } @@ -129,7 +132,7 @@ public class ArbitraryGranularityTest boolean thrown = false; try { - final GranularitySpec spec = new ArbitraryGranularitySpec(intervals); + final GranularitySpec spec = new ArbitraryGranularitySpec(QueryGranularity.NONE, intervals); } catch(IllegalArgumentException e) { thrown = true; } @@ -140,7 +143,7 @@ public class ArbitraryGranularityTest @Test public void testJson() { - final GranularitySpec spec = new ArbitraryGranularitySpec(Lists.newArrayList( + final GranularitySpec spec = new ArbitraryGranularitySpec(QueryGranularity.NONE, 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"),