Skip to content

[BUG] ResultSet::getObject fails for datetime types #17

Open
@Yury-Fridlyand

Description

@Yury-Fridlyand

What is the bug?

rs.getObject(column, LocalTime.class)

causes an exception:

java.sql.SQLDataException: Can not convert object '15:04:32' of type 'java.lang.String' to type 'java.time.LocalTime'
	at org.opensearch.jdbc.types.TypeConverter.objectConversionException(TypeConverter.java:38)
	at org.opensearch.jdbc.types.BaseTypeConverter.convert(BaseTypeConverter.java:53)
	at org.opensearch.jdbc.ResultSetImpl.getObjectX(ResultSetImpl.java:604)
	at org.opensearch.jdbc.ResultSetImpl.getObjectX(ResultSetImpl.java:595)
	at org.opensearch.jdbc.ResultSetImpl.getObject(ResultSetImpl.java:1436)

How can one reproduce the bug?

// load driver
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select time(sysdate())");
ResultSetMetaData rsmd = rs.getMetaData();
var columns = new HashMap<String, String>();
for (int i = 1; i <= rsmd.getColumnCount(); i++) {
  columns.put(rsmd.getColumnName(i), rsmd.getColumnTypeName(i));
}

while (rs.next()) {
  for (var col : columns.entrySet()) {
    Object value = null;
    switch (col.getValue()) {
    // other types handling
    case "TIME" : rs.getObject(col.getKey(), LocalTime.class); break; // <-- crash here
    default:
      throw new IllegalArgumentException(col.getValue());
   }
  }
}

What is the expected behavior?

Driver should be able to generate java.time classes.

What is your host/environment?

2.x @ e2bf2544

Do you have any screenshots?

N/A

Do you have any additional context?

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions