snowflakedb / snowflake-jdbc

Snowflake JDBC Driver
Apache License 2.0
173 stars 163 forks source link

SNOW-159714: Not possible to see query errors using async API #237

Closed buremba closed 1 year ago

buremba commented 4 years ago

The async method Statement.executeAsyncQuery returns SFAsyncResultSet which lets us use getStatus() until the query is finished but in case the query is finished with status FAILED_WITH_ERROR there is no way to see the underlying error.

SFAsyncResultSet returns the following exception in this case: (see: https://github.com/snowflakedb/snowflake-jdbc/blob/e64d5d4a045ee43d46bef9b25aeec68fcbac4277/src/main/java/net/snowflake/client/jdbc/SFAsyncResultSet.java#L162)

Status of query associated with resultSet is FAILED_WITH_ERROR. Results not generated.
buremba commented 4 years ago

Is there any update on this? Not sure if the maintainers are looking into the Github Issues. 🤔

sfc-gh-hkapre commented 3 years ago

@buremba We are looking into this.

kiranking007 commented 2 years ago

It's been a year and I see this issue today with my job. Has this been fixed and release in a new version? or is it closed?

buremba commented 2 years ago

I don't think it's fixed. Looks like it's not prioritized and probably dead in their backlog. :(

sixdimensionalarray commented 2 years ago

@sfc-gh-hkapre @sfc-gh-mknister this still makes it incredibly difficult to debug entire classes of errors using the Snowflake JDBC lib. I don't think it just affects Async queries either. Any chance we can get the details from this added to the exception thrown? https://docs.snowflake.com/en/user-guide/jdbc-api.html#id13

odykstra commented 1 year ago

Glad to see this bug has work in progress. I'm facing the same issue in one of my workflows.

sfc-gh-mknister commented 1 year ago

@buremba @odykstra @sixdimensionalarray We are now adding the error message to be displayed in the SQLException message body. There is already a way to see the query's underlying error message and code by calling QueryStatus.getErrorMessage() and QueryStatus.getErrorCode() as seen in the 2 examples of asynchronous querying documentation here: https://docs.snowflake.com/en/developer-guide/jdbc/jdbc-using#examples-of-asynchronous-queries. Another example would be:

try {
    ResultSet rs = statement.unwrap(SnowflakeStatement.class).executeAsyncQuery("select * from nonexistentTable");
    rs.next();
    } catch (SQLException ex) {
        // Print query error message
        System.out.println(rs.unwrap(SnowflakeResultSet.class).getStatus().getErrorMessage());
        // Print query error code
        System.out.println(rs.unwrap(SnowflakeResultSet.class).getStatus().getErrorCode());
    }

The getErrorMessage() function is inside the QueryStatus class. Is this an ask to make the error message fetchable from the SnowflakeResultSet class as well, like adding a similar SnowflakeResultSet.getQueryErrorMessage?

sfc-gh-mknister commented 1 year ago

Added function SnowflakeResultSet.getQueryErrorMessage() in case customers want to access error message from ResultSet class. PR: https://github.com/snowflakedb/snowflake-jdbc/pull/1328