From 79b2c5d40eaa6378a90519371f07b2b39e4bbda8 Mon Sep 17 00:00:00 2001 From: Margarit Hakobyan Date: Wed, 21 Dec 2022 14:09:21 -0800 Subject: [PATCH 1/5] Fixes ResultSet.getTime returns null bug Signed-off-by: Margarit Hakobyan --- .../org/opensearch/jdbc/ResultSetImpl.java | 30 +++++++--- .../org/opensearch/jdbc/types/TimeType.java | 57 +++++++++++++------ .../opensearch/jdbc/types/TypeConverters.java | 2 +- .../opensearch/jdbc/types/TimeTypeTest.java | 57 ++++++++++++++++++- 4 files changed, 117 insertions(+), 29 deletions(-) diff --git a/src/main/java/org/opensearch/jdbc/ResultSetImpl.java b/src/main/java/org/opensearch/jdbc/ResultSetImpl.java index 3cace79..e34a42d 100644 --- a/src/main/java/org/opensearch/jdbc/ResultSetImpl.java +++ b/src/main/java/org/opensearch/jdbc/ResultSetImpl.java @@ -347,14 +347,18 @@ private Date getDateX(int columnIndex, Calendar calendar) throws SQLException { public Time getTime(int columnIndex) throws SQLException { log.debug(() -> logEntry("getTime (%d)", columnIndex)); checkCursorOperationPossible(); - Time value = getTimeX(columnIndex); + Time value = getTimeX(columnIndex, null); log.debug(() -> logExit("getTime", value)); return value; } - private Time getTimeX(int columnIndex) throws SQLException { - // TODO - add/check support - return getObjectX(columnIndex, Time.class); + private Time getTimeX(int columnIndex, Calendar calendar) throws SQLException { + Map conversionParams = null; + if (calendar != null) { + conversionParams = new HashMap<>(); + conversionParams.put("calendar", calendar); + } + return getObjectX(columnIndex, Time.class, conversionParams); } @Override @@ -494,7 +498,7 @@ public Date getDate(String columnLabel) throws SQLException { public Time getTime(String columnLabel) throws SQLException { log.debug(() -> logEntry("getTime (%s)", columnLabel)); checkCursorOperationPossible(); - Time value = getTimeX(getColumnIndex(columnLabel)); + Time value = getTimeX(getColumnIndex(columnLabel), null); log.debug(() -> logExit("getTime", value)); return value; } @@ -1071,14 +1075,22 @@ public Date getDate(String columnLabel, Calendar cal) throws SQLException { @Override public Time getTime(int columnIndex, Calendar cal) throws SQLException { - // TODO - implement? - return null; + log.debug(() -> logEntry("getTime (%d, %s)", columnIndex, + cal == null ? "null" : "Calendar TZ= " + cal.getTimeZone())); + checkCursorOperationPossible(); + Time value = getTimeX(columnIndex, cal); + log.debug(() -> logExit("getTime", value)); + return value; } @Override public Time getTime(String columnLabel, Calendar cal) throws SQLException { - // TODO - implement? - return null; + log.debug(() -> logEntry("getTime (%s, %s)", columnLabel, + cal == null ? "null" : "Calendar TZ= " + cal.getTimeZone())); + checkCursorOperationPossible(); + Time value = getTimeX(getColumnIndex(columnLabel), cal); + log.debug(() -> logExit("getTime", value)); + return value; } @Override diff --git a/src/main/java/org/opensearch/jdbc/types/TimeType.java b/src/main/java/org/opensearch/jdbc/types/TimeType.java index ad44c7f..74cc51c 100644 --- a/src/main/java/org/opensearch/jdbc/types/TimeType.java +++ b/src/main/java/org/opensearch/jdbc/types/TimeType.java @@ -8,7 +8,13 @@ import java.sql.SQLException; import java.sql.Time; -import java.time.LocalTime; +import java.sql.Timestamp; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.time.temporal.TemporalAccessor; +import java.util.Calendar; +import java.util.Locale; import java.util.Map; public class TimeType implements TypeHelper