fix missing queryGranularity in ArbitraryGranularitySpec

This commit is contained in:
Xavier Léauté 2014-08-08 15:11:35 -07:00
parent 9f4dd7b33e
commit 3826b1d976
3 changed files with 19 additions and 8 deletions

View File

@ -21,6 +21,7 @@ package io.druid.segment.indexing.granularity;
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.api.client.util.Lists;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.collect.Iterators; import com.google.common.collect.Iterators;
import com.google.common.collect.PeekingIterator; import com.google.common.collect.PeekingIterator;
@ -38,13 +39,16 @@ import java.util.TreeSet;
public class ArbitraryGranularitySpec implements GranularitySpec public class ArbitraryGranularitySpec implements GranularitySpec
{ {
private final TreeSet<Interval> intervals; private final TreeSet<Interval> intervals;
private final QueryGranularity queryGranularity;
@JsonCreator @JsonCreator
public ArbitraryGranularitySpec( public ArbitraryGranularitySpec(
@JsonProperty("queryGranularity") QueryGranularity queryGranularity,
@JsonProperty("intervals") List<Interval> inputIntervals @JsonProperty("intervals") List<Interval> inputIntervals
) )
{ {
intervals = Sets.newTreeSet(Comparators.intervalsByStartThenEnd()); this.queryGranularity = queryGranularity;
this.intervals = Sets.newTreeSet(Comparators.intervalsByStartThenEnd());
// Insert all intervals // Insert all intervals
for (final Interval inputInterval : inputIntervals) { for (final Interval inputInterval : inputIntervals) {
@ -98,14 +102,18 @@ public class ArbitraryGranularitySpec implements GranularitySpec
} }
@Override @Override
@JsonProperty("queryGranularity")
public QueryGranularity getQueryGranularity() public QueryGranularity getQueryGranularity()
{ {
throw new UnsupportedOperationException(); return queryGranularity;
} }
@Override @Override
public GranularitySpec withQueryGranularity(QueryGranularity queryGranularity) public GranularitySpec withQueryGranularity(QueryGranularity queryGranularity)
{ {
throw new UnsupportedOperationException(); return new ArbitraryGranularitySpec(
queryGranularity,
Lists.newArrayList(intervals)
);
} }
} }

View File

@ -68,7 +68,7 @@ public class UniformGranularitySpec implements GranularitySpec
Iterables.addAll(granularIntervals, this.segmentGranularity.getIterable(inputInterval)); Iterables.addAll(granularIntervals, this.segmentGranularity.getIterable(inputInterval));
} }
this.inputIntervals = ImmutableList.copyOf(inputIntervals); this.inputIntervals = ImmutableList.copyOf(inputIntervals);
this.wrappedSpec = new ArbitraryGranularitySpec(granularIntervals); this.wrappedSpec = new ArbitraryGranularitySpec(queryGranularity, granularIntervals);
} else { } else {
this.inputIntervals = null; this.inputIntervals = null;
this.wrappedSpec = null; this.wrappedSpec = null;

View File

@ -23,6 +23,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import io.druid.granularity.QueryGranularity;
import io.druid.jackson.DefaultObjectMapper; import io.druid.jackson.DefaultObjectMapper;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.joda.time.Interval; import org.joda.time.Interval;
@ -38,7 +39,9 @@ public class ArbitraryGranularityTest
@Test @Test
public void testSimple() 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-01-08T00Z/2012-01-11T00Z"),
new Interval("2012-02-01T00Z/2012-03-01T00Z"), new Interval("2012-02-01T00Z/2012-03-01T00Z"),
new Interval("2012-01-07T00Z/2012-01-08T00Z"), new Interval("2012-01-07T00Z/2012-01-08T00Z"),
@ -111,7 +114,7 @@ public class ArbitraryGranularityTest
boolean thrown = false; boolean thrown = false;
try { try {
final GranularitySpec spec = new ArbitraryGranularitySpec(intervals); final GranularitySpec spec = new ArbitraryGranularitySpec(QueryGranularity.NONE, intervals);
} catch(IllegalArgumentException e) { } catch(IllegalArgumentException e) {
thrown = true; thrown = true;
} }
@ -129,7 +132,7 @@ public class ArbitraryGranularityTest
boolean thrown = false; boolean thrown = false;
try { try {
final GranularitySpec spec = new ArbitraryGranularitySpec(intervals); final GranularitySpec spec = new ArbitraryGranularitySpec(QueryGranularity.NONE, intervals);
} catch(IllegalArgumentException e) { } catch(IllegalArgumentException e) {
thrown = true; thrown = true;
} }
@ -140,7 +143,7 @@ public class ArbitraryGranularityTest
@Test @Test
public void testJson() 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-01-08T00Z/2012-01-11T00Z"),
new Interval("2012-02-01T00Z/2012-03-01T00Z"), new Interval("2012-02-01T00Z/2012-03-01T00Z"),
new Interval("2012-01-07T00Z/2012-01-08T00Z"), new Interval("2012-01-07T00Z/2012-01-08T00Z"),