From 8c4b8f20162795b76af551fe2ddacf2cef0b7326 Mon Sep 17 00:00:00 2001 From: guiangumpac <90278068+guiangumpac@users.noreply.github.com> Date: Mon, 8 Nov 2021 12:34:44 -0800 Subject: [PATCH] Add support for datetime type conversion in JDBC Signed-off-by: Guian Gumpac --- .../src/main/java/org/opensearch/jdbc/ResultSetImpl.java | 7 +++++-- .../java/org/opensearch/jdbc/types/OpenSearchType.java | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/sql-jdbc/src/main/java/org/opensearch/jdbc/ResultSetImpl.java b/sql-jdbc/src/main/java/org/opensearch/jdbc/ResultSetImpl.java index 488c897ea2..219ad2df19 100644 --- a/sql-jdbc/src/main/java/org/opensearch/jdbc/ResultSetImpl.java +++ b/sql-jdbc/src/main/java/org/opensearch/jdbc/ResultSetImpl.java @@ -595,8 +595,11 @@ protected T getObjectX(int columnIndex, Class javaClass) throws SQLExcept } protected T getObjectX(int columnIndex, Class javaClass, Map conversionParams) throws SQLException { - Object value = getColumn(columnIndex); - TypeConverter tc = TypeConverters.getInstance(getColumnMetaData(columnIndex).getOpenSearchType().getJdbcType()); + final Object value = getColumn(columnIndex); + final TypeConverter tc = TypeConverters.getInstance(getColumnMetaData(columnIndex).getOpenSearchType().getJdbcType()); + if (null == tc) { + throw new SQLException("Conversion from " + getColumnMetaData(columnIndex).getOpenSearchType() + " not supported."); + } return tc.convert(value, javaClass, conversionParams); } diff --git a/sql-jdbc/src/main/java/org/opensearch/jdbc/types/OpenSearchType.java b/sql-jdbc/src/main/java/org/opensearch/jdbc/types/OpenSearchType.java index a29e054b1a..095cb7b6f9 100644 --- a/sql-jdbc/src/main/java/org/opensearch/jdbc/types/OpenSearchType.java +++ b/sql-jdbc/src/main/java/org/opensearch/jdbc/types/OpenSearchType.java @@ -85,6 +85,7 @@ public enum OpenSearchType { OBJECT(JDBCType.STRUCT, null, 0, 0, false), DATE(JDBCType.DATE, Date.class, 24, 24, false), TIME(JDBCType.TIME, Time.class, 24, 24, false), + DATETIME(JDBCType.TIMESTAMP, Timestamp.class, 24, 24, false), TIMESTAMP(JDBCType.TIMESTAMP, Timestamp.class, 24, 24, false), BINARY(JDBCType.VARBINARY, String.class, Integer.MAX_VALUE, 0, false), NULL(JDBCType.NULL, null, 0, 0, false),