Skip to content

SQL: JDBC getDate() method fails with NPE for a CASTed NULL AS DATE query #50174

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

Closed
astefan opened this issue Dec 13, 2019 · 2 comments · Fixed by #50184
Closed

SQL: JDBC getDate() method fails with NPE for a CASTed NULL AS DATE query #50174

astefan opened this issue Dec 13, 2019 · 2 comments · Fixed by #50184
Assignees
Labels

Comments

@astefan
Copy link
Contributor

astefan commented Dec 13, 2019

Connection conn = DriverManager.getConnection(URL);
PreparedStatement statement = conn.prepareStatement("SELECT CAST(NULL AS DATE)");
ResultSet results = statement.executeQuery();
while (results.next()) {
	ResultSetMetaData resultSetMetaData = results.getMetaData();
	logger.log(resultSetMetaData.getColumnLabel(1) + ": " + results.getObject(1));
	logger.log(resultSetMetaData.getColumnLabel(1) + ": " + results.getDate(1, Calendar.getInstance()));
}

results in

CAST(NULL AS DATE): null
Exception in thread "main" java.lang.NullPointerException
	at org.elasticsearch.xpack.sql.jdbc.JdbcResultSet.dateTimeAsMillis(JdbcResultSet.java:276)
	at org.elasticsearch.xpack.sql.jdbc.JdbcResultSet.getDate(JdbcResultSet.java:360)

For SELECT CAST(NULL AS DATETIME) the query is successful.
For SELECT CAST(NULL AS TIME) the query fails again with NPE.

@astefan astefan self-assigned this Dec 13, 2019
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search (:Search/SQL)

@astefan
Copy link
Contributor Author

astefan commented Dec 17, 2019

master (8.0.0): 08214eb
7.x (7.6.0): c6fdf9e
7.5 (7.5.2): e978e05

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants