CREATE DBT PROJECT¶
Creates a new dbt project object or replaces an existing dbt project object. Running CREATE DBT PROJECT with the OR REPLACE option resets the version identifier to version$1 and removes all version name aliases. For more information, see Versions for dbt project objects and files.
- こちらもご参照ください。
ALTER DBT PROJECT、 DESCRIBE DBT PROJECT、 EXECUTE DBT PROJECT、 SHOW DBT PROJECTS、 DROP DBT PROJECT
構文¶
パラメーター¶
nameString that specifies the name of the dbt project object. Must be unique within the schema in which the dbt project object is created.
また、識別子はアルファベット文字で始まる必要があり、識別子文字列全体が二重引用符で囲まれていない限り、スペースや特殊文字を含めることはできません(例:
"My object")。二重引用符で囲まれた識別子も大文字と小文字が区別されます。詳細については、 識別子の要件 をご参照ください。
FROM 'source_location'Required. A string that specifies the location of the dbt project source files.
The source location must point to a directory that contains a single
dbt_project.ymlfile at its root. Although workspaces support working with repositories that contain multiple dbt projects, you must select a specific project directory when deploying a dbt project object.The dbt project object source files can be in any one of the following locations:
Gitリポジトリステージ。たとえば:
'@my_db.my_schema.my_git_repository_stage/branches/my_branch/path/to/dbt_project_or_projects_parent'SnowflakeでGitリポジトリオブジェクトを作成し、Gitリポジトリを |sf-dbt|のワークスペースに接続する方法については、 label-dbt_create_git_integrated_workspace`をご参照ください。ワークスペースを使用せずにGitリポジトリオブジェクトとステージを作成および管理する方法の詳細については、 :doc:/developer-guide/git/git-overview` および :doc:`/sql-reference/sql/create-git-repository`をご参照ください。
既存のdbtプロジェクトステージ。例えば:
'snow://dbt/my_db.my_schema.my_existing_dbt_project_object/versions/last'The version specifier is required and can be
last(as shown in the previous example),first, or the specifier for any existing version in the formversion$<num>. For more information, see Versions for dbt project objects and files.内部の名前付きステージ。たとえば:
'@my_db.my_schema.my_internal_named_stage/path/to/dbt_projects_or_projects_parent'内部ユーザーステージとテーブルステージはサポートされていません。
Snowflake上のdbtのワークスペース。たとえば:
'snow://workspace/user$.public."my_workspace_name"/versions/live/path/to/dbt_projects_or_projects_parent'ワークスペース名は大文字と小文字が区別され、特殊文字を含めることができるため、ワークスペース名を二重引用符で囲むことをお勧めします。
The version specifier is required and can be
last,first,live, or the specifier for any existing version in the formversion$<num>. For more information, see Versions for dbt project objects and files.
COMMENT = 'string_literal'dbtプロジェクトオブジェクトのコメントを指定します。
デフォルト: 値なし
DBT_VERSION = version_numberSpecifies a version for the dbt project object.
If no value is specified, the system defaults to the version set by the DEFAULT_DBT_VERSION account parameter. For more information, see Set the account-level default version.
DEFAULT_TARGET = default_targetSpecifies the profile used for compilation and subsequent executions (for example,
prod) of the dbt project object. You can override this parameter by using the EXECUTE DBT PROJECT command withARGS = '--target <other_target>'.デフォルト: 値なし
EXTERNAL_ACCESS_INTEGRATIONS = ( integration_name [ , ... ] )dbtパッケージハブまたはGitHubからリモート依存関係をプルする権限を付与するために使用される外部アクセス統合を指定します。オブジェクトに対して宣言する場合、
dbt depsはデプロイ中に自動的に実行されます。詳細については、 Snowflake上のdbtプロジェクトの依存関係を理解する をご参照ください。
アクセス制御の要件¶
この操作の実行に使用される ロール には、少なくとも次の 権限 が必要です。
権限 |
オブジェクト |
|---|---|
CREATE DBT PROJECT |
スキーマ |
スキーマ内のオブジェクトを操作するには、親データベースの少なくとも1つの権限と、親スキーマの少なくとも1つの権限が必要です。
指定された権限のセットを使用してカスタムロールを作成する手順については、 カスタムロールの作成 をご参照ください。
セキュリティ保護可能なオブジェクト に対して SQL アクションを実行するためのロールと権限付与に関する一般的な情報については、 アクセス制御の概要 をご参照ください。
使用上の注意¶
OR REPLACE 句と IF NOT EXISTS 句は互いに排他的です。この2つを同じステートメントで使うことはできません。
CREATE OR REPLACE <オブジェクト> ステートメントはアトミックです。つまり、オブジェクトが置き換えられると、単一のトランザクションで、古いオブジェクトが削除されて新しいオブジェクトが作成されます。
メタデータについて:
注意
Snowflakeサービスを使用する場合、お客様は、個人データ(ユーザーオブジェクト向け以外)、機密データ、輸出管理データ、またはその他の規制されたデータがメタデータとして入力されていないことを確認する必要があります。詳細については、 Snowflakeのメタデータフィールド をご参照ください。
例¶
SnowflakeでGitリポジトリステージからdbtプロジェクトオブジェクトを作成する¶
Gitリポジトリステージのdbtプロジェクトファイルから sales_dbt_model という名前のdbtプロジェクトオブジェクトを作成します。この例は、Snowflakeで sales_dbt_git_stage という名前のGitリポジトリステージの main ブランチを参照します。プロジェクトの dbt_project.yml ファイルはリポジトリルートに保存されます。このコマンドは、dbtコマンドの実行時に使用されるデフォルトのターゲットも設定し、プロジェクトに必要な外部アクセス統合を指定します。
SnowflakeでGitリポジトリステージ内のサブディレクトリからdbtプロジェクトオブジェクトを作成する¶
複数のdbtプロジェクトを含むGitリポジトリステージ内部のサブディレクトリから sw_region_sales_model という名前のdbtプロジェクトオブジェクトを作成します。この例は、Snowflakeで sales_dbt_git_stage という名前のGitリポジトリステージの main ブランチを参照します。プロジェクトの dbt_project.yml ファイルは、 sales_dbt_projects_parent ディレクトリの sw_region_dbt_project サブディレクトリに保存されます。
この例では、次のプロパティも設定しています。
dbtバージョン
dbtコマンドによって使用されるデフォルトの実行ターゲット(たとえば
prodまたはdev)はSnowflakeを介して実行されます。External access integrations the dbt project object is permitted to use to pull remote dependencies from dbt package hub or Github.
既存のdbtプロジェクトオブジェクトの特定バージョンからdbtプロジェクトオブジェクトを作成する¶
Create a new dbt project object named sales_model_nw_region from version$2 of the existing sales_model dbt project object.
この例では、 DEFAULT_TARGET を使用してデフォルトの実行ターゲットも設定し、 EXTERNAL_ACCESS_INTEGRATIONS を使用して許可される外部アクセス統合を指定します。
複数のdbtプロジェクトを含むワークスペースからdbtプロジェクトオブジェクトを作成する¶
複数のdbtプロジェクトディレクトリを含むワークスペースのライブバージョンから sales_model_from_workspace という名前の新しいdbtプロジェクトオブジェクトを作成します。ユーザーの個人データベース内の「My dbt Project Workspace」。これは、ワークスペースにいくつかのサブプロジェクトがあり、特定のサブディレクトリからdbtプロジェクトオブジェクトを作成する場合に便利です。ワークスペースは大文字と小文字が区別され、特殊文字を含めることができるため、ワークスペース名を二重引用符で囲むことをお勧めします。