From d722c995302f88cd0d00a0db585a8903a3da8517 Mon Sep 17 00:00:00 2001 From: xvrl Date: Wed, 20 Mar 2013 23:36:52 -0700 Subject: [PATCH 1/3] fix cursor overshooting granularity boundaries, due to incorrect gran.next() usage --- .../com/metamx/druid/index/v1/QueryableIndexStorageAdapter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/java/com/metamx/druid/index/v1/QueryableIndexStorageAdapter.java b/server/src/main/java/com/metamx/druid/index/v1/QueryableIndexStorageAdapter.java index 0dfded54178..1cde70b5c73 100644 --- a/server/src/main/java/com/metamx/druid/index/v1/QueryableIndexStorageAdapter.java +++ b/server/src/main/java/com/metamx/druid/index/v1/QueryableIndexStorageAdapter.java @@ -272,7 +272,7 @@ public class QueryableIndexStorageAdapter extends BaseStorageAdapter } final Offset offset = new TimestampCheckingOffset( - baseOffset, timestamps, Math.min(interval.getEndMillis(), gran.next(timeStart)) + baseOffset, timestamps, Math.min(interval.getEndMillis(), gran.next(input)) ); return new Cursor() From c0397aa67c40dc8a7facca3f60ed2de769354a26 Mon Sep 17 00:00:00 2001 From: xvrl Date: Thu, 21 Mar 2013 10:36:14 -0700 Subject: [PATCH 2/3] add test case for granularities not aligned with segment boundaries --- .../timeseries/TimeseriesQueryRunnerTest.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/server/src/test/java/com/metamx/druid/query/timeseries/TimeseriesQueryRunnerTest.java b/server/src/test/java/com/metamx/druid/query/timeseries/TimeseriesQueryRunnerTest.java index 3be91c3686f..a28a93c62cd 100644 --- a/server/src/test/java/com/metamx/druid/query/timeseries/TimeseriesQueryRunnerTest.java +++ b/server/src/test/java/com/metamx/druid/query/timeseries/TimeseriesQueryRunnerTest.java @@ -375,6 +375,53 @@ public class TimeseriesQueryRunnerTest TestHelper.assertExpectedResults(expectedResults2, results2); } + @Test + public void testTimeseriesGranularityNotAlignedOnSegmentBoundariesWithFilter() + { + TimeseriesQuery query1 = Druids.newTimeseriesQueryBuilder() + .dataSource(QueryRunnerTestHelper.dataSource) + .filters(QueryRunnerTestHelper.providerDimension, "spot", "upfront", "total_market") + .granularity(new PeriodGranularity(new Period("P7D"), null, DateTimeZone.forID("America/Los_Angeles"))) + .intervals( + Arrays.asList( + new Interval( + "2011-01-12T00:00:00.000-08:00/2011-01-20T00:00:00.000-08:00" + ) + ) + ) + .aggregators( + Arrays.asList( + QueryRunnerTestHelper.rowsCount, + new LongSumAggregatorFactory( + "idx", + "index" + ) + ) + ) + .build(); + + List> expectedResults1 = Arrays.asList( + new Result( + new DateTime("2011-01-06T00:00:00.000-08:00", DateTimeZone.forID("America/Los_Angeles")), + new TimeseriesResultValue( + ImmutableMap.of("rows", 13L, "idx", 6071L) + ) + ), + new Result( + new DateTime("2011-01-13T00:00:00.000-08:00", DateTimeZone.forID("America/Los_Angeles")), + new TimeseriesResultValue( + ImmutableMap.of("rows", 91L, "idx", 33382L) + ) + ) + ); + + Iterable> results1 = Sequences.toList( + runner.run(query1), + Lists.>newArrayList() + ); + TestHelper.assertExpectedResults(expectedResults1, results1); + } + @Test public void testTimeseriesWithVaryingGranWithFilter() { From 16e4cd4291c51fa1a2a9e3a189c8c57cd09d6901 Mon Sep 17 00:00:00 2001 From: xvrl Date: Thu, 21 Mar 2013 10:38:39 -0700 Subject: [PATCH 3/3] fix cursor overshooting granularity boundaries in IncrementalIndexStorageAdapter as well --- .../metamx/druid/index/v1/IncrementalIndexStorageAdapter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/java/com/metamx/druid/index/v1/IncrementalIndexStorageAdapter.java b/server/src/main/java/com/metamx/druid/index/v1/IncrementalIndexStorageAdapter.java index bf8e0ac9653..8ec2cc10f52 100644 --- a/server/src/main/java/com/metamx/druid/index/v1/IncrementalIndexStorageAdapter.java +++ b/server/src/main/java/com/metamx/druid/index/v1/IncrementalIndexStorageAdapter.java @@ -164,7 +164,7 @@ public class IncrementalIndexStorageAdapter implements StorageAdapter timeStart, new String[][]{} ), new IncrementalIndex.TimeAndDims( - Math.min(actualInterval.getEndMillis(), gran.next(timeStart)), new String[][]{} + Math.min(actualInterval.getEndMillis(), gran.next(input)), new String[][]{} ) ); time = gran.toDateTime(input);