Kill Snowflake queries from Spark Connector

Viewed 218

Is there a way to kill Snowflake queries using the Spark connector ? Alternatively is there a way to grab the last last query id or session id in Spark to kill it outside of Spark.

The use case is user controlled long running Spark jobs with long running Snowflake queries. When a user is killing the Spark jobs , the current Snowflake query keeps on running (for many hours )

Thank you

1 Answers

Log into snowflake UI (or use snowsql) with the same user you use for spark, and run following:

use database <your_db>;
use warehouse <your wh>;

select  
    query_id, query_text, execution_status, error_message, start_time, end_time     
from 
    table(information_schema.query_history( RESULT_LIMIT => 10) );

This should show you your recent queries. Find the one that is in RUNNING state, copy its QUERY_ID, and use to run this:

select system$cancel_query('<your query id here>');
Related