From 1298b4abd32fd218d43f418706f8201064a1816e Mon Sep 17 00:00:00 2001 From: Gian Merlino Date: Tue, 3 Feb 2015 17:34:33 -0800 Subject: [PATCH] JodaUtils: Bring in MIN/MAX instants a bit. This prevents the difference overflowing a long. --- common/src/main/java/io/druid/common/utils/JodaUtils.java | 7 +++---- .../src/test/java/io/druid/common/utils/JodaUtilsTest.java | 7 +++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/io/druid/common/utils/JodaUtils.java b/common/src/main/java/io/druid/common/utils/JodaUtils.java index a3e1b9cee26..c7f0e62eee9 100644 --- a/common/src/main/java/io/druid/common/utils/JodaUtils.java +++ b/common/src/main/java/io/druid/common/utils/JodaUtils.java @@ -27,7 +27,6 @@ import com.metamx.common.guava.Comparators; import org.joda.time.DateTime; import org.joda.time.Interval; -import javax.annotation.Nullable; import java.util.ArrayList; import java.util.Iterator; import java.util.TreeSet; @@ -36,9 +35,9 @@ import java.util.TreeSet; */ public class JodaUtils { - // joda limits years to [-292275054,292278993] that should be reasonable - public static final long MAX_INSTANT = new DateTime("292278993").getMillis(); - public static final long MIN_INSTANT = new DateTime("-292275054").getMillis(); + // limit intervals such that duration millis fits in a long + public static final long MAX_INSTANT = Long.MAX_VALUE / 2; + public static final long MIN_INSTANT = Long.MIN_VALUE / 2; public static ArrayList condenseIntervals(Iterable intervals) { diff --git a/common/src/test/java/io/druid/common/utils/JodaUtilsTest.java b/common/src/test/java/io/druid/common/utils/JodaUtilsTest.java index 2fe084c3a01..68d9c1ee2a3 100644 --- a/common/src/test/java/io/druid/common/utils/JodaUtilsTest.java +++ b/common/src/test/java/io/druid/common/utils/JodaUtilsTest.java @@ -119,4 +119,11 @@ public class JodaUtilsTest ); } } + + @Test + public void testMinMaxInterval() + { + final Interval interval = new Interval(JodaUtils.MIN_INSTANT, JodaUtils.MAX_INSTANT); + Assert.assertEquals(Long.MAX_VALUE, interval.toDuration().getMillis()); + } }