创建 Azure 暂存区

暂存区指定数据文件的存储位置(即“暂存”),以便可以将文件中的数据加载到表中。

本主题内容:

可以直接从指定的 Azure 容器中的文件或 Azure“文件夹”路径(即键值前缀)中的文件加载数据。如果路径以 / 结尾,则加载相应 Azure 文件夹中的所有对象。

外部暂存区

除了直接从 Azure 容器中的文件加载之外,Snowflake 还支持创建命名的外部暂存区,其中封装了暂存文件所需的所有信息,包括:

  • 暂存文件的 Azure 容器。

  • 容器的命名存储集成对象或 Azure 凭据(如果受保护)。

  • 加密密钥(如果容器中的文件已加密)。

命名的外部暂存区是可选的,但当您计划定期从同一位置加载数据时,建议 使用。有关创建外部暂存区的说明,请参阅下面的 `创建外部暂存区 `_。

备注

为改进 Azure 外部暂存区的查询性能,请将网络路由配置为使用 Microsoft 网络路由 (https://learn.microsoft.com/en-us/azure/storage/common/network-routing-preference#microsoft-global-network-versus-internet-routing)。有关说明,请参阅 Azure 文档 (https://learn.microsoft.com/en-us/azure/storage/common/configure-network-routing-preference?tabs=azure-portal)。

创建外部暂存区

您可以使用 SQL 或 Web 界面创建命名的外部暂存区。

备注

To create a stage, you must use a role that is granted or inherits the necessary privileges. For more information, see 访问控制要求 for CREATE STAGE.

使用 SQL 创建外部暂存区

使用 CREATE STAGE 命令创建外部暂存区。

以下示例创建名为 my_azure_stage 的外部暂存区。CREATE 语句包括在 配置 Azure 容器以加载数据 中创建的 azure_int 存储集成,以在 myaccount 账户中访问 Azure 容器 container1

数据文件存储在 load/files/ 路径中。该暂存区引用名为 my_csv_format 的命名文件格式对象,该对象描述了存储在路径中的文件中的数据:

CREATE STAGE my_azure_stage
  STORAGE_INTEGRATION = azure_int
  URL = 'azure://myaccount.blob.core.windows.net/mycontainer/load/files/'
  FILE_FORMAT = my_csv_format;
Copy

备注

blob.core.windows.net 端点用于所有受支持类型的 Azure Blob 存储账户,包括 Data Lake Storage Gen2。

备注

通过为暂存区指定命名的文件格式对象(或单个文件格式选项),以后就不必在用于从暂存区加载数据的 COPY 命令中指定相同的文件格式选项。有关文件格式对象和选项的详细信息,请参阅 CREATE FILE FORMAT

使用 Python 创建外部暂存区

使用 Snowflake Python APIsStageCollection.create 方法来创建外部暂存区。

与前面的 SQL 示例类似,以下 Python 示例创建了一个名为 my_azure_stage 的外部暂存区:

from snowflake.core.stage import Stage

my_stage = Stage(
  name="my_azure_stage",
  storage_integration="azure_int",
  url="azure://myaccount.blob.core.windows.net/mycontainer/load/files/"
)
root.databases["<database>"].schemas["<schema>"].stages.create(my_stage)
Copy

备注

Python API 当前不支持 CREATE STAGE SQL 命令的 FILE_FORMAT 参数。

使用 Snowsight 创建外部暂存区

要使用 Snowsight 创建指定外部暂存区,请执行以下操作:

  1. Sign in to Snowsight.

  2. At the top of the navigation menu, select Add a dashboard tile (Create) » Stage » External Stage.

  3. 选择外部云存储提供商:Amazon S3Microsoft AzureGoogle Cloud Platform

  4. Create Stage 对话框中,输入 Stage Name

  5. 选择要在其中创建暂存区的数据库和架构。

  6. 输入外部云存储位置的 URL

  7. 如果外部存储不是公开的,请启用 Authentication 并输入详细信息。有关更多信息,请参阅 CREATE STAGE

  8. (可选)取消选择 Directory table。目录表允许您在暂存区中查看文件,但需要仓库,因此会产生费用。您可以选择暂时取消选择此选项,稍后再启用目录表。

    If you enable Directory table, optionally select Enable auto-refresh, and then select your event notification or notification integration to automatically refresh the directory table when files are added or removed. For more information, see 自动目录表元数据刷新.

  9. If your files are encrypted, enable Encryption, and then enter your details.

  10. (Optional) To view a generated SQL statement, expand the SQL Preview. To specify additional options for your stage, such as AUTO_REFRESH, you can open this SQL preview in a worksheet.

  11. 选择 Create

使用 Classic Console 创建外部暂存区

Select Databases Databases 选项卡 » <db_name> » Stages.

下一步: 从 Azure 暂存区复制数据

语言: 中文