This is an automated email from the ASF dual-hosted git repository.

jonwei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-druid.git


The following commit(s) were added to refs/heads/master by this push:
     new f6a8e03  Select query failing if miliseconds used as time for indexing 
(#6937)
f6a8e03 is described below

commit f6a8e030cc491aa6199c907d37cda253da4e4d41
Author: Mirko Jotic <joticmi...@gmail.com>
AuthorDate: Mon Feb 25 17:36:01 2019 -0500

    Select query failing if miliseconds used as time for indexing (#6937)
    
    * [#1332] Fix - select failing if milis used for idx.
    
    * Formating correction.
    
    * Address comment: throw original exception.
    
    * Using constant values in tests
    
    - Try converting to Integer and then multiply by 1000L to achieve milis.
    - If not successful try converting to Long or rethrow original
    exception.
    
    * DateTime#of has to support "2011-01-01T00:00:00"
    
    - in addition to seconds and milisecs, this method currently supports
    even a date string.
    
    * Handle only milisec timestamps and ISO8601 strings
---
 .../org/apache/druid/java/util/common/DateTimes.java  | 12 +++++++++++-
 .../apache/druid/java/util/common/DateTimesTest.java  | 19 +++++++++++++++++++
 2 files changed, 30 insertions(+), 1 deletion(-)

diff --git 
a/core/src/main/java/org/apache/druid/java/util/common/DateTimes.java 
b/core/src/main/java/org/apache/druid/java/util/common/DateTimes.java
index 94f1295..de1fc40 100644
--- a/core/src/main/java/org/apache/druid/java/util/common/DateTimes.java
+++ b/core/src/main/java/org/apache/druid/java/util/common/DateTimes.java
@@ -107,7 +107,17 @@ public final class DateTimes
 
   public static DateTime of(String instant)
   {
-    return new DateTime(instant, ISOChronology.getInstanceUTC());
+    try {
+      return new DateTime(instant, ISOChronology.getInstanceUTC());
+    }
+    catch (IllegalArgumentException ex) {
+      try {
+        return new DateTime(Long.valueOf(instant), 
ISOChronology.getInstanceUTC());
+      }
+      catch (IllegalArgumentException ex2) {
+        throw ex;
+      }
+    }
   }
 
   public static DateTime of(
diff --git 
a/core/src/test/java/org/apache/druid/java/util/common/DateTimesTest.java 
b/core/src/test/java/org/apache/druid/java/util/common/DateTimesTest.java
index 61bc746..15f3033 100644
--- a/core/src/test/java/org/apache/druid/java/util/common/DateTimesTest.java
+++ b/core/src/test/java/org/apache/druid/java/util/common/DateTimesTest.java
@@ -37,4 +37,23 @@ public class DateTimesTest
       
Assert.assertTrue(DateTimes.COMMON_DATE_TIME_PATTERN.matcher(dt.toString()).matches());
     }
   }
+
+  @Test
+  public void testStringToDateTimeConversion()
+  {
+    String seconds = "2018-01-30T06:00:00";
+    DateTime dt2 = DateTimes.of(seconds);
+    Assert.assertEquals("2018-01-30T06:00:00.000Z", dt2.toString());
+
+    String milis = "1517292000000";
+    DateTime dt1 = DateTimes.of(milis);
+    Assert.assertEquals("2018-01-30T06:00:00.000Z", dt1.toString());
+  }
+
+  @Test(expected = IllegalArgumentException.class)
+  public void testStringToDateTimeConverstion_RethrowInitialException()
+  {
+    String invalid = "51729200AZ";
+    DateTimes.of(invalid);
+  }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org
For additional commands, e-mail: commits-h...@druid.apache.org

Reply via email to