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

Unexpected BadSqlGrammarException Instead of TimeoutException on Query Timeout #1972

Open
koyr-exem opened this issue Nov 25, 2024 · 1 comment
Labels
integration integration issues with anything module-jdbc JDBC driver

Comments

@koyr-exem
Copy link

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

  1. Configure JdbcTemplate with a query timeout: jdbcTemplate.setQueryTimeout(10) (10 seconds).
  2. Execute a query that takes longer than the configured timeout.
  3. 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)

Configuration

Environment

  • Client version: clickhouse-jdbc:0.4.6
  • Language version: Java 11
  • OS: windows 11

ClickHouse server

  • ClickHouse Server version: 24.1.5.6
  • ClickHouse Server non-default settings, if any:
  • CREATE TABLE statements for tables involved:
  • Sample data for all these tables, use clickhouse-obfuscator if necessary
@koyr-exem koyr-exem added the bug label Nov 25, 2024
@koyr-exem koyr-exem changed the title Unexpected BadSqlGrammarException Instead of TimeoutException on Query Timeout Unexpected BadSqlGrammarException Instead of TimeoutException on Query Timeout Nov 25, 2024
@chernser chernser added module-jdbc JDBC driver integration integration issues with anything and removed bug labels Nov 25, 2024
@chernser
Copy link
Contributor

Good day, @koyr-exem !
Thank you for bringing it up. We will try to look into it soon.

@chernser chernser added this to the Priority Backlog milestone Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration integration issues with anything module-jdbc JDBC driver
Projects
None yet
Development

No branches or pull requests

2 participants