宣言型オートメーションバンドルを使用して機能ビューを管理する
プレビュー
この機能は プライベート プレビュー段階です。試用については、Databricksの連絡先にお問い合わせください。
宣言型オートメーションバンドル (旧Databricks アセットバンドル) を使用すると、特徴量ビューやそれらをマテリアライズするパイプラインなどの Databricks リソースをプログラムで検証、デプロイ、実行できます。「宣言型オートメーションバンドルとは?」をご覧ください。
このチュートリアルでは、4つのフィーチャービューを宣言し、それらを3つの方法で実体化するバンドルを作成します。オフラインストアとオンラインストアの両方に書き込まれる2つのバッチフィーチャー、オンラインストアに継続的に書き込まれるストリーミングフィーチャー、およびノコギリ波ウィンドウを持つストリーミングフィーチャーです。ノコギリ波ウィンドウを持つストリーミングフィーチャーは、バッチモードではオフラインストアとオンラインストアに実体化され、ストリーミングモードではオンラインストアに実体化されます。次に、設定を変更し、再デプロイし、すべてを破棄します。
バンドルで機能を宣言すると、デプロイするすべてのワークスペースで同じ定義が使用され、プロジェクトの他の部分と合わせてソースとしてレビューされます。これは、ノートブックから create_feature および materialize_features を呼び出す宣言型の代替手段です。機能ビューを参照してください。
各ステップでは、YAMLとPythonの両方での設定を示します。言語を選択すると、ページがその選択に従います。
要件
- Databricks CLI バージョン 1.24.0 以降。確認のために
databricks --versionをランします。Databricks CLI をインストールまたは更新するを参照してください。 - ダイレクトデプロイメントエンジン。
featuresおよびmaterialization_setsのリソースは、Terraform デプロイメントエンジンではサポートされていません。リソースの互換性 を参照してください。 - Unity Catalog有効化ワークスペース。要件を参照してください。
- 機能の作成および具体化の権限。「パーミッション」を参照してください。
- 既存のオンラインストア。オンラインストアの作成を参照してください。
- バッチマテリアライゼーション用のエンティティ列とTimestamp列がある既存のDeltaテーブル。Databricksテーブルを参照してください。
- ストリームマテリアライゼーションの既存のストリーム。ストリームの作成を参照してください。
Online Feature Store は ベータ版であり、限られたリージョンで利用できます。サードパーティのオンラインストアはサポートされていません。「 DatabricksオンラインFeature Store」を参照してください。
ソーステーブルとストリームにはそれぞれのライフサイクルがあり、どちらもバンドルリソースではありません。それらを最初に作成し、バンドル内で名前で参照してください。ステップ3はテーブルに対して行い、ステップ4はストリームに対して行います。
バンドル内のFeature Storeリソース
このチュートリアルでは、2つの Feature Store リソースタイプを宣言し、その違いがデプロイのコストを決定します。
- 機能ビュー : そのソース、集計、およびキーをカバーする機能の定義。これは軽量なメタデータです。機能ビュー、および構成リファレンスについては、featureを参照してください。
- Materialization set : 実体化された特徴量 のグループ。実体化された特徴量は、パイプラインまたはジョブを通じてテーブルにコンピュートされた 1 つの特徴量ビューであるため、これが重量級の半分になります。実体化された特徴量を 1 つのセットにグループ化すると、Databricks にそれらを一緒にコンピュートできることが伝わるため、Databricks はそれらを保持する最小のテーブルと LakeFlow Pipelines にパックします。特徴量ビューの実体化と、構成リファレンスについては、materialization_set と materialization_set.materialized_features を参照してください。
以下のステップで、バッチ機能、ストリーミング機能、のこぎり波ウィンドウを持つストリーミング機能を宣言します。プロジェクトに必要なものだけを宣言します。マテリアライゼーションがどのように機能するかについては、マテリアライズド特徴量ビューを参照してください。
ステップ1: 認証を設定する
最初に、開発マシンの Databricks CLI と Databricks ワークスペース間の認証を設定します。このページでは、OAuth ユーザーマシン間 (U2M) 認証と、認証に DEFAULT という名前の対応する Databricks 構成プロファイルを使用することを前提としています。
U2M 認証は、これらのステップをリアルタイムで試すのに適しています。完全に自動化されたワークフローの場合、Databricks では、代わりに OAuth マシン間 (M2M) 認証を使用することをお勧めします。OAuthを使用したDatabricksへのDatabricks Service Principalアクセスの承認のM2M認証の設定手順を参照してください。
-
Databricks CLIを使用して、ターゲットワークスペースごとに以下のコマンドを実行し、ローカルでOAuthトークン管理を開始します。
次のコマンドで、
<workspace-url>をhttps://1234567890123456.7.gcp.databricks.comのような Databricks ワークスペース インスタンスの URL に置き換えます。Bashdatabricks auth login --host <workspace-url> -
Databricks CLIは、入力した情報をDatabricks構成プロファイルとして保存するよう促します。
Enterを押して提案されたプロファイル名を受け入れるか、新規または既存のプロファイルの名前を入力してください。同じ名前の既存のプロファイルは、入力した情報で上書きされます。プロファイルを使用すると、複数のワークスペース間で認証コンテキストをすばやく切り替えることができます。既存のプロファイルのリストを取得するには、別のターミナルまたはコマンドプロンプトでDatabricks CLIを使用してコマンド
databricks auth profilesを実行します。特定のプロファイルの既存の設定を表示するには、コマンドdatabricks auth env --profile <profile-name>を実行します。 -
Webブラウザで、画面の指示に従ってDatabricksワークスペースにログインします。
-
以下のいずれかのコマンドをランして、プロファイルの現在のOAuthトークンの値とトークンの今後の有効期限のTimestampを表示します。
databricks auth token --host <workspace-url>databricks auth token -p <profile-name>databricks auth token --host <workspace-url> -p <profile-name>
同じ
--host値を持つプロファイルが複数ある場合、Databricks CLIが正しいOAuthトークン情報を見つけられるように--hostと-pオプションを一緒に指定する必要がある場合があります。
ステップ 2: バンドルを作成する
バンドルの空のディレクトリを作成し、ルートに databricks.yml ファイルを、その横に resources ディレクトリを作成します。
- YAML
- Python
以下の各ステップでは、バンドルリソースを宣言するために resources/ の下にファイルを1つ追加します。
databricks.yml
resources/
batch_feature.yml
streaming_feature.yml
streaming_feature_sawtooth.yml
databricks.yml 3つの要素を保持します。
- バンドル名。
includeエントリ。バンドルがリソースを読み込むファイルを決定します。- リソースが参照できる値 (カタログ、スキーマ、ソース名など) を保持する変数。
bundle:
name: feature-store-quickstart
include:
- resources/*.yml
variables:
catalog:
description: The catalog that features are written to.
default: main
schema:
description: The schema that features are written to.
default: features_demo
source_table:
description: The three-level name of the source Delta table.
default: main.features_demo.transactions
stream:
description: The three-level name of a Stream registered in Unity Catalog.
default: main.features_demo.events
online_store:
description: The online store that serves the features.
default: my_online_store
databricks.ymlのすべてを宣言することもできます。includeを省略し、各ステップの宣言を1つのresourcesマッピングの下に収集します:
bundle:
name: feature-store-quickstart
variables:
# The variables above.
resources:
features:
# The Feature Views from the following steps.
materialization_sets:
# The materialization sets from the following steps.
Pythonで宣言されたリソースは、databricks.ymlのpythonマッピングを通じてのみ見つけることができます。それがなければ、バンドルは正常に検証およびデプロイされますが、リソースは含まれていないため、今すぐ追加します:
bundle:
name: feature-store-quickstart
python:
venv_path: .venv
resources:
- 'resources:load_resources'
variables:
catalog:
description: The catalog that features are written to.
default: main
schema:
description: The schema that features are written to.
default: features_demo
source_table:
description: The three-level name of the source Delta table.
default: main.features_demo.transactions
stream:
description: The three-level name of a Stream registered in Unity Catalog.
default: main.features_demo.events
online_store:
description: The online store that serves the features.
default: my_online_store
venv_path は、Databricks CLIがこのコードを実行する仮想環境です。resourcesの下の各エントリは関数を<module>:<function>として名前を付け、Databricks CLIはバンドルのリソースを収集するために呼び出します。resourcesの下で複数の<module>:<function>エントリが宣言されている場合、Databricks CLIはすべての関数を呼び出し、それぞれが返すリソースを収集します。
次に、プロジェクトとその仮想環境を作成し、パッケージを追加します:
uv init --bare
uv venv .venv
uv add databricks-bundles
databricks.ymlが名前を付ける関数を使用してresources/__init__.pyを作成します。
from databricks.bundles.core import Bundle, Resources
def load_resources(bundle: Bundle) -> Resources:
resources = Resources()
# The following steps add resources here.
return resources
プロジェクトTemplateやミューテーターを含む、Pythonでのバンドル作成の詳細については、Pythonでのバンドル設定を参照してください。
ステップ 3: バッチ機能を追加する
これらの2つの特徴量ビューは、過去7日間および過去30日間にわたるユーザーごとのトランザクション数をカウントし、両方とも毎日再計算され、オフラインストアとオンラインストアにまとめてマテリアライズされます。
Feature Viewは、それ自体では定義に過ぎません。マテリアライゼーションセットは、それからデータを生成するものです。
各リソースには2つの名前が付けられています。transaction_count は リソースキー です。これは、バンドル内で一意である、ユーザーが選択する名前であり、databricks bundle コマンドがリソースのアドレス指定やその他の構成の参照に使用します。たとえば、セット transactions の transaction_count の2つの具体化された機能は、機能ビューの名前を ${resources.features.transaction_count.full_name} として参照します。これは、セットが機能ビュー transaction_count に依存していることをバンドルに伝えます。
この依存関係のため、両方が作成されると transaction_count は設定 transactions の前に作成され、両方が破棄されるとその後に削除されます。${}なしで記述された main.features_demo.transaction_count_7d のようなハードコーディングされた名前は、その依存関係を省略し、予測不可能な順序でデプロイされます。
full_name は、Unity Catalogの下で登録されるフィーチャービューに選択する3レベルの名前であり、後でクエリーする名前です。2つの名前は独立しています。
期間は、604800s(7日間の場合)のように、s接尾辞が付いた秒数です。ウィンドウ、ソース、または関数の期間の指定を参照してください。
materialized_features の各エントリは、1 つの実体化された特徴量メンバーです。つまり、1 つの特徴量ビューが 1 つの宛先に実体化されます。これらの特徴量ビューはそれぞれオフラインとオンラインの両方の宛先に実体化されるため、それぞれが 2 つの実体化された特徴量メンバーに寄与し、各メンバーは独自の Trigger を保持します。セットには 1 つのオフライン宛先と最大 1 つのオンライン宛先しかないため、両方の特徴量ビューは同じオフラインおよびオンライン宛先に書き込みます。
- YAML
- Python
resources/batch_feature.ymlを作成:
resources:
features:
transaction_count:
full_name: ${var.catalog}.${var.schema}.transaction_count_7d
description: Transactions per user over a trailing seven days
source:
delta_table_source:
full_name: ${var.source_table}
function:
aggregation_function:
count_function:
input: transaction_id
time_window:
sliding:
window_duration: 604800s
slide_duration: 86400s
entities:
- name: user_id
timeseries_column:
name: transaction_time
transaction_count_30d:
full_name: ${var.catalog}.${var.schema}.transaction_count_30d
description: Transactions per user over a trailing 30 days
source:
delta_table_source:
full_name: ${var.source_table}
function:
aggregation_function:
count_function:
input: transaction_id
time_window:
sliding:
window_duration: 2592000s
slide_duration: 86400s
entities:
- name: user_id
timeseries_column:
name: transaction_time
materialization_sets:
transactions:
materialized_features:
# Batch offline materialized feature of transaction_count.
- feature_name: ${resources.features.transaction_count.full_name}
offline_store_config:
catalog_name: ${var.catalog}
schema_name: ${var.schema}
table_name_prefix: transactions_offline
cron_schedule_trigger:
mode: DERIVED
# Batch online materialized feature of transaction_count.
- feature_name: ${resources.features.transaction_count.full_name}
online_store_config:
online_store_name: ${var.online_store}
catalog_name: ${var.catalog}
schema_name: ${var.schema}
table_name_prefix: transactions_online
cron_schedule_trigger:
mode: DERIVED
# Batch offline materialized feature of transaction_count_30d.
- feature_name: ${resources.features.transaction_count_30d.full_name}
offline_store_config:
catalog_name: ${var.catalog}
schema_name: ${var.schema}
table_name_prefix: transactions_offline
cron_schedule_trigger:
mode: DERIVED
# Batch online materialized feature of transaction_count_30d.
- feature_name: ${resources.features.transaction_count_30d.full_name}
online_store_config:
online_store_name: ${var.online_store}
catalog_name: ${var.catalog}
schema_name: ${var.schema}
table_name_prefix: transactions_online
cron_schedule_trigger:
mode: DERIVED
インポートをresources/__init__.pyに追加します。
from databricks.bundles.features import (
AggregationFunction,
CountFunction,
DataSource,
DeltaTableSource,
EntityColumn,
Feature,
Function,
SlidingWindow,
TimeWindow,
TimeseriesColumn,
)
from databricks.bundles.materialization_sets import (
CronSchedule,
CronScheduleMode,
MaterializationSet,
MaterializedFeature,
OfflineStoreConfig,
OnlineStoreConfig,
)
次に、これをload_resourcesの本文に追加します。
resources.add_feature(
'transaction_count',
Feature(
full_name='${var.catalog}.${var.schema}.transaction_count_7d',
description='Transactions per user over a trailing seven days',
source=DataSource(delta_table_source=DeltaTableSource(full_name='${var.source_table}')),
function=Function(
aggregation_function=AggregationFunction(
count_function=CountFunction(input='transaction_id'),
time_window=TimeWindow(
sliding=SlidingWindow(window_duration='604800s', slide_duration='86400s')
),
)
),
entities=[EntityColumn(name='user_id')],
timeseries_column=TimeseriesColumn(name='transaction_time'),
),
)
resources.add_feature(
'transaction_count_30d',
Feature(
full_name='${var.catalog}.${var.schema}.transaction_count_30d',
description='Transactions per user over a trailing 30 days',
source=DataSource(delta_table_source=DeltaTableSource(full_name='${var.source_table}')),
function=Function(
aggregation_function=AggregationFunction(
count_function=CountFunction(input='transaction_id'),
time_window=TimeWindow(
sliding=SlidingWindow(window_duration='2592000s', slide_duration='86400s')
),
)
),
entities=[EntityColumn(name='user_id')],
timeseries_column=TimeseriesColumn(name='transaction_time'),
),
)
resources.add_materialization_set(
'transactions',
MaterializationSet(
materialized_features=[
# Batch offline materialized feature of transaction_count.
MaterializedFeature(
feature_name='${resources.features.transaction_count.full_name}',
offline_store_config=OfflineStoreConfig(
catalog_name='${var.catalog}',
schema_name='${var.schema}',
table_name_prefix='transactions_offline',
),
cron_schedule_trigger=CronSchedule(mode=CronScheduleMode.DERIVED),
),
# Batch online materialized feature of transaction_count.
MaterializedFeature(
feature_name='${resources.features.transaction_count.full_name}',
online_store_config=OnlineStoreConfig(
online_store_name='${var.online_store}',
catalog_name='${var.catalog}',
schema_name='${var.schema}',
table_name_prefix='transactions_online',
),
cron_schedule_trigger=CronSchedule(mode=CronScheduleMode.DERIVED),
),
# Batch offline materialized feature of transaction_count_30d.
MaterializedFeature(
feature_name='${resources.features.transaction_count_30d.full_name}',
offline_store_config=OfflineStoreConfig(
catalog_name='${var.catalog}',
schema_name='${var.schema}',
table_name_prefix='transactions_offline',
),
cron_schedule_trigger=CronSchedule(mode=CronScheduleMode.DERIVED),
),
# Batch online materialized feature of transaction_count_30d.
MaterializedFeature(
feature_name='${resources.features.transaction_count_30d.full_name}',
online_store_config=OnlineStoreConfig(
online_store_name='${var.online_store}',
catalog_name='${var.catalog}',
schema_name='${var.schema}',
table_name_prefix='transactions_online',
),
cron_schedule_trigger=CronSchedule(mode=CronScheduleMode.DERIVED),
),
]
),
)
ステップ4: ストリーミング機能の追加
この機能ビューは、過去90分間のキーごとのイベントをカウントし、オンラインストアに継続的にマテリアライズします。1つの宛先に書き込むため、そのセットは単一のメンバーを宣言します。
ストリーミングマテリアライズドフィーチャーメンバーは streaming_mode を持ち、cron_schedule_trigger を持ちません。モードとその意味については、materialization_set.materialized_features.streaming_mode を参照してください。
これは、ステップ 3で定義されたセットに追加されたマテリアライズド機能ではなく、2番目のマテリアライズドセットです。マテリアライズドセットは、ストリーミングモードでマテリアライズされたフィーチャービューとバッチでマテリアライズされたフィーチャービューを混在させることができないためです。ノコギリ波ウィンドウを持つストリーミングフィーチャービューは例外です。ステップ 5のように、バッチおよびストリーミングのマテリアライズド機能は同じセットに属します。
フィーチャビューはストリームを名前で読み取ります。ストリームは、バッチフィーチャが読み取るDeltaテーブルと同じ方法で、バンドルの外部で個別に作成およびバージョン管理されます。ストリームを作成するには、「ストリームの作成」を参照してください。
ストリーミング機能ビューは、入力列を単純な列名ではなくストリームレコードへのパスとして処理するため、例で value.* が示されている場所にはストリームのスキーマが使用する名前を代入します。
- YAML
- Python
resources/streaming_feature.ymlを作成:
resources:
features:
event_count_90m:
full_name: ${var.catalog}.${var.schema}.event_count_90m
description: Events per key over a trailing 90 minutes
source:
stream_source:
full_name: ${var.stream}
function:
aggregation_function:
count_function:
input: value.amount
time_window:
rolling:
window_duration: 5400s
entities:
- name: value.key
timeseries_column:
name: value.event_timestamp
materialization_sets:
events_online:
materialized_features:
- feature_name: ${resources.features.event_count_90m.full_name}
online_store_config:
online_store_name: ${var.online_store}
catalog_name: ${var.catalog}
schema_name: ${var.schema}
table_name_prefix: event_count_90m_online
streaming_mode:
mode: STREAMING_MODE_TYPE_RTM
databricks.bundles.featuresからRollingWindowとStreamSourceを、databricks.bundles.materialization_setsからStreamingModeとStreamingModeStreamingModeTypeをインポートに追加し、これをload_resourcesに追加します。
resources.add_feature(
'event_count_90m',
Feature(
full_name='${var.catalog}.${var.schema}.event_count_90m',
description='Events per key over a trailing 90 minutes',
source=DataSource(stream_source=StreamSource(full_name='${var.stream}')),
function=Function(
aggregation_function=AggregationFunction(
count_function=CountFunction(input='value.amount'),
time_window=TimeWindow(rolling=RollingWindow(window_duration='5400s')),
)
),
entities=[EntityColumn(name='value.key')],
timeseries_column=TimeseriesColumn(name='value.event_timestamp'),
),
)
resources.add_materialization_set(
'events_online',
MaterializationSet(
materialized_features=[
MaterializedFeature(
feature_name='${resources.features.event_count_90m.full_name}',
online_store_config=OnlineStoreConfig(
online_store_name='${var.online_store}',
catalog_name='${var.catalog}',
schema_name='${var.schema}',
table_name_prefix='event_count_90m_online',
),
streaming_mode=StreamingMode(
mode=StreamingModeStreamingModeType.STREAMING_MODE_TYPE_RTM
),
)
]
),
)
ステップ5: 鋸歯状ウィンドウを持つストリーミング機能を追加する
集計に鋸歯ウィンドウを使用するストリーミングフィーチャビューをマテリアライズすると、オフラインバッチマテリアライズ機能、オンラインバッチマテリアライズ機能、オンラインストリーミングマテリアライズ機能の3つのマテリアライズ機能が生成されます。サーバーにはこれらすべてが必要であり、マテリアライズ機能のサブセットを宣言すると拒否されます。Databricksがフィーチャ定義からスケジュールを選択できるように、2つのバッチマテリアライズ機能はcron_schedule_triggerとしてDERIVEDを使用する必要があります。バッチオンラインマテリアライズ機能とストリーミングオンラインマテリアライズ機能は、同じオンラインストア構成を共有する必要があります。これらの要件を満たさないマテリアライズセットは、デプロイ時に拒否されます。完全なリストについては、マテリアライズセットが満たさなければならないルールを参照してください。
- YAML
- Python
resources/streaming_feature_sawtooth.ymlを作成:
resources:
features:
amount_sum:
full_name: ${var.catalog}.${var.schema}.amount_sum_3d
description: Sum of amount per key over a sawtooth window
source:
stream_source:
full_name: ${var.stream}
function:
aggregation_function:
sum:
input: value.amount
time_window:
sawtooth:
window_duration: 259200s
entities:
- name: value.key
timeseries_column:
name: value.event_timestamp
materialization_sets:
amounts:
materialized_features:
# Batch offline materialized feature.
- feature_name: ${resources.features.amount_sum.full_name}
offline_store_config:
catalog_name: ${var.catalog}
schema_name: ${var.schema}
table_name_prefix: amount_sum_offline
cron_schedule_trigger:
mode: DERIVED
# Batch online materialized feature.
- feature_name: ${resources.features.amount_sum.full_name}
online_store_config:
online_store_name: ${var.online_store}
catalog_name: ${var.catalog}
schema_name: ${var.schema}
table_name_prefix: amount_sum_online
cron_schedule_trigger:
mode: DERIVED
# Streaming online materialized feature.
- feature_name: ${resources.features.amount_sum.full_name}
online_store_config:
online_store_name: ${var.online_store}
catalog_name: ${var.catalog}
schema_name: ${var.schema}
table_name_prefix: amount_sum_online
streaming_mode:
mode: STREAMING_MODE_TYPE_RTM
databricks.bundles.featuresからのインポートにSawtoothWindowとSumFunctionを追加し、これをload_resourcesに追加します:
resources.add_feature(
'amount_sum',
Feature(
full_name='${var.catalog}.${var.schema}.amount_sum_3d',
description='Sum of amount per key over a sawtooth window',
source=DataSource(stream_source=StreamSource(full_name='${var.stream}')),
function=Function(
aggregation_function=AggregationFunction(
sum=SumFunction(input='value.amount'),
time_window=TimeWindow(sawtooth=SawtoothWindow(window_duration='259200s')),
)
),
entities=[EntityColumn(name='value.key')],
timeseries_column=TimeseriesColumn(name='value.event_timestamp'),
),
)
resources.add_materialization_set(
'amounts',
MaterializationSet(
materialized_features=[
# Batch offline materialized feature.
MaterializedFeature(
feature_name='${resources.features.amount_sum.full_name}',
offline_store_config=OfflineStoreConfig(
catalog_name='${var.catalog}',
schema_name='${var.schema}',
table_name_prefix='amount_sum_offline',
),
cron_schedule_trigger=CronSchedule(mode=CronScheduleMode.DERIVED),
),
# Batch online materialized feature.
MaterializedFeature(
feature_name='${resources.features.amount_sum.full_name}',
online_store_config=OnlineStoreConfig(
online_store_name='${var.online_store}',
catalog_name='${var.catalog}',
schema_name='${var.schema}',
table_name_prefix='amount_sum_online',
),
cron_schedule_trigger=CronSchedule(mode=CronScheduleMode.DERIVED),
),
# Streaming online materialized feature.
MaterializedFeature(
feature_name='${resources.features.amount_sum.full_name}',
online_store_config=OnlineStoreConfig(
online_store_name='${var.online_store}',
catalog_name='${var.catalog}',
schema_name='${var.schema}',
table_name_prefix='amount_sum_online',
),
streaming_mode=StreamingMode(
mode=StreamingModeStreamingModeType.STREAMING_MODE_TYPE_RTM
),
),
]
),
)
ステップ 6: 検証とプランニング
databricks.ymlとバンドルが読み込むすべてのリソースファイルを読み取る構成を確認します:
databricks bundle validate
validate また、フィールドが受け入れられるかどうかを知るための最も安価な方法でもあります。バンドルが認識しないフィールドの名前を、パス、ファイル、およびそのファイルからの行とともに指定します:
Warning: unknown field: bogus_field
at resources.features.transaction_count.function.aggregation_function.time_window.sliding
in resources/batch_feature.yml:16:15
認識されないフィールドは警告として報告され、その値はドロップされるため、終了コードだけでなく出力も読み取ってください。警告をエラーとして扱うには、--strict を渡します。各ウィンドウ、関数、ソースが受け入れるフィールドについては、「機能」を参照してください。
サーバーによって適用されるルール(のこぎり歯ウィンドウを持つFeature Viewでは、3つすべてのマテリアライズドフィーチャーを宣言する必要があるというルールなど)は、ここではチェックされず、databricks bundle deployに表示されます。
デプロイメントをランする前に、その内容を確認します。
databricks bundle plan
初回のデプロイでは、7つすべてのリソース(Feature View 4つとマテリアライゼーションセット3つ)が create を報告します:
create features.amount_sum
create features.event_count_90m
create features.transaction_count
create features.transaction_count_30d
create materialization_sets.amounts
create materialization_sets.events_online
create materialization_sets.transactions
Plan: 7 to add, 0 to change, 0 to delete, 0 unchanged
後続のすべての変更に対しても plan をランし、計画されているアクションを確認します。
ステップ7:デプロイする
バンドルをワークスペースにデプロイする:
databricks bundle deploy
デプロイは、各リソースを作成する際にレポートします。
Uploading bundle files to /Workspace/Users/someone@example.com/.bundle/feature-store-quickstart/default/files...
Created features.transaction_count_30d
Created features.transaction_count
Created features.amount_sum
Created features.event_count_90m
Created materialization_sets.transactions
Created materialization_sets.events_online
Created materialization_sets.amounts
Files: 4 uploaded, 0 deleted
Resources: 7 created, 0 changed, 0 deleted, 0 unchanged
ステップ8: 作成されたものを確認する
databricks bundle summary -o json 最後のデプロイ時に記録されたマテリアライゼーションセットIDなどのリソース識別子を使用して、バンドル設定をレポートします。ステップ5で定義したマテリアライゼーションセットの場合:
{
"id": "1234567890abcdef1234567890abcdef",
"materialized_features": [
{
"cron_schedule_trigger": {
"mode": "DERIVED"
},
"feature_name": "${resources.features.amount_sum.full_name}",
"offline_store_config": {
"catalog_name": "main",
"schema_name": "features_demo",
"table_name_prefix": "amount_sum_offline"
}
},
{
"cron_schedule_trigger": {
"mode": "DERIVED"
},
"feature_name": "${resources.features.amount_sum.full_name}",
"online_store_config": {
"catalog_name": "main",
"online_store_name": "my_online_store",
"schema_name": "features_demo",
"table_name_prefix": "amount_sum_online"
}
},
{
"feature_name": "${resources.features.amount_sum.full_name}",
"online_store_config": {
"catalog_name": "main",
"online_store_name": "my_online_store",
"schema_name": "features_demo",
"table_name_prefix": "amount_sum_online"
},
"streaming_mode": {
"mode": "STREAMING_MODE_TYPE_RTM"
}
}
]
}
サーバーに何が保存されているかを確認するには、 databricks bundle summary 出力からの id を使用して、Feature エンジニアリングコマンドでセットを読み取ります。
databricks feature-engineering get-materialization-set <materialization-set-id>
応答には、サーバーが同じセットに対して保存した内容が含まれます。これにはサーバーが生成するフィールドも含まれます:
{
"materialization_set_id": "1234567890abcdef1234567890abcdef",
"materialized_features": [
{
"cron_schedule_trigger": {
"cron_expression": "0 0 2 * * ?",
"mode": "DERIVED",
"timezone_id": "UTC"
},
"feature_name": "main.features_demo.amount_sum_3d",
"is_online": true,
"job_id": 123456789012345,
"materialization_set_id": "1234567890abcdef1234567890abcdef",
"materialized_feature_id": "22222222222222222222222222222222",
"online_store_config": {
"catalog_name": "",
"online_store_name": "my_online_store",
"schema_name": "",
"table_name_prefix": ""
},
"pipeline_schedule_state": "ACTIVE",
"table_name": "main.features_demo.amount_sum_online_ceq88t"
},
{
"feature_name": "main.features_demo.amount_sum_3d",
"is_online": true,
"job_id": 234567890123456,
"materialization_set_id": "1234567890abcdef1234567890abcdef",
"materialized_feature_id": "33333333333333333333333333333333",
"online_store_config": {
"catalog_name": "",
"online_store_name": "my_online_store",
"schema_name": "",
"table_name_prefix": ""
},
"pipeline_id": "12345678-1234-1234-1234-123456789012",
"pipeline_schedule_state": "ACTIVE",
"streaming_mode": {
"mode": "STREAMING_MODE_TYPE_RTM"
},
"table_name": "main.features_demo.amount_sum_online_qiohun"
},
{
"cron_schedule_trigger": {
"cron_expression": "0 0 2 * * ?",
"mode": "DERIVED",
"timezone_id": "UTC"
},
"feature_name": "main.features_demo.amount_sum_3d",
"is_online": false,
"job_id": 123456789012345,
"materialization_set_id": "1234567890abcdef1234567890abcdef",
"materialized_feature_id": "11111111111111111111111111111111",
"pipeline_schedule_state": "ACTIVE",
"table_name": "main.features_demo.amount_sum_offline_ceq88t"
}
]
}
ステップ 9: 構成を変更する
以下の例では、前のステップからフィーチャービューとマテリアライズドセットを変更し、各変更がデプロイメントで何を行うかを示しています。例で異なる起動点が指定されていない限り、それぞれはステップ 7のデプロイメントから起動します。それぞれは、リソースを宣言するファイルへの編集、またはすべてを1つのファイルで宣言した場合はdatabricks.ymlのresourcesマッピングへの編集です。Python tabでは、編集内容はresources/__init__.pyに入ります。どの変更が所定の位置に適用され、どれがリソースを置換し、どれが拒否されるかについては、フィーチャビューの変更およびマテリアライゼーションセットの変更を参照してください。
フィーチャテーブルの具現化済みフィーチャをすべて削除する
マテリアライズ・セットから 1 つの特徴量ビューのすべてのマテリアライズされた特徴量を削除することはインプレースで適用されるため、特徴量データは再計算されません。マテリアライズ・セットの変更を参照してください。
以下は、ステップ3で定義された特徴量ビュー transaction_count と transaction_count_30d のセット transactions を取得し、特徴量ビュー transaction_count_30d のすべてのマテリアライズド特徴量を削除します。同じセット内のtransaction_countのマテリアライズド特徴量はそのままです。
- YAML
- Python
materialization_sets:
transactions:
materialized_features:
# Batch offline materialized feature of transaction_count.
- feature_name: ${resources.features.transaction_count.full_name}
offline_store_config: # As in Step 3.
cron_schedule_trigger:
mode: DERIVED
# Batch online materialized feature of transaction_count.
- feature_name: ${resources.features.transaction_count.full_name}
online_store_config: # As in Step 3.
cron_schedule_trigger:
mode: DERIVED
- # Batch offline materialized feature of transaction_count_30d.
- - feature_name: ${resources.features.transaction_count_30d.full_name}
- offline_store_config: # As in Step 3.
- cron_schedule_trigger:
- mode: DERIVED
- # Batch online materialized feature of transaction_count_30d.
- - feature_name: ${resources.features.transaction_count_30d.full_name}
- online_store_config: # As in Step 3.
- cron_schedule_trigger:
- mode: DERIVED
resources.add_materialization_set(
'transactions',
MaterializationSet(
materialized_features=[
# Batch offline materialized feature of transaction_count.
MaterializedFeature(...), # As in Step 3.
# Batch online materialized feature of transaction_count.
MaterializedFeature(...), # As in Step 3.
- # Batch offline materialized feature of transaction_count_30d.
- MaterializedFeature(...), # As in Step 3.
- # Batch online materialized feature of transaction_count_30d.
- MaterializedFeature(...), # As in Step 3.
]
),
)
databricks bundle plan セットを更新として報告します:
update materialization_sets.transactions
Plan: 0 to add, 1 to change, 0 to delete, 6 unchanged
Feature Viewの変更不可フィールドを変更する
マテリアライズドセットがFeature Viewに依存している場合、Feature Viewの不変フィールドを変更するとデプロイが失敗します。Feature Viewを置き換えると最初にそれが削除されますが、Feature Viewにマテリアライズされた機能がある間は削除が拒否されます。どのフィールドが不変か、および変更を推奨する方法については、Feature Viewの変更を参照してください。
次は、ステップ3で定義された特徴ビュー transaction_count を取得し、不変フィールドであるスライディングウィンドウの期間を広げます:
- YAML
- Python
features:
transaction_count:
# The other keys, as in Step 3.
function:
aggregation_function:
count_function:
input: transaction_id
time_window:
sliding:
- window_duration: 604800s
+ window_duration: 1209600s
slide_duration: 86400s
resources.add_feature(
'transaction_count',
Feature(
# The other arguments, as in Step 3.
function=Function(
aggregation_function=AggregationFunction(
count_function=CountFunction(input='transaction_id'),
time_window=TimeWindow(
- sliding=SlidingWindow(window_duration='604800s', slide_duration='86400s')
+ sliding=SlidingWindow(window_duration='1209600s', slide_duration='86400s')
),
)
),
),
)
databricks bundle plan 再作成を報告します:
recreate features.transaction_count
Plan: 1 to add, 0 to change, 1 to delete, 6 unchanged
databricks bundle deploy 確認を求め、そのメッセージで、変更が記述通りに実行できない理由が説明されます:
This action will result in the deletion or recreation of the following Feature Views.
A Feature View that has materialized features in a materialization set cannot be deleted or
recreated. Remove its materialized features from the set in a separate deploy first, then delete
or recreate the Feature View. Deleting or recreating a Feature View that a FeatureSpec serves is
not blocked, and leaves the FeatureSpec stale:
recreate resources.features.transaction_count
承認すると、セット transactions にはまだフィーチャビューの2つのマテリアライズドフィーチャが保持されているため、デプロイは失敗します。
Error: cannot recreate resources.features.transaction_count: deleting old id=main.features_demo.transaction_count_7d: Cannot delete feature 'main.features_demo.transaction_count_7d' because it has 2 materialized feature(s). Delete all materialized features first before deleting the feature. (400 BAD_REQUEST)
変更を行うには、特徴量ビューの変更で説明されているように、2 回デプロイします:
-
Feature View のマテリアライズされた特徴量をセットから削除し、デプロイします。セットは、「 Feature View のすべてのマテリアライズされた特徴量を削除する」と同様に、インプレースで更新されます。
-
特徴量ビューを変更し、マテリアライズド特徴量をセットに戻してデプロイします。プランは変更されたウィンドウの特徴量ビューを再作成し、セットを再作成します。マテリアライズド特徴量をセットに追加するとセットが置換されるためです。
TextWarn: planning resources.materialization_sets.transactions: the member for feature "main.features_demo.transaction_count_7d" is not in the deployed set, and members cannot be added to an existing set, so the whole set will be recreated: every member is dropped and recomputedWarn: planning resources.materialization_sets.transactions: the member for feature "main.features_demo.transaction_count_7d" is not in the deployed set, and members cannot be added to an existing set, so the whole set will be recreated: every member is dropped and recomputedrecreate features.transaction_countrecreate materialization_sets.transactionsPlan: 2 to add, 0 to change, 2 to delete, 5 unchanged承認後、デプロイによってFeature Viewとセットが再作成されます。
TextRecreated features.transaction_countRecreated materialization_sets.transactionsFiles: 3 uploaded, 0 deletedResources: 2 created, 0 changed, 2 deleted, 5 unchanged
マテリアライゼーションセットの不変フィールドの変更
セット内のマテリアライズド特徴量のフィールドを変更すると、編集が影響しないマテリアライズド特徴量を含め、マテリアライズドセット全体が置き換わります。マテリアライズドセットの変更を参照してください。
次は、 ステップ3 で定義されたセット transactions を取得し、不変であるオンライン送信先の table_name_prefix を変更します。セットには1つのオンライン送信先があるため、両方のオンラインマテリアライズド機能にはプレフィックスが付いています。
- YAML
- Python
materialization_sets:
transactions:
materialized_features:
# Batch offline materialized feature of transaction_count.
- feature_name: ${resources.features.transaction_count.full_name}
offline_store_config: # As in Step 3.
cron_schedule_trigger:
mode: DERIVED
# Batch online materialized feature of transaction_count.
- feature_name: ${resources.features.transaction_count.full_name}
online_store_config:
online_store_name: ${var.online_store}
catalog_name: ${var.catalog}
schema_name: ${var.schema}
- table_name_prefix: transactions_online
+ table_name_prefix: transactions_online_v2
cron_schedule_trigger:
mode: DERIVED
# Batch offline materialized feature of transaction_count_30d.
- feature_name: ${resources.features.transaction_count_30d.full_name}
offline_store_config: # As in Step 3.
cron_schedule_trigger:
mode: DERIVED
# Batch online materialized feature of transaction_count_30d.
- feature_name: ${resources.features.transaction_count_30d.full_name}
online_store_config:
online_store_name: ${var.online_store}
catalog_name: ${var.catalog}
schema_name: ${var.schema}
- table_name_prefix: transactions_online
+ table_name_prefix: transactions_online_v2
cron_schedule_trigger:
mode: DERIVED
resources.add_materialization_set(
'transactions',
MaterializationSet(
materialized_features=[
# Batch offline materialized feature of transaction_count.
MaterializedFeature(...), # As in Step 3.
# Batch online materialized feature of transaction_count.
MaterializedFeature(
feature_name='${resources.features.transaction_count.full_name}',
online_store_config=OnlineStoreConfig(
online_store_name='${var.online_store}',
catalog_name='${var.catalog}',
schema_name='${var.schema}',
- table_name_prefix='transactions_online',
+ table_name_prefix='transactions_online_v2',
),
cron_schedule_trigger=CronSchedule(mode=CronScheduleMode.DERIVED),
),
# Batch offline materialized feature of transaction_count_30d.
MaterializedFeature(...), # As in Step 3.
# Batch online materialized feature of transaction_count_30d.
MaterializedFeature(
feature_name='${resources.features.transaction_count_30d.full_name}',
online_store_config=OnlineStoreConfig(
online_store_name='${var.online_store}',
catalog_name='${var.catalog}',
schema_name='${var.schema}',
- table_name_prefix='transactions_online',
+ table_name_prefix='transactions_online_v2',
),
cron_schedule_trigger=CronSchedule(mode=CronScheduleMode.DERIVED),
),
]
),
)
databricks bundle plan セットの再作成が報告されるため、その2つのバッチオフラインマテリアライズド特徴量も削除され、再計算されます。
recreate materialization_sets.transactions
Plan: 1 to add, 0 to change, 1 to delete, 6 unchanged
既存のセットにマテリアライズ済み特徴量を加える
既にデプロイされているマテリアライゼーションセットにマテリアライズド機能を追加すると、そのセットが置き換えられ、セット内のすべてのマテリアライズド機能が再計算されます。マテリアライゼーションセットの変更を参照してください。
次は、機能ビューの具体化されたすべての機能を削除するで機能ビュー transaction_count_30d のすべての具体化された機能を削除した後のセット transactions を取得し、機能ビュー transaction_count_30d の具体化された機能を戻します:
- YAML
- Python
materialization_sets:
transactions:
materialized_features:
# Batch offline materialized feature of transaction_count.
- feature_name: ${resources.features.transaction_count.full_name}
offline_store_config: # As in Step 3.
cron_schedule_trigger:
mode: DERIVED
# Batch online materialized feature of transaction_count.
- feature_name: ${resources.features.transaction_count.full_name}
online_store_config: # As in Step 3.
cron_schedule_trigger:
mode: DERIVED
+ # Batch offline materialized feature of transaction_count_30d.
+ - feature_name: ${resources.features.transaction_count_30d.full_name}
+ offline_store_config: # As in Step 3.
+ cron_schedule_trigger:
+ mode: DERIVED
+ # Batch online materialized feature of transaction_count_30d.
+ - feature_name: ${resources.features.transaction_count_30d.full_name}
+ online_store_config: # As in Step 3.
+ cron_schedule_trigger:
+ mode: DERIVED
resources.add_materialization_set(
'transactions',
MaterializationSet(
materialized_features=[
# Batch offline materialized feature of transaction_count.
MaterializedFeature(...), # As in Step 3.
# Batch online materialized feature of transaction_count.
MaterializedFeature(...), # As in Step 3.
+ # Batch offline materialized feature of transaction_count_30d.
+ MaterializedFeature(...), # As in Step 3.
+ # Batch online materialized feature of transaction_count_30d.
+ MaterializedFeature(...), # As in Step 3.
]
),
)
databricks bundle plan 追加された各マテリアライズド機能について警告し、再作成を報告します。
Warn: planning resources.materialization_sets.transactions: the member for feature "main.features_demo.transaction_count_30d" is not in the deployed set, and members cannot be added to an existing set, so the whole set will be recreated: every member is dropped and recomputed
Warn: planning resources.materialization_sets.transactions: the member for feature "main.features_demo.transaction_count_30d" is not in the deployed set, and members cannot be added to an existing set, so the whole set will be recreated: every member is dropped and recomputed
recreate materialization_sets.transactions
Plan: 1 to add, 0 to change, 1 to delete, 6 unchanged
databricks bundle deploy セットを再作成する前に確認を求めます:
This action will result in the deletion or recreation of the following materialization sets.
Every materialized feature in a recreated set is dropped and recomputed from scratch, including
the members whose configuration did not change:
recreate resources.materialization_sets.transactions
特徴ビューの実体化された特徴の一部を削除する
マテリアライゼーションセットから機能ビューのマテリアライズされた機能の一部 (すべてではない) を削除することは拒否されます。マテリアライゼーションセットの変更を参照してください。
以下では、鋸歯状ウィンドウを持つFeature View amount_sumについて、ステップ5で定義されたセットamountsを取得し、そのバッチ・オフライン・マテリアライズド機能のみを削除します:
- YAML
- Python
materialization_sets:
amounts:
materialized_features:
- # Batch offline materialized feature.
- - feature_name: ${resources.features.amount_sum.full_name}
- offline_store_config: # As in Step 5.
- cron_schedule_trigger:
- mode: DERIVED
# Batch online materialized feature.
- feature_name: ${resources.features.amount_sum.full_name}
online_store_config: # As in Step 5.
cron_schedule_trigger:
mode: DERIVED
# Streaming online materialized feature.
- feature_name: ${resources.features.amount_sum.full_name}
online_store_config: # As in Step 5.
streaming_mode:
mode: STREAMING_MODE_TYPE_RTM
resources.add_materialization_set(
'amounts',
MaterializationSet(
materialized_features=[
- # Batch offline materialized feature.
- MaterializedFeature(...), # As in Step 5.
# Batch online materialized feature.
MaterializedFeature(...), # As in Step 5.
# Streaming online materialized feature.
MaterializedFeature(...), # As in Step 5.
]
),
)
この編集によってamount_sumのバッチオフラインマテリアライズドフィーチャが削除され、その削除によって同じフィーチャビューの他の2つのマテリアライズドフィーチャも削除されますが、この編集はそのような削除を要求していません。デプロイメントが拒否されました:
Error: cannot update resources.materialization_sets.amounts: updating id=1234567890abcdef1234567890abcdef: Deleting materialized features '11111111111111111111111111111111' of feature 'main.features_demo.amount_sum_3d' also deletes materialized features '22222222222222222222222222222222', '33333333333333333333333333333333', which the request does not delete. Delete the unrequested materialized features as well. (400 INVALID_PARAMETER_VALUE)
ステップ 10: クリーンアップ
マテリアライゼーションパイプラインは、セットが削除されるまで、構成されたスケジュールに従って実行され続けます。完了したら、バンドルを削除します。
databricks bundle destroy
これにより、バンドルに含まれるすべてのファイルで宣言されているマテリアライゼーションセットと特徴量ビューが削除されます。マテリアライズド特徴量の背後にあるテーブル、パイプライン、ジョブは、それらを共有する最後のマテリアライズド特徴量がなくなった後にバックグラウンドプロセスによって削除されるため、関連するコストが停止するまでに少し遅延があります。マテリアライズド特徴量を作成したユーザーのみが削除できるため、バンドルをデプロイしたのと同じIDとして databricks bundle destroy をランしてください。delete_materialized_feature()を参照してください。
具体化のコストとその割り当て方法については、Feature Store のコスト管理をご覧ください。
制限
- ストリームはバンドルリソースではありません。バンドルの外部に作成し、名前で参照してください。
- 既存のマテリアライゼーション・セットにマテリアライズド・フィーチャを追加すると、セットが再作成されるため、そのセット内のすべてのマテリアライズド・フィーチャが再計算されます。
request_sourceまたはfeature_view_source上の特徴量ビュー、あるいはcustom_udf関数を使用する特徴量ビューは、マテリアライズできません。特徴量ビューのマテリアライズを参照してください。
次のステップ
- CI/CDワークフローからこれらのリソースをデプロイする方法については、「 GitHub Actionsを使用したフィーチャービューのCI/CD」を参照してください。
- バンドルからこれらの機能を配信する方法については、 宣言型オートメーションバンドルを使用して機能ビューを配信するを参照してください。Python APIを使用して配信する方法については、 機能ビューを配信すると 例:Feature Serving Endpointをデプロイおよびクエリーするを参照してください。
- それらのモデルをトレーニングするには、フィーチャービューでモデルをトレーニングするを参照してください。
- 完全な設定リファレンスについては、featureおよびmaterialization_setを参照してください。
- マテリアライゼーションがどのように機能するかを学習するには、マテリアライズド特徴量ビューを参照してください。