Important
이 기능은 비공개 프리뷰. 이를 시도하려면 Azure Databricks 연락처에 문의하세요.
선언적 자동화 번들(이전 명칭: Databricks Asset Bundles)은 기능 뷰와 이를 구현하는 파이프라인과 같은 Azure Databricks 리소스를 프로그래밍 방식으로 검증, 배포 및 실행할 수 있게 해줍니다. 선언적 자동화 번들이란 무엇인가?를 참조하세요.
이 튜토리얼은 네 가지 Feature Views를 선언하고 세 가지 방식으로 머티리얼라이즈하는 번들을 만듭니다: 오프라인과 온라인 스토어 모두에 저장되는 두 개의 일괄 기능, 온라인 스토어에 지속적으로 저장되는 스트리밍 기능, 그리고 sawtooth window가 있는 스트리밍 기능으로, 일괄 모드에서는 오프라인 및 온라인 스토어에, 스트리밍 모드에서는 온라인 스토어에 머티리얼라이즈됩니다. 그 다음 구성을 변경하고, 재배포한 뒤 모든 것을 정리합니다.
번들에서 기능을 선언하면 배포하는 모든 작업 공간에서 동일한 정의가 제공되며, 프로젝트의 나머지 부분과 함께 소스로 검토됩니다. 이는 노트북에서 create_feature 및 materialize_features를 호출하는 것의 선언적 대안입니다.
기능 보기를 참조하세요.
각 단계마다 YAML과 Python 모두로 구성된 구성이 표시됩니다. 언어를 선택하면 페이지가 그 선택에 따라 변경됩니다.
Requirements
- Databricks CLI 버전 1.24.0 이상입니다. 실행
databricks --version하여 확인합니다. Databricks CLI 설치 또는 업데이트를 참조하세요. - 직접 배포 엔진.
features및materialization_sets리소스는 Terraform 배포 엔진에서 지원되지 않습니다. 리소스 호환성을 참조하세요. - Unity 카탈로그 사용 작업 영역입니다. 요구 사항을 참조하세요.
- 피처를 생성하고 실체화할 수 있는 권한. 사용 권한을 참조하세요.
- 기존 온라인 스토어. 온라인 상점 만들기를 참조하세요.
- 배치 구체화를 위한 엔티티 열과 타임스탬프 열이 있는 기존 Delta 테이블입니다. Azure Databricks 테이블을 참조하세요.
- 스트림 구체화를 위한 기존 스트림. 스트림 만들기를 참조하세요.
소스 테이블과 스트림은 각각 고유한 라이프사이클을 가지며, 둘 다 번들 리소스가 아닙니다. 먼저 생성한 후 번들 내에서 이름으로 참조하는데, 3단계에서 테이블을, 4단계에서 스트림을 참조합니다.
번들 내 기능 스토어 리소스
이 튜토리얼에서는 두 가지 피처 스토어 리소스 유형을 선언하며, 이들 간의 차이가 배포 비용을 결정합니다.
- Feature View: 기능의 정의로, 그 출처, 집계 및 키를 포괄합니다. 가벼운 메타데이터입니다. Feature Views를 참조하고, 구성 참조는 feature를 참조하세요.
- 머티리얼라이제이션 세트: 머티리얼라이즈된 피처들의 집합. 구체화된 피처는 파이프라인이나 작업을 통해 테이블로 계산된 하나의 피처 뷰로, 이것이 더 무거운 쪽입니다. 구체화된 특징들을 하나의 집합으로 묶으면 Azure Databricks가 함께 계산할 수 있음을 알려주며, 이를 담는 가장 적은 테이블과 Lakeflow 파이프라인에 압축합니다. Materialize Feature Views를 참조하고, 구성 참조는 materialization_set 및 materialization_set.materialized_features를 참조하십시오.
다음 단계에는 일괄 기능을 선언하는 단계, 스트리밍 기능, 톱니 창이 있는 스트리밍 기능이 포함됩니다. 프로젝트에 필요한 것만 선언하세요. 구체화 작동 방식에 대해서는 피처 뷰 구체화를 참조하세요.
1단계: 인증 설정
먼저, 개발 머신의 Databricks CLI와 Azure Databricks 작업 공간 간의 인증을 설정하세요. 이 페이지에서는 OAuth U2M(사용자-컴퓨터) 인증 및 인증을 위해 명명된 DEFAULT 해당 Azure Databricks 구성 프로필을 사용하려는 것으로 가정합니다.
Note
U2M 인증은 이러한 단계를 실시간으로 시도하는 데 적합합니다. 완전히 자동화된 워크플로의 경우 Databricks는 OAuth M2M(컴퓨터 간) 인증을 대신 사용하는 것이 좋습니다. OAuth를 사용하여 Azure Databricks에 대한 서비스 주체 액세스 권한 부여의 M2M 인증 설정 지침을 참조하세요.
Databricks CLI를 사용하여 각 대상 작업 영역에 대해 다음 명령을 실행하여 OAuth 토큰 관리를 로컬로 시작합니다.
다음 명령에서
<workspace-url>를 Azure Databricks 작업공간별 URL로 바꾸십시오. 예를 들면 다음과 같습니다https://adb-1234567890123456.7.azuredatabricks.net.databricks auth login --host <workspace-url>Databricks CLI는 Azure Databricks 구성 프로필로 입력한 정보를 저장하라는 메시지를 표시합니다.
Enter를 눌러 제안된 프로필 이름을 수락하거나 새 프로필 또는 기존 프로필의 이름을 입력합니다. 이름이 같은 기존 프로필은 입력한 정보로 덮어쓰여집니다. 프로필을 사용하여 여러 작업 영역에서 인증 컨텍스트를 빠르게 전환할 수 있습니다.기존 프로필 목록을 얻으려면 별도의 터미널 또는 명령 프롬프트에서 Databricks CLI를 사용하여
databricks auth profiles명령을 실행합니다. 특정 프로필의 기존 설정을 보려면 명령을databricks auth env --profile <profile-name>실행합니다.웹 브라우저에서 화면상의 지침을 완료하여 Azure Databricks 작업 영역에 로그인합니다.
프로필의 현재 OAuth 토큰 값과 토큰의 예정된 만료 타임스탬프를 보려면 다음 명령 중 하나를 실행합니다.
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
다음 각 단계는 번들 리소스를 선언하기 위해 resources/ 아래에 파일 하나를 추가합니다:
databricks.yml
resources/
batch_feature.yml
streaming_feature.yml
streaming_feature_sawtooth.yml
databricks.yml 세 가지를 포함합니다:
- 번들 이름.
-
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에서 모든 것을 선언하는 것도 가능합니다.
resources를 생략하고 각 단계의 선언을 하나의 include 매핑 아래에 모으세요:
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
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
resources/__init__.py에서 이름을 지정한 함수로 databricks.yml를 생성하세요:
from databricks.bundles.core import Bundle, Resources
def load_resources(bundle: Bundle) -> Resources:
resources = Resources()
# The following steps add resources here.
return resources
프로젝트 템플릿과 뮤테이터를 포함한 Python에서 번들 작성에 대한 자세한 내용은 Python에서의 번들 구성을 참조하세요.
3단계: 배치 기능 추가
이 두 가지 Feature View는 사용자별 거래 수를 최근 7일 및 30일 기준으로 집계하며, 둘 다 매일 재계산되고 오프라인 스토어와 온라인 스토어에 함께 구체화되어 저장됩니다.
Feature View 자체는 단지 정의일 뿐입니다. 머티리얼라이제이션 세트가 바로 그것으로부터 데이터를 생성하는 것입니다.
각 자원에는 두 개의 이름이 붙습니다.
transaction_count는 리소스 키입니다. 즉, 사용자가 선택하는 이름으로 번들 내에서 고유하며, databricks bundle 명령이 리소스를 지정하는 데 사용하고 다른 구성에서 참조하는 이름입니다. 예를 들어, 집합 transactions 내 두 개의 물질화된 피처 transaction_count 는 피처 뷰의 이름을 ${resources.features.transaction_count.full_name}로 참조하는데, 이는 집합이 피처 뷰transaction_count에 의존한다는 것을 번들에 알려줍니다.
이러한 의존성 때문에, 둘 다 생성될 때 transaction_count가 집합 transactions보다 먼저 생성되고, 둘 다 삭제될 때는 transactions가 삭제된 후 transaction_count가 삭제됩니다. 하드코딩된 이름 main.features_demo.transaction_count_7d처럼 ${} 없이 작성되면 그 의존성이 생략되고 예측 불가능한 순서로 배포됩니다.
full_name Unity 카탈로그에 등록할 기능 뷰를 위해 선택한 3단계 이름이며, 나중에 쿼리할 이름입니다. 두 이름은 서로 독립적입니다.
지속 시간은 s 접미사가 붙은 초 수이며, 예를 들어 604800s 는 7일을 나타냅니다.
창, 소스 또는 함수의 지속 시간 지정을 참조하세요.
각 materialized_features 항목은 하나의 물리화된 피처 멤버로, 하나의 피처 뷰가 하나의 목적지에 구체화됩니다. 각 기능 뷰는 오프라인과 온라인 목적지 모두에 구현되므로, 각각 두 개의 특성화된 기능 멤버를 기여하며, 각 멤버는 고유한 트리거를 가지고 있습니다. 두 기능 뷰는 동일한 오프라인 및 온라인 목적지에 쓰기 기능을 수행하는데, 이는 세트가 하나의 오프라인 목적지와 최대 하나의 온라인 목적지를 가지고 있기 때문입니다.
YAML
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
Python
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단계: 스트리밍 기능 추가
이 Feature View는 지난 90분 동안 키별 이벤트를 집계하며 온라인 스토어에 지속적으로 반영됩니다. 하나의 목적지에 쓰기 때문에, 그 집합은 단일 멤버를 선언합니다.
스트리밍 물질화된 기능 멤버는 streaming_mode를 가지며 cron_schedule_trigger는 없습니다. 모드와 각 모드가 의미하는 바에 대해서는 materialization_set.materialized_features.streaming_mode를 참조하세요.
이는 3단계에서 정의한 세트에 추가된 물질화된 피처가 아니라 두 번째 물질화 세트입니다. 물질화 세트는 스트리밍 모드에서 물질화된 피처 뷰와 배치에서 물질화된 피처 뷰를 혼합할 수 없기 때문입니다. 톱니 윈도우가 있는 스트리밍 Feature View는 예외입니다. 배치 피처와 스트리밍 물질화된 피처는 5단계와 마찬가지로 동일한 세트에 속합니다.
Feature View는 이름으로 Stream을 읽습니다. 스트림은 번들 외부에서 단독으로 생성되고 버전 관리되며, 이는 배치 기능이 읽는 델타 테이블과 동일한 방식입니다. 스트림을 만들려면 스트림 만들기를 참조하세요.
스트리밍 기능 뷰는 입력 열을 단순 열 이름이 아닌 스트림 레코드로 들어가는 경로로 처리하므로, 예시에서 표시된 value.*곳에서는 스트림 스키마가 사용하는 이름으로 대체하세요.
YAML
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
Python
StreamSource에서 가져오는 import에 RollingWindow 및 databricks.bundles.features를 추가하고, databricks.bundles.materialization_sets에서 가져오는 import에 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단계: 톱니형 윈도우가 있는 스트리밍 피처 추가
sawtooth 창을 사용해 집계한 스트리밍 피처 뷰를 구체화하면 세 가지 구체화된 피처가 생성됩니다: 오프라인 배치 구체화된 피처, 온라인 배치 구체화된 피처, 그리고 온라인 스트리밍 구체화된 피처. 서버는 세 가지 모두를 요구하며, 구체화된 피처의 일부를 선언하는 것은 거부됩니다. 두 개의 배치 구체화된 기능은 DERIVED를 cron_schedule_trigger(으)로 사용해야 하며, 그래야 Azure Databricks가 기능 정의에서 일정을 선택합니다. 일괄 온라인 구체화 기능과 스트리밍 온라인 구체화 기능은 동일한 온라인 스토어 구성을 공유해야 합니다. 이러한 요구 사항을 충족하지 않는 머티리얼라이제이션 세트는 배포 시 거부됩니다. 전체 목록은 '물질화 집합이 충족해야 하는 규칙'을 참조하세요.
YAML
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
Python
SumFunction에서 가져오는 import에 databricks.bundles.features와 SawtoothWindow를 추가한 다음, 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를 참조하세요.
톱니바 창을 가진 피처 뷰가 세 가지 구체화된 피처를 모두 선언해야 한다는 규칙과 같이 서버가 강제하는 규칙은 여기서 체크되지 않고 표면 databricks bundle deploy화됩니다.
그런 다음 배포가 실행되기 전에 수행하는 작업을 검토하세요:
databricks bundle plan
첫 배포 시 7개 리소스(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 마지막 배포 시 기록된 자원 식별자(예: materialization set 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"
}
}
]
}
서버에 저장된 내용을 보려면 id 출력의 databricks bundle summary를 사용하여 Feature Engineering 명령어로 세트를 다시 읽으세요:
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단계: 구성 변경
다음 예제들은 이전 단계의 Feature Views와 머티리얼라이제이션 세트를 변경하고, 각 변경 사항이 배포 시 어떤 효과를 가져오는지 보여줍니다. 예시에서 다른 시작 지점을 언급하지 않는 한, 각 예시는 7단계의 배포 시점부터 시작합니다. 각 수정은 리소스를 선언하는 파일에 대한 편집이거나, 모든 것을 한 파일에 선언했다면 매핑 databricks.yml 에 resources 대한 편집입니다. Python 탭에서 편집 내용은 resources/__init__.py에 들어갑니다. 어떤 변경 사항이 현장에서 적용되는지, 어떤 변경 사항이 리소스를 대체하며, 어떤 변경이 거부되는지는 '피처 뷰 변경' 및 '물질화 세트 변경'을 참조하세요.
피처 뷰의 모든 구체화된 피처 제거하기
하나의 피처 뷰에서 모든 구체화된 피처를 구체화 세트에서 제거하므로, 피처 데이터는 재계산되지 않습니다. ' 물질화 세트 변경'을 참조하세요.
다음은 transaction_count에서 정의된 집합 을 가져와 피처 뷰 transactions 및 transaction_count_30d에 대해 피처 뷰 transaction_count_30d의 모든 구체화된 피처를 제거합니다. 같은 세트 내 구현된 특징 transaction_count 들은 그대로 유지됩니다:
YAML
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
Python
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 변경'을 참조하세요.
다음은 transaction_count에서 정의한 Feature View의 슬라이딩 윈도우 기간을 늘리는 것으로, 이는 변경할 수 없는 필드입니다:
YAML
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
Python
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 에는 여전히 Feature View의 두 가지 구체화된 기능이 포함되어 있기 때문입니다:
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)
변경을 수행하려면 ' 기능 보기 변경'에 설명된 대로 두 번 배포하세요:
기능 뷰의 구체화된 기능을 세트에서 제거하고 배포하세요. 이 세트는 제자리에서 업데이트되며, 피처 뷰의 모든 구체화된 특징 제거의 경우와 같습니다.
Feature View를 변경하고, 해당 materialized features를 다시 집합에 추가한 뒤 배포하세요. 계획은 변경된 창에 대한 피처 뷰를 다시 생성하고, 세트를 다시 생성합니다. 왜냐하면 세트에 구체화된 피처를 추가하면 그 뷰가 대체되기 때문입니다:
Warn: 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 recomputed Warn: 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 recomputed recreate features.transaction_count recreate materialization_sets.transactions Plan: 2 to add, 0 to change, 2 to delete, 5 unchanged승인 후 배포가 기능 보기를 다시 생성한 후 세트를 다시 생성합니다:
Recreated features.transaction_count Recreated materialization_sets.transactions Files: 3 uploaded, 0 deleted Resources: 2 created, 0 changed, 2 deleted, 5 unchanged
물질화 집합의 불변 필드 변경
세트 내 어떤 구체화 피처의 필드를 변경하면, 편집이 영향을 미치지 않는 구체화 피처를 포함한 전체 구체화 세트가 교체됩니다. ' 물질화 세트 변경'을 참조하세요.
다음은 transactions에서 정의한 집합을 가져와 그 온라인 목적지의 table_name_prefix을(를) 변경하는데, 이는 불변입니다. 두 온라인 구체화된 피처 모두 접두사를 붙여 있는데, 이는 세트에 하나의 온라인 목적지가 있기 때문입니다:
YAML
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
Python
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 집합이 다시 생성된다고 나타내므로, 두 개의 일괄 오프라인 물질화된 피처도 삭제되고 다시 계산됩니다:
recreate materialization_sets.transactions
Plan: 1 to add, 0 to change, 1 to delete, 6 unchanged
기존 집합에 구체화된 피처 추가
이미 배포된 물질화 집합에 물질화된 특징을 추가하면 세트가 대체되므로, 그 안에 있는 모든 물질화된 특징이 다시 계산됩니다. ' 물질화 세트 변경'을 참조하세요.
다음은 집합을, transactions에서 피처 뷰 transaction_count_30d의 모든 구체화된 피처를 제거한 후, 피처 뷰 transaction_count_30d의 구체화된 피처를 다시 추가한 것입니다:
YAML
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
Python
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의 일부 구체화된 기능 제거하기
특징 뷰의 구체화된 특징 중 일부만 구체화 세트에서 제거하는 것은 허용되지 않습니다. ' 물질화 세트 변경'을 참조하세요.
다음은 톱니바 창을 가진 Feature Viewamount_sum에 대해 5단계에서 정의한 집합 amounts 을 가져와, 해당 배치 오프라인 물리화된 기능만 제거합니다:
YAML
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
Python
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의 일괄 오프라인 구체화된 기능을 제거하며, 해당 삭제는 편집이 요청하지 않는 동일한 기능 뷰의 다른 두 가지 구체화된 기능도 함께 삭제합니다. 배포가 거부됩니다:
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 비용 관리를 참조하세요.
Limitations
- 스트림은 번들 리소스가 아닙니다. 번들 외부에서 생성하고 이름으로 참조하세요.
- 기존 구체화 세트에 구체화된 피처를 추가하면 세트가 다시 생성되므로, 그 안에 있는 모든 구체화된 피처가 다시 계산됩니다.
-
feature_view_source또는request_source의 피처 뷰나custom_udf함수를 사용하는 피처 뷰는 머티리얼라이즈할 수 없습니다. Materialize Feature Views를 참조하세요.
다음 단계
- CI/CD 워크플로에서 이러한 리소스를 배포하려면 GitHub Actions를 사용한 기능 뷰용 CI/CD를 참조하세요.
- 번들에서 이러한 피처를 제공하려면 선언적 자동화 번들을 사용하여 기능 뷰 제공하기를 참조하세요. Python API로 이를 제공하려면 기능 뷰 제공 및 예제: 기능 제공 엔드포인트 배포 및 쿼리를 참조하세요.
- 이들로 모델을 학습하려면 '피처 뷰로 모델 학습하기'를 참조하세요.
- 전체 구성 참조는 feature 및 materialization_set를 참조하십시오.
- 구체화가 어떻게 작동하는지 알아보려면 '특징 뷰 구체화'를 참조하세요.