dyf6372 closed pull request #6805: compare timestamp with 32503680000 in auto 
format
URL: https://github.com/apache/incubator-druid/pull/6805
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/core/src/main/java/org/apache/druid/java/util/common/parsers/TimestampParser.java
 
b/core/src/main/java/org/apache/druid/java/util/common/parsers/TimestampParser.java
index ecd06f822f9..1338590dc81 100644
--- 
a/core/src/main/java/org/apache/druid/java/util/common/parsers/TimestampParser.java
+++ 
b/core/src/main/java/org/apache/druid/java/util/common/parsers/TimestampParser.java
@@ -36,6 +36,9 @@
 
 public class TimestampParser
 {
+  // 32503680000s <=> 3000-01-01T00:00:00Z
+  private static final long MAX_TIMESTAMP_IN_SECONDS = 32503680000L;
+
   public static Function<String, DateTime> createTimestampParser(
       final String format
   )
@@ -63,7 +66,12 @@
           }
         }
 
-        return DateTimes.utc(Long.parseLong(input));
+        long timestamp = Long.parseLong(input);
+        if (timestamp > MAX_TIMESTAMP_IN_SECONDS) {
+          return DateTimes.utc(timestamp);
+        } else {
+          return DateTimes.utc(timestamp * 1000);
+        }
       };
     } else if ("iso".equalsIgnoreCase(format)) {
       return input -> {
@@ -112,7 +120,14 @@
     } else if ("ruby".equalsIgnoreCase(format)) {
       return input -> DateTimes.utc(Double.valueOf(input.doubleValue() * 
1000).longValue());
     } else {
-      return input -> DateTimes.utc(input.longValue());
+      return input -> {
+        long timestamp = input.longValue();
+        if (timestamp > MAX_TIMESTAMP_IN_SECONDS) {
+          return DateTimes.utc(timestamp);
+        } else {
+          return DateTimes.utc(timestamp * 1000);
+        }
+      };
     }
   }
 
diff --git 
a/core/src/test/java/org/apache/druid/java/util/common/parsers/TimestampParserTest.java
 
b/core/src/test/java/org/apache/druid/java/util/common/parsers/TimestampParserTest.java
index 9c0e66e10d2..005217193bb 100644
--- 
a/core/src/test/java/org/apache/druid/java/util/common/parsers/TimestampParserTest.java
+++ 
b/core/src/test/java/org/apache/druid/java/util/common/parsers/TimestampParserTest.java
@@ -73,6 +73,8 @@ public void testAuto()
         parser.apply("2009-02-13 23:31:30 PST"));
     Assert.assertEquals(new DateTime("2009-02-13T23:31:30Z", 
DateTimeZone.forTimeZone(TimeZone.getTimeZone("PST"))),
         parser.apply("\"2009-02-13 23:31:30 PST\""));
+    Assert.assertEquals(DateTimes.of("3000-01-01T00:00:00Z"), 
parser.apply(32503680000L));
+    Assert.assertEquals(DateTimes.of("1971-01-12T04:48:01Z"), 
parser.apply(32503681000L));
   }
 
   @Test


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to