From ac0070e7100ceac90861b37dab0669e5b3e7aabb Mon Sep 17 00:00:00 2001 From: Margarit Hakobyan Date: Tue, 3 Jan 2023 12:35:12 -0800 Subject: [PATCH] Fixes "`ResultSet.getTime()` returns `null`" bug (#1) * Fixes ResultSet.getTime returns null bug Signed-off-by: Margarit Hakobyan --- .../org/opensearch/jdbc/ResultSetImpl.java | 30 +++++++--- .../org/opensearch/jdbc/types/TimeType.java | 58 ++++++++++++------ .../opensearch/jdbc/types/TypeConverters.java | 2 +- .../opensearch/jdbc/types/TimeTypeTest.java | 60 ++++++++++++++++++- 4 files changed, 121 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..73593c3 100644 --- a/src/main/java/org/opensearch/jdbc/types/TimeType.java +++ b/src/main/java/org/opensearch/jdbc/types/TimeType.java @@ -8,7 +8,14 @@ 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.format.DateTimeParseException; +import java.time.temporal.TemporalAccessor; +import java.util.Calendar; +import java.util.Locale; import java.util.Map; public class TimeType implements TypeHelper