From 9f742a87a6afeaeaffc31058e482b7a231cef4de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xavier=20L=C3=A9aut=C3=A9?= Date: Thu, 28 Aug 2014 17:15:45 -0700 Subject: [PATCH] fix timewarp with different bounds --- .../java/io/druid/query/TimewarpOperator.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/processing/src/main/java/io/druid/query/TimewarpOperator.java b/processing/src/main/java/io/druid/query/TimewarpOperator.java index ac2a5f8c930..4f9bc597f74 100644 --- a/processing/src/main/java/io/druid/query/TimewarpOperator.java +++ b/processing/src/main/java/io/druid/query/TimewarpOperator.java @@ -22,7 +22,6 @@ package io.druid.query; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.google.common.base.Function; -import com.google.common.collect.ImmutableMap; import com.metamx.common.guava.Sequence; import com.metamx.common.guava.Sequences; import io.druid.data.input.MapBasedRow; @@ -80,7 +79,7 @@ public class TimewarpOperator implements PostProcessingOperator return new QueryRunner() { @Override - public Sequence run(Query query) + public Sequence run(final Query query) { final long offset = computeOffset(now); @@ -101,16 +100,22 @@ public class TimewarpOperator implements PostProcessingOperator if (input instanceof Result) { Result res = (Result) input; Object value = res.getValue(); + final DateTime timestamp = res.getTimestamp().minus(offset); if (value instanceof TimeBoundaryResultValue) { TimeBoundaryResultValue boundary = (TimeBoundaryResultValue) value; - value = new TimeBoundaryResultValue( - ImmutableMap.of( - TimeBoundaryQuery.MIN_TIME, boundary.getMinTime().minus(offset), - TimeBoundaryQuery.MAX_TIME, new DateTime(Math.min(boundary.getMaxTime().getMillis() - offset, now)) - ) - ); + + DateTime minTime = null; + try{ + minTime = boundary.getMinTime(); + } catch(IllegalArgumentException e) {} + + return (T) ((TimeBoundaryQuery) query).buildResult( + timestamp, + minTime, + boundary.getMaxTime() + ).iterator().next(); } - return (T) new Result(res.getTimestamp().minus(offset), value); + return (T) new Result(timestamp, value); } else if (input instanceof MapBasedRow) { MapBasedRow row = (MapBasedRow) input; return (T) new MapBasedRow(row.getTimestamp().minus(offset), row.getEvent());