When using the ClickHouse JDBC driver with JdbcTemplate in a Spring application, a query timeout is set using JdbcTemplate.setQueryTimeout(10). However, when the query exceeds the configured timeout, a BadSqlGrammarException is thrown instead of the expected TimeoutException. This behavior is misleading as it suggests an issue with SQL syntax rather than a timeout.
Steps to reproduce
Configure JdbcTemplate with a query timeout: jdbcTemplate.setQueryTimeout(10) (10 seconds).
Execute a query that takes longer than the configured timeout.
Observe the exception thrown when the query times out.
Expected behaviour
A TimeoutException or another appropriate exception should be thrown to clearly indicate that the query execution exceeded the configured timeout.
Code example
public executeQuery(String query) {
jdbcTemplate.query(query)
}
Error log
org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad SQL grammar [SELECT * FROM large_table];
nested exception is java.sql.SQLException: Code: 159. DB::Exception: Timeout exceeded: elapsed 10.114165251 seconds, maximum: 10: While executing MergeTreeSelect(pool: ReadPoolInOrder, algorithm: InOrder). (TIMEOUT_EXCEEDED) (version 24.1.5.6 (official build))
at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:101)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:70)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:79)
at org.springframework.jdbc.core.JdbcTemplate.translateException(JdbcTemplate.java:1541)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:393)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:465)
Describe the bug
When using the ClickHouse JDBC driver with JdbcTemplate in a Spring application, a query timeout is set using JdbcTemplate.setQueryTimeout(10). However, when the query exceeds the configured timeout, a BadSqlGrammarException is thrown instead of the expected TimeoutException. This behavior is misleading as it suggests an issue with SQL syntax rather than a timeout.
Steps to reproduce
Expected behaviour
A TimeoutException or another appropriate exception should be thrown to clearly indicate that the query execution exceeded the configured timeout.
Code example
Error log
Configuration
Environment
ClickHouse server
CREATE TABLE
statements for tables involved: