mirror of https://github.com/apache/druid.git
Merge pull request #674 from metamx/fix-arbitrary-granularity
fix missing queryGranularity in ArbitraryGranularitySpec
This commit is contained in:
commit
9a371f3490
|
@ -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<Interval> intervals;
|
||||
private final QueryGranularity queryGranularity;
|
||||
|
||||
@JsonCreator
|
||||
public ArbitraryGranularitySpec(
|
||||
@JsonProperty("queryGranularity") QueryGranularity queryGranularity,
|
||||
@JsonProperty("intervals") List<Interval> 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)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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"),
|
||||
|
|
Loading…
Reference in New Issue