The following examples illustrate how you can use Snowpark APIs to begin asynchronous child jobs, as well as how those jobs behave under
different conditions.
In the following example, the asyncWait procedure executes an asynchronous child job that waits 10 seconds.
In the following example, the cancelJob procedure uses SQL to start a job that would take 10 seconds to finish. It then cancels
the child job before it finishes.
In the following example, the checkStatus procedure executes an asynchronous child job that waits 10 seconds. The procedure then
checks on the status of the job before it finishes, so the check returns False.
CREATEORREPLACEPROCEDURE checkStatus()
RETURNSVARCHARLANGUAGESCALARUNTIME_VERSION = 2.12PACKAGES = ('com.snowflake:snowpark_2.12:latest')
HANDLER = 'TestScalaSP.asyncBasic'
AS
$$
import java.sql.ResultSetimport net.snowflake.client.jdbc.{SnowflakeConnectionV1, SnowflakeResultSet, SnowflakeStatement}
objectTestScalaSP{
defasyncBasic(session: com.snowflake.snowpark.Session): String = {
val connection = session.jdbcConnection
val stmt = connection.createStatement()
val rs = stmt.asInstanceOf[SnowflakeStatement].executeAsyncQuery("CALL SYSTEM$WAIT(10)")
val status = rs.asInstanceOf[SnowflakeResultSet].getStatus.toString
s"""status: ${status}"""
}
}
$$;
CREATEORREPLACEPROCEDURE checkStatus()
RETURNSVARCHARLANGUAGESCALARUNTIME_VERSION = 2.13PACKAGES = ('com.snowflake:snowpark_2.13:latest')
HANDLER = 'TestScalaSP.asyncBasic'
AS
$$
import java.sql.ResultSetimport net.snowflake.client.jdbc.{SnowflakeConnectionV1, SnowflakeResultSet, SnowflakeStatement}
objectTestScalaSP{
defasyncBasic(session: com.snowflake.snowpark.Session): String = {
val connection = session.jdbcConnection
val stmt = connection.createStatement()
val rs = stmt.asInstanceOf[SnowflakeStatement].executeAsyncQuery("CALL SYSTEM$WAIT(10)")
val status = rs.asInstanceOf[SnowflakeResultSet].getStatus.toString
s"""status: ${status}"""
}
}
$$;