UniformGranularitySpec: Only return bucketInterval for timestamps that legitimately

overlap our input intervals
This commit is contained in:
Gian Merlino 2013-01-15 22:29:03 -08:00
parent 86277d1114
commit 616415cb7e
3 changed files with 31 additions and 16 deletions

View File

@ -20,6 +20,9 @@
package com.metamx.druid.indexer.granularity; package com.metamx.druid.indexer.granularity;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.metamx.common.Granularity; import com.metamx.common.Granularity;
import com.metamx.common.guava.Comparators; import com.metamx.common.guava.Comparators;
@ -35,47 +38,47 @@ import java.util.TreeSet;
public class UniformGranularitySpec implements GranularitySpec public class UniformGranularitySpec implements GranularitySpec
{ {
final private Granularity granularity; final private Granularity granularity;
final private List<Interval> intervals; final private List<Interval> inputIntervals;
final private ArbitraryGranularitySpec wrappedSpec;
@JsonCreator @JsonCreator
public UniformGranularitySpec( public UniformGranularitySpec(
@JsonProperty("gran") Granularity granularity, @JsonProperty("gran") Granularity granularity,
@JsonProperty("intervals") List<Interval> intervals @JsonProperty("intervals") List<Interval> inputIntervals
) )
{ {
List<Interval> granularIntervals = Lists.newArrayList();
for (Interval inputInterval : inputIntervals) {
Iterables.addAll(granularIntervals, granularity.getIterable(inputInterval));
}
this.granularity = granularity; this.granularity = granularity;
this.intervals = intervals; this.inputIntervals = ImmutableList.copyOf(inputIntervals);
this.wrappedSpec = new ArbitraryGranularitySpec(granularIntervals);
} }
@Override @Override
public SortedSet<Interval> bucketIntervals() public SortedSet<Interval> bucketIntervals()
{ {
final TreeSet<Interval> retVal = Sets.newTreeSet(Comparators.intervals()); return wrappedSpec.bucketIntervals();
for (Interval interval : intervals) {
for (Interval segmentInterval : granularity.getIterable(interval)) {
retVal.add(segmentInterval);
}
}
return retVal;
} }
@Override @Override
public Optional<Interval> bucketInterval(DateTime dt) public Optional<Interval> bucketInterval(DateTime dt)
{ {
return Optional.of(granularity.bucket(dt)); return wrappedSpec.bucketInterval(dt);
} }
@JsonProperty @JsonProperty("gran")
public Granularity getGranularity() public Granularity getGranularity()
{ {
return granularity; return granularity;
} }
@JsonProperty @JsonProperty("intervals")
public Iterable<Interval> getIntervals() public Iterable<Interval> getIntervals()
{ {
return intervals; return inputIntervals;
} }
} }

View File

@ -69,6 +69,12 @@ public class ArbitraryGranularityTest
spec.bucketInterval(new DateTime("2012-01-03T01Z")) spec.bucketInterval(new DateTime("2012-01-03T01Z"))
); );
Assert.assertEquals(
"2012-01-04T01Z",
Optional.<Interval>absent(),
spec.bucketInterval(new DateTime("2012-01-04T01Z"))
);
Assert.assertEquals( Assert.assertEquals(
"2012-01-07T23:59:59.999Z", "2012-01-07T23:59:59.999Z",
Optional.of(new Interval("2012-01-07T00Z/2012-01-08T00Z")), Optional.of(new Interval("2012-01-07T00Z/2012-01-08T00Z")),

View File

@ -72,6 +72,12 @@ public class UniformGranularityTest
spec.bucketInterval(new DateTime("2012-01-03T01Z")) spec.bucketInterval(new DateTime("2012-01-03T01Z"))
); );
Assert.assertEquals(
"2012-01-04T01Z",
Optional.<Interval>absent(),
spec.bucketInterval(new DateTime("2012-01-04T01Z"))
);
Assert.assertEquals( Assert.assertEquals(
"2012-01-07T23:59:59.999Z", "2012-01-07T23:59:59.999Z",
Optional.of(new Interval("2012-01-07T00Z/2012-01-08T00Z")), Optional.of(new Interval("2012-01-07T00Z/2012-01-08T00Z")),