Skip to main content

0. Grant yourself read access to Kumo tables 

Because Kumo may create new tables or update existing ones during prediction runs, grant yourself (or a reader role) access to existing and future tables in the destination schema.
Replace placeholders:
  • TARGET_DB / TARGET_SCHEMA → where your BP writes prediction/output tables
  • MY_ROLE → the role you use to read those outputs (can be ACCOUNTADMIN, or any role)
-- you must have these to "see" the objects
GRANT USAGE ON DATABASE TARGET_DB TO ROLE MY_ROLE;
GRANT USAGE ON SCHEMA  TARGET_DB.TARGET_SCHEMA TO ROLE MY_ROLE;

-- read existing tables (one-time for what already exists)
GRANT SELECT ON ALL TABLES IN SCHEMA TARGET_DB.TARGET_SCHEMA TO ROLE MY_ROLE;

-- read all future tables (so you don't have to grant every run)
GRANT SELECT ON FUTURE TABLES IN SCHEMA TARGET_DB.TARGET_SCHEMA TO ROLE MY_ROLE;

1. Define Procedures

Create two small procedures you can call from the notebook to safely start and stop the Kumo app.
Replace:
  • MY_DB.MY_SCHEMA → where to store these procedures (e.g., KUMO.AUTOMATION)
  • MY_APP → your installed app name (e.g., KUMO_SPCS_RELEASE_INTERNAL)
  • MY_USER_SCHEMA → schema used when installing the app
-- Idempotent START_APP
CREATE OR REPLACE PROCEDURE MY_DB.MY_SCHEMA.START_APP()
RETURNS STRING
LANGUAGE JAVASCRIPT
EXECUTE AS CALLER
AS
$$
function run(sql){ snowflake.execute({sqlText: sql}); }
try {
  // If this resolves, the app is already running
  run("CALL IDENTIFIER('MY_APP.PROCEDURES.GET_END_POINT')('MY_USER_SCHEMA')");
  return 'App already running; no action taken.';
} catch (e) {
  // Not running -> start it
  run("CALL IDENTIFIER('MY_APP.PROCEDURES.START_APP')('MY_USER_SCHEMA')");
  return 'App start initiated.';
}
$$;

-- Idempotent STOP_APP
CREATE OR REPLACE PROCEDURE MY_DB.MY_SCHEMA.STOP_APP()
RETURNS STRING
LANGUAGE JAVASCRIPT
EXECUTE AS CALLER
AS
$$
function run(sql){ snowflake.execute({sqlText: sql}); }
try {
  // Try to stop; if already stopped, the call may error — we swallow it
  run("CALL IDENTIFIER('MY_APP.PROCEDURES.SHUTDOWN_APP')('MY_USER_SCHEMA')");
  return 'App stop initiated.';
} catch (e) {
  return 'App already stopped or stop not needed; no action taken.';
}
$$;

2. Use these in your Kumo BP SDK snippet

If you haven’t set up the SDK yet, follow the setup guide here
Rules:
  • Call START_APP() first (very first command).
  • Run your BP pipeline with non_blocking = False so the notebook waits for completion.
  • Call STOP_APP() last (very last command), so the app shuts down after the job.

Example notebook flow

SQL cell — start app (first line):
CALL MY_DB.MY_SCHEMA.START_APP();
Python cell — Kumo BP SDK (make sure non_blocking=False):
import kumoai

# Gather artifacts
pquery = kumoai.PredictiveQuery.load_from_training_job("trainingjob-...")
graph = pquery.graph

# Create a prediction table from the predictive query:
prediction_table = pquery.generate_prediction_table()

# Generate predictions:
trainer = kumoai.Trainer.load("trainingjob-...")
prediction_job = trainer.predict(
    pquery.graph,
    pquery.generate_prediction_table(),
    non_blocking = False  # <<< Make sure this is False so the notebook waits
)
SQL cell — stop app (last line):
CALL MY_DB.MY_SCHEMA.STOP_APP();

3) Schedule the Containerized Notebook

  1. Open your containerized notebook in Snowflake.
  2. Click Schedule.
  3. Set your CRON/time zone and save
CRON examples
  • Every 3 hours (top of hour):
    USING CRON 0 */3 * * * America/Chicago
  • Daily at 7:00 AM:
    USING CRON 0 7 * * * America/Chicago
  • Daily at 8:00 PM:
    USING CRON 0 20 * * * America/Chicago
I