指定实体

In the snowflake.yml definition file, you can specify multiple entities. Each entity is identified by a unique key. The example below specifies two entities with the entity_a and entity_b keys:

entities:
  entity_a:
    ...
  entity_b:
    ...

每个实体都必须指定一个类型。目前支持的类型包括:

实体标识符

You can specify multiple entities of the same type in the snowflake.yml file. You can name entities in the following ways:

  • 在实体列表中使用唯一密钥。

    The following example shows using entity_a and entity_b as the unique keys:

    entities:
      entity_a:
     ...
      entity_b:
     ...
  • Specify an identifier name to each entity.

    The following example adds identifier names to the entity_a and entity_b entities:

    entities:
      entity_a:
     identifier: entity_a_name
     ...
      entity_b:
     identifier:
       name: entity_a_name
  • Add an identifier object to each entity.

使用标识符对象允许为每个实体指定名称、数据库和架构,如以下示例所示:

entities:
  entity_b:
 identifier:
   name: entity_a_name
   schema: public
   database: DEV

如果未指定标识符,则使用实体密钥作为对象的名称,而不需要任何数据库或架构限定。

项目 mixin

In many cases you might find it useful to define project-wide default values. Mixins provide a way to extract common attributes out of individual entities. You can specify multiple mixins. You need to declare which mixins should be used by each entity using meta.use_mixins property.

在实体中使用 mixin 时,必须确保 mixin 的所有属性都可以应用于该实体。应用实体上不可用的属性会导致错误。因此,在某些情况下,您可能需要使用多个 mixin。

Note

显式声明的实体属性可覆盖 Mixin 值。

The following example includes two mixins: stage_mixin and snowpark_shared. The my_dashboard entity uses only stage_mixin, while the my_function entity uses both of the mixins.

definition_version: 2
mixins:
  stage_mixin:
    stage: "my_stage"
  snowpark_shared:
    artifacts: ["app/"]
    imports: ["@package_stage/package.zip"]

entities:
  my_function:
    type: "function"
    ...
    meta:
      use_mixins:
        - "stage_mixin"
        - "snowpark_shared"
  my_dashboard:
    type: "dashboard"
    ...
    meta:
      use_mixins:
        - "stage_mixin"

If an entity uses multiple mixins that specify the same property, the entity uses the value of later mixin. In the following example, the value of key on the foo entity will be mixin_2_value.

mixins:
  mixin_1:
    key: mixin_1_value
  mixin_2:
    key: mixin_2_value

entities:
  foo:
    meta:
      use_mixin:
      - mixin_1
      - mixin_2

应用 mixin 值的行为取决于值类型。对于标量值(字符串、数字、布尔),值将被覆盖。

Mixin notationExplicit result
definition_version: 2
mixins:
  mix1:
    stage: A

  mix2:
    stage: B

entities:
  test_procedure:
    stage: C
    meta:
      use_mixins:
        - mix1
        - mix2
definition_version: 2
entities:
  test_procedure:
    stage: C

如果是序列,则合并值以创建新序列。此实施可避免在序列中创建重复条目。

Mixin notationExplicit result
definition_version: 2
mixins:
  mix1:
    artifacts:
    - a.py

  mix2:
    artifacts:
    - b.py

entities:
  test_procedure:
    artifacts:
      - app/
    meta:
      use_mixins:
        - mix1
        - mix2
definition_version: 2
entities:
  test_procedure:
    artifacts:
      - a.py
      - b.py
      - app/

对于映射值,将添加新键并更新现有值。更新具有递归性。

Mixin notationExplicit result
definition_version: 2
mixins:
  mix1:
    secrets:
      secret1: v1

  mix2:
    secrets:
      secret2: v2

entities:
  test_procedure:
    secrets:
      secret3: v3
    meta:
      use_mixins:
        - mix1
        - mix2
definition_version: 2
entities:
  test_procedure:
    secrets:
      secret1: v1
      secret2: v2
      secret3: v3
definition_version: 2
mixins:
  mix1:
    secrets:
      secret_name: v1

  mix2:
    secrets:
      secret_name: v2

entities:
  test_procedure:
    secrets:
      secret_name: v3
    meta:
      use_mixins:
        - mix1
        - mix2
definition_version: 2
entities:
  test_procedure:
    secrets:
      secret_name: v3
definition_version: 2
mixins:
  shared:
    identifier:
      schema: foo

entities:
  sproc1:
    identifier:
      name: sproc
    meta:
      use_mixins: ["shared"]
  sproc2:
    identifier:
      name: sproc
      schema: from_entity
    meta:
      use_mixins: ["shared"]
definition_version: 2
entities:
  sproc1:
    identifier:
      name: sproc
      schema: foo
  sproc2:
    identifier:
      name: sproc
      schema: from_entity