diff --git a/ingester-protocol/src/main/java/io/greptime/models/Util.java b/ingester-protocol/src/main/java/io/greptime/models/Util.java index e670c81..de801f5 100644 --- a/ingester-protocol/src/main/java/io/greptime/models/Util.java +++ b/ingester-protocol/src/main/java/io/greptime/models/Util.java @@ -67,19 +67,17 @@ static int getDateValue(Object value) { return (int) getLongValue(value); } - static int getDateTimeValue(Object value) { + static long getDateTimeValue(Object value) { if (value instanceof Instant) { - long epochSecond = ((Instant) value).getEpochSecond(); - return (int) epochSecond; + return ((Instant) value).toEpochMilli(); } if (value instanceof Date) { Instant instant = ((Date) value).toInstant(); - long epochSecond = instant.getEpochSecond(); - return (int) epochSecond; + return instant.toEpochMilli(); } - return (int) getLongValue(value); + return getLongValue(value); } static Common.IntervalMonthDayNano getIntervalMonthDayNanoValue(Object value) { diff --git a/ingester-protocol/src/test/java/io/greptime/models/UtilTest.java b/ingester-protocol/src/test/java/io/greptime/models/UtilTest.java index 8aa19a3..90873e5 100644 --- a/ingester-protocol/src/test/java/io/greptime/models/UtilTest.java +++ b/ingester-protocol/src/test/java/io/greptime/models/UtilTest.java @@ -60,8 +60,10 @@ public void testGetDateTimeValue() { TimeZone gmtTimeZone = TimeZone.getTimeZone("GMT"); cal.setTimeZone(gmtTimeZone); cal.set(1970, Calendar.JANUARY, 2, 0, 0, 0); - Assert.assertEquals(86400, Util.getDateTimeValue(cal.getTime())); - Assert.assertEquals(86400, Util.getDateTimeValue(Instant.ofEpochSecond(86400))); + cal.set(Calendar.MILLISECOND, 111); + Assert.assertEquals(86400111, Util.getDateTimeValue(cal.getTime())); + Assert.assertEquals(86400111, Util.getDateTimeValue(cal.getTime().toInstant())); + Assert.assertEquals(86400000, Util.getDateTimeValue(Instant.ofEpochSecond(86400))); Assert.assertEquals(86400, Util.getDateTimeValue(86400)); }