From a4d2c0c7e6207ea9f7e0557aded792470db1ff83 Mon Sep 17 00:00:00 2001 From: Guian Gumpac Date: Thu, 18 Nov 2021 15:17:11 -0800 Subject: [PATCH] Added Kyle's fix for ADDDATE and SUBDATE with resulting 00:00:00 being unexpectedly null Signed-off-by: Guian Gumpac --- .../org/opensearch/jdbc/types/TimestampType.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/sql-jdbc/src/main/java/org/opensearch/jdbc/types/TimestampType.java b/sql-jdbc/src/main/java/org/opensearch/jdbc/types/TimestampType.java index 3ae9463ea4..3f80eff0c7 100644 --- a/sql-jdbc/src/main/java/org/opensearch/jdbc/types/TimestampType.java +++ b/sql-jdbc/src/main/java/org/opensearch/jdbc/types/TimestampType.java @@ -8,6 +8,7 @@ import java.sql.SQLException; import java.sql.Timestamp; +import java.time.LocalDate; import java.time.LocalDateTime; import java.util.Calendar; import java.util.Map; @@ -78,13 +79,17 @@ else if (value.charAt(23) == '+' || value.charAt(23) == '-') { } } - if (calendar == null) { - return Timestamp.valueOf(value); + final Timestamp ts; + if (value.length() < 11) { + ts = Timestamp.valueOf(LocalDate.parse(value).atStartOfDay()); } else { - Timestamp ts = Timestamp.valueOf(value); - return localDateTimeToTimestamp(ts.toLocalDateTime(), calendar); + ts = Timestamp.valueOf(value); } + if (calendar == null) { + return ts; + } + return localDateTimeToTimestamp(ts.toLocalDateTime(), calendar); } catch (IllegalArgumentException iae) { throw stringConversionException(value, iae); }