Skip to main content
code.register_dataset registers a Snowflake table or view as a Narrative dataset in code, without launching the Native App’s Configuration screen — from a worksheet, the Snowflake SQL API, or a scheduled task. Use it to script dataset onboarding, or to run it from the pipeline that already builds the table. The Configuration screen is unchanged and is still the simplest way to register your first dataset. Both routes produce the same dataset, and both depend on the app having been installed and configured once — see Install the Snowflake Native App for that setup.

Prerequisites

  • The Snowflake Native App installed, with its external access integration and API token configured. These also create the Narrative data plane the dataset attaches to.
  • At least one warehouse granted to the application, because every job the operator later runs against the dataset — health checks, samples, statistics, deliveries — needs one. This grant cannot be requested through Snowflake’s reference framework and has to be run by an ACCOUNTADMIN:
  • The dataset_registration application role, or app_admin.

Grant the registration role

dataset_registration carries usage on the two registration procedures and read access to the app’s mapping table, and nothing else. The procedures run with owner’s rights, so a caller needs no privilege on the source object, the API token, or the app’s own state.
app_admin also works, since it holds dataset_registration. Prefer the smaller role for anyone whose job is registering datasets — app_admin additionally grants full write access to the application’s state, every function it exposes, and its compute pools and services.
Neither role confers anything in your account outside the application, and neither can read your tables. Access to your own objects is granted separately, per object, as described next.

Register a table or view

code.register_dataset describes the object, derives its schema, creates and activates the dataset, and returns the new dataset_id. There are two ways to give it the source object.
An object can only be bound once per reference. A second system$reference for the same table is rejected with “The same object cannot be added more than once” — including when the Configuration screen bound it. To register an object that is already bound, pass its alias in place of the reference:
To register the same table as a second dataset, address it by name rather than by reference.

Arguments

What it returns

unsupported_columns is not an error. The dataset registers without those columns, so check this field if a column you expected is missing downstream.

Override the inferred schema

By default the schema comes from desc table or desc view, with variant, array and object columns resolved by sampling 1000 rows. code.infer_dataset_schema returns what register_dataset would infer, without creating anything:
infer_dataset_schema takes object_type and source exactly as register_dataset does, which means passing a system$reference token here will bind the reference. Pass a qualified name or an already-bound alias when you only want to look.
Edit what it returns and pass it back as schema_override. Inference is then skipped entirely, including the sampling:
The format is Narrative’s dataset schema: an object whose properties map column names to types, where a type is one of string, long, double, boolean, timestamptz, {"type":"array","items":…}, or {"type":"object","properties":{…}}. Property names must match the column names Snowflake reports, which are upper-case unless the column was created quoted. Do not include file_config — the procedure adds it.

Errors

The procedure validates before it changes anything, and every failure names its remedy.

Troubleshooting

The procedure is created once the external access integration is bound, and recreated on every app upgrade. If it is missing, the integration or the API token is not configured. Configure them, then force the pass:
This returns external access integration not available if the integration still is not bound.
Everything here is a stored procedure, so it is invoked with CALL and cannot be used inside a SELECT expression. Snowflake reports that as Unknown user-defined function, which reads like the procedure is missing when it is only being called the wrong way.
The dataset keeps pointing at the old object. Remove it and register the replacement.

Remove a dataset

Removing a dataset goes through the Narrative API. code.call_narrative_api calls it with the account’s configured token, and is granted to app_admin only:
The operator then removes the app’s mapping, and the reference too if there was one. The same procedure inspects a dataset:

Install the Snowflake Native App

One-time setup, and registering a dataset through the Configuration screen

Snowflake Native App Reference

Capabilities, requirements, privileges, and naming conventions

Data Planes

How a customer-hosted data plane executes work

Compute Pools

The warehouses that run jobs against your registered datasets