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

SNOW-1524152-Implement-setQueryTimeout-for-async-queries #1958

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
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 @@ -39,9 +39,11 @@ public abstract class SFBaseStatement {
public void addProperty(String propertyName, Object propertyValue) throws SFException {
statementParametersMap.put(propertyName, propertyValue);

// for query timeout, we implement it on client side for now
if ("query_timeout".equalsIgnoreCase(propertyName)) {
// Client side implementation
queryTimeout = (Integer) propertyValue;
// Set server parameter for supporting query timeout on async queries
statementParametersMap.put("STATEMENT_TIMEOUT_IN_SECONDS", (Integer) propertyValue);
}

// check if the number of session properties exceed limit
Expand Down
52 changes: 52 additions & 0 deletions src/test/java/net/snowflake/client/jdbc/StatementLatestIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
import net.snowflake.client.TestUtil;
import net.snowflake.client.category.TestCategoryStatement;
import net.snowflake.client.core.ParameterBindingDTO;
import net.snowflake.client.core.QueryStatus;
import net.snowflake.client.core.SFSession;
import net.snowflake.client.core.bind.BindUploader;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
Expand Down Expand Up @@ -297,4 +299,54 @@ public void testQueryIdIsSetOnFailedExecuteQuery() throws SQLException {
}
}
}

/**
* Run test manually to confirm setQueryTimeout is working for async query
*
* @throws SQLException if there is an error when executing
*/
@Test
@Ignore
public void testSetQueryTimeoutForAsnycQuery() throws SQLException {
Statement statement = connection.createStatement();

statement.unwrap(SnowflakeStatement.class).setParameter("MULTI_STATEMENT_COUNT", 0);
statement.setQueryTimeout(3);

String sql = "SELECT * FROM SNOWFLAKE_SAMPLE_DATA.TPCDS_SF100TCL.CUSTOMER;";

// Async
System.out.println("Async start time: " + java.time.LocalTime.now());
ResultSet resultSet = statement.unwrap(SnowflakeStatement.class).executeAsyncQuery(sql);

String queryID = resultSet.unwrap(SnowflakeResultSet.class).getQueryID();
System.out.println("Async query ID: " + queryID);

QueryStatus queryStatus = QueryStatus.RUNNING;
while (queryStatus == QueryStatus.RUNNING || queryStatus == QueryStatus.RESUMING_WAREHOUSE) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
fail(e.getMessage());
}
queryStatus = resultSet.unwrap(SnowflakeResultSet.class).getStatus();
System.out.println("Current status: " + queryStatus);
}

if (queryStatus == QueryStatus.SUCCESS) {
while (resultSet.next()) {
System.out.println(resultSet.getString(1));
System.exit(0);
}
}

if (queryStatus == QueryStatus.FAILED_WITH_ERROR) {
while (resultSet.next()) {
System.out.println(queryStatus.getErrorMessage());
System.exit(0);
}
}

System.out.println("Async end time: " + java.time.LocalTime.now());
}
}
Loading