提交 9a371f34 编写于 作者: F fjy

Merge pull request #674 from metamx/fix-arbitrary-granularity

fix missing queryGranularity in ArbitraryGranularitySpec
...@@ -21,6 +21,7 @@ package io.druid.segment.indexing.granularity; ...@@ -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; ...@@ -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 ...@@ -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)
);
} }
} }
...@@ -68,7 +68,7 @@ public class UniformGranularitySpec implements GranularitySpec ...@@ -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;
......
...@@ -23,6 +23,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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"),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册