Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Yury-Fridlyand opened this issue Nov 29, 2022 · 0 comments
Open

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

Yury-Fridlyand opened this issue Nov 29, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@Yury-Fridlyand
Copy link
Collaborator

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

@Yury-Fridlyand Yury-Fridlyand added the bug Something isn't working label Nov 29, 2022
@dai-chen dai-chen transferred this issue from opensearch-project/sql Dec 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant