CREATE NOTEBOOK

Creates a new Snowflake notebook or replaces an existing notebook.

语法

CREATE [ OR REPLACE ] NOTEBOOK [ IF NOT EXISTS ] <name>
  [ FROM '<source_location>' ]
  [ MAIN_FILE = '<main_file_name>' ]
  [ COMMENT = '<string_literal>' ]
  [ QUERY_WAREHOUSE = <warehouse_to_run_nb_and_sql_queries_in> ]
  [ IDLE_AUTO_SHUTDOWN_TIME_SECONDS = <number_of_seconds> ]
  [ RUNTIME_NAME = '<runtime_name>' ]
  [ COMPUTE_POOL = '<compute_pool_name>' ]
  [ WAREHOUSE = <warehouse_to_run_notebook_python_runtime> ]

必填参数

name

指定笔记本标识符(即名称)的字符串;在创建笔记本的架构中必须是唯一的。

In addition, the identifier must start with an alphabetic character and cannot contain spaces or special characters unless the entire identifier string is enclosed in double quotes (for example, "My object"). Identifiers enclosed in double quotes are also case-sensitive.

For more information, see Identifier requirements.

可选参数

FROM 'source_location'

Specifies that the notebook should be created from an .ipynb file in the specified stage location. To create the notebook from a file on a stage, set source_location to the stage location of the file, and set the MAIN_FILE parameter to the name of the file.

如果未指定此参数,则通过模板笔记本创建笔记本对象。

MAIN_FILE = 'main_file_name'

User-specified identifier for the notebook file name. This is separate from the notebook object name, which is specified in the name parameter. This file must be an ipynb file.

QUERY_WAREHOUSE = warehouse_name

指定运行笔记本中 SQL 查询的仓库。此参数是可选的。但是,需要运行 EXECUTE NOTEBOOK 命令。

IDLE_AUTO_SHUTDOWN_TIME_SECONDS = number_of_seconds

笔记本自动关闭前的空闲时间秒数。此参数仅适用于在容器运行时运行的笔记本。值必须是介于 60 和 259200(72 小时)之间的整数。

默认值:3600 秒

RUNTIME_NAME = runtime_name
  • ‘SYSTEM$WAREHOUSE_RUNTIME’ (default): Runs the notebook in a Snowflake warehouse (Warehouse Runtime only).
  • ‘SYSTEM$BASIC_RUNTIME’: Runs the notebook in a Snowpark Container Services (SPCS) container using a CPU runtime (Container Runtime only).
  • ‘SYSTEM$GPU_RUNTIME’: Runs the notebook in a Snowpark Container Services (SPCS) container using a GPU runtime (Container Runtime only).

When specifying a Container Runtime (SYSTEM$BASIC_RUNTIME_ or _SYSTEM$GPU_RUNTIME), you must also include the COMPUTE_POOL parameter. SYSTEM$WAREHOUSE_RUNTIME is for Warehouse Runtime only.

COMPUTE_POOL = compute_pool_name

(Container Runtime only) Specifies the compute pool that hosts the notebook when using a Container Runtime. This parameter is required when RUNTIME_NAME is set to SYSTEM$BASIC_RUNTIME_ or _SYSTEM$GPU_RUNTIME.

For more information about compute pools, see Snowpark Container Services: Working with compute pools.

WAREHOUSE = warehouse_name

The warehouse is used to run:

  • For Warehouse Runtime: Both the notebook kernel and SQL queries (including Snowpark pushdown compute).
  • For Container Runtime: Only SQL queries (including Snowpark pushdown compute). The notebook kernel runs on the compute pool.

If you don’t specify a warehouse when you create a notebook, Snowflake uses the default warehouse defined by the schema lineage parameter DEFAULT_STREAMLIT_NOTEBOOK_WAREHOUSE. You can set this parameter at the schema, database, or account lineage level to define a preferred warehouse.

访问控制要求

A role used to execute this operation must have the following privileges at a minimum:

权限对象
USAGE数据库
USAGE 或 OWNERSHIP架构
CREATE NOTEBOOK架构

Operating on an object in a schema requires at least one privilege on the parent database and at least one privilege on the parent schema.

For instructions on creating a custom role with a specified set of privileges, see Creating custom roles.

For general information about roles and privilege grants for performing SQL actions on securable objects, see Overview of Access Control.

使用说明

  • When creating a notebook that uses a Container Runtime, the notebook runs inside a Snowpark Container Services environment. Container runtime notebooks must specify both the RUNTIME_NAME and COMPUTE_POOL parameters.

  • 关于元数据:

    Attention

    Customers should ensure that no personal data (other than for a User object), sensitive data, export-controlled data, or other regulated data is entered as metadata when using the Snowflake service. For more information, see Metadata fields in Snowflake.

  • The OR REPLACE and IF NOT EXISTS clauses are mutually exclusive. They can’t both be used in the same statement.
  • CREATE OR REPLACE <object> statements are atomic. That is, when an object is replaced, the old object is deleted and the new object is created in a single transaction.

示例

The following creates a notebook named mynotebook:

CREATE NOTEBOOK mynotebook;

虽然 QUERY_WAREHOUSE 参数是可选的,但建议在创建新笔记本时指定该参数,以便可以在仓库上运行 EXECUTE NOTEBOOK。

CREATE NOTEBOOK mynotebook
 QUERY_WAREHOUSE = my_warehouse;

The following example creates a notebook from an ipynb file on a stage:

CREATE NOTEBOOK mynotebook
 FROM '@my_db.my_schema.my_stage'
 MAIN_FILE = 'my_notebook_file.ipynb'
 QUERY_WAREHOUSE = my_warehouse;

The following example creates a notebook using Container Runtime (CPU):

CREATE NOTEBOOK my_cpu_notebook
  RUNTIME_NAME = 'SYSTEM$BASIC_RUNTIME'
  COMPUTE_POOL = 'my_compute_pool';

The following example creates a notebook using Container Runtime (GPU):

CREATE NOTEBOOK my_gpu_notebook
  RUNTIME_NAME = 'SYSTEM$GPU_RUNTIME'
  COMPUTE_POOL = 'gpu_pool_1';