diff --git a/src/integrationTest/java/integration/tests/StatementTest.java b/src/integrationTest/java/integration/tests/StatementTest.java index ae44e352c7..ee32deeceb 100644 --- a/src/integrationTest/java/integration/tests/StatementTest.java +++ b/src/integrationTest/java/integration/tests/StatementTest.java @@ -2,22 +2,10 @@ import com.firebolt.jdbc.connection.FireboltConnection; import com.firebolt.jdbc.exception.FireboltException; +import com.firebolt.jdbc.testutils.TestTag; import integration.ConnectionInfo; import integration.EnvironmentCondition; import integration.IntegrationTest; -import kotlin.collections.ArrayDeque; -import lombok.CustomLog; -import org.apache.commons.lang3.RandomStringUtils; -import org.hamcrest.Matchers; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.EnabledIfSystemProperty; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.CsvSource; -import org.junit.jupiter.params.provider.ValueSource; - import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; @@ -31,9 +19,20 @@ import java.util.Map; import java.util.concurrent.TimeUnit; import java.util.stream.IntStream; +import kotlin.collections.ArrayDeque; +import lombok.CustomLog; +import org.apache.commons.lang3.RandomStringUtils; +import org.hamcrest.Matchers; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledIfSystemProperty; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; +import org.junit.jupiter.params.provider.ValueSource; import static integration.EnvironmentCondition.Attribute.databaseVersion; -import static integration.EnvironmentCondition.Attribute.fireboltVersion; import static java.lang.String.format; import static java.sql.Statement.SUCCESS_NO_INFO; import static java.util.stream.Collectors.joining; @@ -558,6 +557,56 @@ void unlimitedMaxFieldSize(int maxFieldSize) throws SQLException { } } + @Test + @Tag(TestTag.V2) + @EnvironmentCondition(value = "4.16.0", attribute = databaseVersion, comparison = EnvironmentCondition.Comparison.GE) + void canUseStatementTimeout() throws SQLException { + try (Connection connection = createConnection(); Statement statement = connection.createStatement()) { + statement.execute("set statement_timeout=1"); + ResultSet resultSet = statement.executeQuery("SELECT * FROM GENERATE_SERIES(1, 10000000);"); + boolean errorFound = false; + while (resultSet.next()) { + String object = resultSet.getString(1); + if (object.contains("Query was canceled with reason 'Query timeout expired (1 ms)")) { + errorFound = true; + } + } + assertTrue(errorFound, "Did not find the error for query timing out"); + } + } + + @Test + @Tag(TestTag.V2) + @EnvironmentCondition(value = "4.16.0", attribute = databaseVersion, comparison = EnvironmentCondition.Comparison.GE) + void canUseStatementQueryTimeout() throws SQLException { + try (Connection connection = createConnection(); Statement statement = connection.createStatement()) { + statement.setQueryTimeout(1); + ResultSet resultSet = statement.executeQuery("SELECT * FROM GENERATE_SERIES(1, 10000000);"); + boolean errorFound = false; + while (resultSet.next()) { + String object = resultSet.getString(1); + if (object.contains("Query was canceled with reason 'Query timeout expired (1 ms)")) { + errorFound = true; + } + } + assertTrue(errorFound, "Did not find the error for query timing out"); + } + } + + @Test + @Tag(TestTag.V2) + @EnvironmentCondition(value = "4.16.0", attribute = databaseVersion, comparison = EnvironmentCondition.Comparison.GE) + void canExecuteStatementWithoutTimeout() throws SQLException { + try (Connection connection = createConnection(); Statement statement = connection.createStatement()) { + ResultSet resultSet = statement.executeQuery("SELECT * FROM GENERATE_SERIES(1, 10000000);"); + int lastNumberReturned = 0; + while (resultSet.next()) { + lastNumberReturned++; + } + assertEquals(1000000, lastNumberReturned); + } + } + private Collection readValues(Statement statement, String query, int columnIndex) throws SQLException { List values = new ArrayList<>(); try (ResultSet rs = statement.executeQuery(query)) { diff --git a/src/main/java/com/firebolt/jdbc/client/query/StatementClientImpl.java b/src/main/java/com/firebolt/jdbc/client/query/StatementClientImpl.java index ae5bdc9c2e..ff47925382 100644 --- a/src/main/java/com/firebolt/jdbc/client/query/StatementClientImpl.java +++ b/src/main/java/com/firebolt/jdbc/client/query/StatementClientImpl.java @@ -331,7 +331,7 @@ private Map getAllParameters(FireboltProperties fireboltProperti params.put(FireboltQueryParameterKey.COMPRESS.getKey(), fireboltProperties.isCompress() ? "1" : "0"); if (queryTimeout > 0) { - params.put("max_execution_time", String.valueOf(queryTimeout)); + params.put("statement_timeout", String.valueOf(queryTimeout)); } } params.put(FireboltQueryParameterKey.DATABASE.getKey(), fireboltProperties.getDatabase()); diff --git a/src/test/java/com/firebolt/jdbc/client/query/StatementClientImplTest.java b/src/test/java/com/firebolt/jdbc/client/query/StatementClientImplTest.java index da29747c68..b14c35fe85 100644 --- a/src/test/java/com/firebolt/jdbc/client/query/StatementClientImplTest.java +++ b/src/test/java/com/firebolt/jdbc/client/query/StatementClientImplTest.java @@ -83,7 +83,7 @@ class StatementClientImplTest { @ParameterizedTest @CsvSource({ - "false,http://firebolt1:555/?database=db1&output_format=TabSeparatedWithNamesAndTypes&compress=1&max_execution_time=15", + "false,http://firebolt1:555/?database=db1&output_format=TabSeparatedWithNamesAndTypes&compress=1&statement_timeout=15", "true,http://firebolt1:555/?database=db1&account_id=12345&output_format=TabSeparatedWithNamesAndTypes" }) void shouldPostSqlQueryWithExpectedUrl(boolean systemEngine, String expectedUrl) throws SQLException, IOException {