Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@ protected ResultSetImpl executeQueryImpl(String sql, QuerySettings settings) thr
if (queryTimeout == 0) {
response = connection.getClient().query(lastStatementSql, mergedSettings).get();
} else {
response = connection.getClient().query(lastStatementSql, mergedSettings).get(queryTimeout, TimeUnit.SECONDS);
// we need to perform async operation to support timeout.
response = connection.getClient().query(lastStatementSql, mergedSettings
.setOption(ClientConfigProperties.ASYNC_OPERATIONS.getKey(), true))
.get(queryTimeout, TimeUnit.SECONDS);
}

if (response.getFormat().isText()) {
Expand Down Expand Up @@ -246,7 +249,9 @@ protected long executeUpdateImpl(String sql, QuerySettings settings) throws SQLE
LOG.trace("SQL Query: {}", lastStatementSql);
int updateCount = 0;
try (QueryResponse response = queryTimeout == 0 ? connection.getClient().query(lastStatementSql, mergedSettings).get()
: connection.getClient().query(lastStatementSql, mergedSettings).get(queryTimeout, TimeUnit.SECONDS)) {
: connection.getClient().query(lastStatementSql, mergedSettings
.setOption(ClientConfigProperties.ASYNC_OPERATIONS.getKey(), true))
.get(queryTimeout, TimeUnit.SECONDS)) {
updateCount = Math.max(0, (int) response.getWrittenRows()); // when statement alters schema no result rows returned.
lastQueryId = response.getQueryId();
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.clickhouse.jdbc;

import com.clickhouse.client.api.ClientConfigProperties;
import com.clickhouse.client.api.DataTypeUtils;
import com.clickhouse.data.ClickHouseColumn;
import com.clickhouse.data.ClickHouseDataType;
Expand Down Expand Up @@ -566,6 +567,16 @@ void testSelectFromArray() throws Exception {
}
}

@Test(groups = {"integration"})
void testExecuteQueryTimeout() throws Exception {
final String sql = "SELECT sum(reinterpretAsUInt64(MD5(toString(number)))) FROM system.numbers LIMIT 1000000";
try (Connection conn = getJdbcConnection();
PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setQueryTimeout(1);
assertThrows(SQLException.class, stmt::executeQuery);
}
}

@Test(groups = { "integration" })
void testInsert() throws Exception {
int ROWS = 1000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ public void testUpdateQueryWithResultSet() throws Exception {
props.setProperty(ClientConfigProperties.HTTP_MAX_OPEN_CONNECTIONS.getKey(), "1");
props.setProperty(ClientConfigProperties.CONNECTION_REQUEST_TIMEOUT.getKey(), "500");
try (Connection conn = getJdbcConnection(props); Statement stmt = conn.createStatement()) {
stmt.setQueryTimeout(1);
stmt.setQueryTimeout(10);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this only masks the issue :-)

ResultSet rs = stmt.executeQuery("SELECT 1");
boolean failedOnTimeout = false;
try {
Expand Down
Loading