I'm developing a software with Presto JDBC, and would like to get query's session ID to cancel the statement later in another thread.
In MySQL, I can get the ID as in:
long id = statement.getConnection().unwrap(MySQLConnection.class).getId();
(statement is an object of java.sql.Statement)
How can I get Presto statement's unique session ID? I'm looking into Presto JDBC document and sources but can't find it.
Before the query and not in the resultset
Any ideas or suggestions would be appreciated so much.
Sorry for the late reply. There are two options. First is to get the query ID from the ResultSet:
resultSet.unwrap(PrestoResultSet.class).getQueryId();
However, this will only tell you the query ID after results are available, which might be a long time for big queries. The other way is to add a progress monitor to Statement:
statement.unwrap(PrestoStatement.class).setProgressMonitor(stats -> {
stats.getQueryId();
});
The progress monitor is called many times during execution (with the latest stats each time). This callback happens inline, on the thread executing the query, so don't do anything slow or expensive here.
Note that Presto doesn't really have the concept of a session ID
Most helpful comment
Sorry for the late reply. There are two options. First is to get the query ID from the
ResultSet:However, this will only tell you the query ID after results are available, which might be a long time for big queries. The other way is to add a progress monitor to
Statement:The progress monitor is called many times during execution (with the latest stats each time). This callback happens inline, on the thread executing the query, so don't do anything slow or expensive here.
Note that Presto doesn't really have the concept of a session ID