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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

sfc-gh-ext-simba-jf
Copy link
Collaborator

@sfc-gh-ext-simba-jf sfc-gh-ext-simba-jf commented Nov 7, 2024

Overview

SNOW-1524152

Pre-review self checklist

  • PR branch is updated with all the changes from master branch
  • The code is correctly formatted (run mvn -P check-style validate)
  • New public API is not unnecessary exposed (run mvn verify and inspect target/japicmp/japicmp.html)
  • The pull request name is prefixed with SNOW-XXXX:
  • Code is in compliance with internal logging requirements

External contributors - please answer these questions before submitting a pull request. Thanks!

  1. What GitHub issue is this PR addressing? Make sure that there is an accompanying issue to your PR.

    Issue: #NNNN

  2. Fill out the following pre-review checklist:

    • I am adding a new automated test(s) to verify correctness of my new code
    • I am adding new logging messages
    • I am modifying authorization mechanisms
    • I am adding new credentials
    • I am modifying OCSP code
    • I am adding a new dependency or upgrading an existing one
    • I am adding new public/protected component not marked with @SnowflakeJdbcInternalApi (note that public/protected methods/fields in classes marked with this annotation are already internal)
  3. Please describe how your code solves the related issue.

    Please write a short description of how your code change solves the related issue.

@sfc-gh-ext-simba-jf sfc-gh-ext-simba-jf marked this pull request as ready for review November 28, 2024 06:06
@sfc-gh-ext-simba-jf sfc-gh-ext-simba-jf requested a review from a team as a code owner November 28, 2024 06:06
@Test
public void testSetQueryTimeoutForAsnycQuery() throws SQLException {
try (Statement statement = connection.createStatement()) {
statement.unwrap(SnowflakeStatement.class).setParameter("MULTI_STATEMENT_COUNT", 0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

why do we need multistatements? we are sendinf single query


QueryStatus queryStatus = QueryStatus.RUNNING;
while (queryStatus == QueryStatus.RUNNING
|| queryStatus == QueryStatus.RESUMING_WAREHOUSE) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

resuming warehouse it's not an error we should check - if we want to avoid it let's run a normal query without timeout before to ensure that Warehouse is ready

statement.unwrap(SnowflakeStatement.class).executeAsyncQuery(sql)) {

QueryStatus queryStatus = QueryStatus.RUNNING;
while (queryStatus == QueryStatus.RUNNING
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's use awaitility for waiting

} catch (InterruptedException e) {
fail(e.getMessage());
}
queryStatus = resultSet.unwrap(SnowflakeResultSet.class).getStatus();
Copy link
Collaborator

Choose a reason for hiding this comment

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

we should use getStatusV2

queryStatus = resultSet.unwrap(SnowflakeResultSet.class).getStatus();
}

if (queryStatus == QueryStatus.FAILED_WITH_ERROR) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's not have the if - it should always fail, checkout my fix in #1974

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

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

Choose a reason for hiding this comment

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

can we use gnerated data instead of predefined?

public void testSetQueryTimeoutForAsnycQuery() throws SQLException {
try (Statement statement = connection.createStatement()) {
statement.unwrap(SnowflakeStatement.class).setParameter("MULTI_STATEMENT_COUNT", 0);
statement.setQueryTimeout(3);
Copy link
Collaborator

Choose a reason for hiding this comment

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

the connection is reused now in this test so when we set the timeout all the tests in this class will have the timeout - we should have local connection or reset query timeout in finally

queryTimeout = (Integer) propertyValue;
// Set server parameter for supporting query timeout on async queries
statementParametersMap.put("STATEMENT_TIMEOUT_IN_SECONDS", (Integer) propertyValue);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am also not sure if we want to mix the behaviour here for sync and async queries - do our users receive exactly the same error as before when driver internall was timing out?
To play safe I would suggest creating new method in SnowflakeStatement with explicit name setAsyncQueryTimeout
in the existing setQueryTimeout method I would guard the STATEMENT_TIMEOUT_IN_SECONDS with some new driver parameter with default to false e.g. SUPPORT_IMPLICIT_ASYNC_QUERY_TIMEOUT
@sfc-gh-abenzaoui WDYT?

@sfc-gh-dprzybysz sfc-gh-dprzybysz changed the title SNOW-1524152-Implement-setQueryTimeout-for-async-queries SNOW-1524152: Implement setQueryTimeout for async queries Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants