Categories:

Information Schema , Table functions

CODE_BUNDLE_HISTORY

Returns the run history of Code Bundles: one row per run of EXECUTE CODE BUNDLE or EXECUTE NOTEBOOK PROJECT, including anonymous runs (EXECUTE CODE BUNDLE FROM ...) and runs submitted through the REST API. All arguments are optional and act as filters. With no arguments, the function returns the most recent runs, up to RESULT_LIMIT.

Use this function to check whether a run succeeded, find a run by its query ID or execution name, and review failures.

See also:

EXECUTE CODE BUNDLE, SHOW CODE BUNDLES, Monitor Code Bundle runs

Syntax

CODE_BUNDLE_HISTORY(
  [ BUNDLE_NAME => '<string>' ]
  [ , DATABASE => '<string>' ]
  [ , SCHEMA => '<string>' ]
  [ , ENTRYPOINT => '<string>' ]
  [ , START_TIME_RANGE_START => <constant_expr> ]
  [ , START_TIME_RANGE_END => <constant_expr> ]
  [ , BUNDLE_TYPES => '<string>' ]
  [ , COMPUTE_TYPES => '<string>' ]
  [ , LANGUAGE_TYPES => '<string>' ]
  [ , STATUS => '<string>' ]
  [ , EXECUTION_NAME => '<string>' ]
  [ , QUERY_ID => '<string>' ]
  [ , RESULT_LIMIT => <integer> ]
  [ , PAGE_TOKEN => '<string>' ]
)

Arguments

All arguments are optional.

BUNDLE_NAME => '<string>'

Name of the Code Bundle to return runs for. You can specify a fully qualified name (database.schema.bundle) or a bare name combined with DATABASE and SCHEMA.

DATABASE => '<string>'

Database used to resolve a bare BUNDLE_NAME, or to return runs of Code Bundles in that database. Ignored when BUNDLE_NAME is fully qualified.

SCHEMA => '<string>'

Schema used to resolve a bare BUNDLE_NAME, or to return runs of Code Bundles in that schema. Ignored when BUNDLE_NAME is fully qualified.

ENTRYPOINT => '<string>'

Returns only runs whose entrypoint matches this value exactly (for example, main.py, main.py:run, or com.example.MyApp).

START_TIME_RANGE_START => <constant_expr>, START_TIME_RANGE_END => <constant_expr>

TIMESTAMP_LTZ values that bound the start time of the returned runs. Both ends are inclusive.

BUNDLE_TYPES => '<string>'

Comma-separated, case-insensitive list of bundle types to include: custom, spark, and ml.

COMPUTE_TYPES => '<string>'

Comma-separated, case-insensitive list of compute types to include: warehouse and compute_pool.

LANGUAGE_TYPES => '<string>'

Comma-separated, case-insensitive list of languages to include: python, java, and scala.

STATUS => '<string>'

A single status to filter by: pending, running, done (or succeeded), failed, cancelled (or canceled), or deleted.

These filter values aren’t the same as the values in the STATUS column. For example, a successful run has STATUS DONE.

EXECUTION_NAME => '<string>'

Returns only runs whose EXECUTION_NAME, set with EXECUTE CODE BUNDLE, matches this value exactly.

QUERY_ID => '<string>'

Returns the run started by the statement with this query ID. The query ID of an EXECUTE CODE BUNDLE statement identifies its run. It’s the same value as the job_id returned by a REST submission.

RESULT_LIMIT => <integer>

Maximum number of rows to return. Default: 100. Values are limited to the range 1 to 1000.

PAGE_TOKEN => '<string>'

Returns the runs after the row that the token came from. To get the next page of results, pass the PAGE_TOKEN value from the last row of the previous call, with the same filters.

Output

The function returns one row per run, with the following columns:

