opensearch-project / opensearch-project/sql-jdbc
[BUG] `ResultSet::getObject` fails for datetime types
Open
Nobody has claimed this yet.
bug
- Dominant language
- Java
- Stars
- 28
- Forks
- 39
- PR merge metrics
- No merged PRs in 30d
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with TypeConverter.java and BaseTypeConverter.convert, then trace ResultSetImpl.getObjectX and the getObject overload shown in the stack trace. Reproduce the TIME query with LocalTime.class and inspect how the returned string is converted. Done means the driver can generate the requested java.time class without the SQLDataException.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100