ColumnDescription
CODE_BUNDLE_NAMEName of the Code Bundle. NULL for an anonymous run.
DATABASE_NAMEDatabase of the Code Bundle. NULL for an anonymous run.
SCHEMA_NAMESchema of the Code Bundle. NULL for an anonymous run.
ENTRYPOINTEntrypoint of the run.
STATUSState of the run, for example DONE or FAILED.
RUNTIME_STATUS_DETAILSAdditional status details from the runtime, if any.
SQL_ERROR_CODESnowflake error code of a failed run.
ERROR_MESSAGEError message of a failed run.
BUNDLE_TYPEBundle type of the run, for example SPARK.
COMPUTE_TYPECompute type that the run used: WAREHOUSE or COMPUTE_POOL.
LANGUAGE_TYPELanguage of the run, for example PYTHON or SCALA.
RUNTIME_NAMEName of the runtime that ran the code: the warehouse name, or the name of the service on the compute pool.
START_TIMETime when the run started.
END_TIMETime when the run finished. NULL while the run is in progress.
QUERY_IDQuery ID of the statement that started the run.
EXECUTION_NAMEExecution name set for the run, if any.
RUNTIME_VERSIONRuntime version that the run used, for example the Python version on a warehouse or the Container Runtime version on a compute pool.
TASK_NAMEFully qualified name of the task that started the run. NULL if the run wasn’t started by a task.
PAGE_TOKENContinuation token for the next page of results. Pass it as the PAGE_TOKEN argument to get the runs after this row.

Usage notes

  • Call the function as SNOWFLAKE.INFORMATION_SCHEMA.CODE_BUNDLE_HISTORY, or qualify it with a database that you can access, such as my_db.INFORMATION_SCHEMA.CODE_BUNDLE_HISTORY. If you call it unqualified and your session has no current database, the query fails.
  • The runs that you can see depend on your role’s privileges on the Code Bundle and your IMPERSONATE privilege on the user who started each run. For details, see Run history and result visibility.
  • An asynchronous run appears in the history after it starts. If a statement fails before the run starts, for example because the entrypoint doesn’t exist, the run doesn’t appear in the history; check the statement’s error instead.

Examples

Return the most recent runs of a Code Bundle:

SELECT *
  FROM TABLE(SNOWFLAKE.INFORMATION_SCHEMA.CODE_BUNDLE_HISTORY(
    BUNDLE_NAME => 'my_db.my_schema.my_bundle'));

Check the status of one run by its query ID:

SELECT STATUS, ERROR_MESSAGE, START_TIME, END_TIME
  FROM TABLE(SNOWFLAKE.INFORMATION_SCHEMA.CODE_BUNDLE_HISTORY(
    QUERY_ID => '01c51743-c819-4261-0000-5349586311aa'));

Find failed Python runs on warehouses in the last day:

SELECT CODE_BUNDLE_NAME, ENTRYPOINT, ERROR_MESSAGE, QUERY_ID
  FROM TABLE(SNOWFLAKE.INFORMATION_SCHEMA.CODE_BUNDLE_HISTORY(
    START_TIME_RANGE_START => DATEADD('day', -1, CURRENT_TIMESTAMP()),
    COMPUTE_TYPES => 'warehouse',
    LANGUAGE_TYPES => 'python',
    STATUS => 'failed',
    RESULT_LIMIT => 1000));

Find anonymous runs by execution name:

SELECT QUERY_ID, STATUS, START_TIME
  FROM TABLE(SNOWFLAKE.INFORMATION_SCHEMA.CODE_BUNDLE_HISTORY(
    EXECUTION_NAME => 'adhoc_backfill'));

Get the next page of results by passing the PAGE_TOKEN value from the last row of the previous page:

SELECT *
  FROM TABLE(SNOWFLAKE.INFORMATION_SCHEMA.CODE_BUNDLE_HISTORY(
    BUNDLE_NAME => 'my_db.my_schema.my_bundle',
    RESULT_LIMIT => 100,
    PAGE_TOKEN => '<page_token_from_last_row>'));