Exemple #1
0
def test_apply_data_source(test_registry: Registry):
    # Create Feature Views
    batch_source = FileSource(
        name="test_source",
        file_format=ParquetFormat(),
        path="file://feast/*",
        timestamp_field="ts_col",
        created_timestamp_column="timestamp",
    )

    fv1 = FeatureView(
        name="my_feature_view_1",
        schema=[
            Field(name="fs1_my_feature_1", dtype=Int64),
            Field(name="fs1_my_feature_2", dtype=String),
            Field(name="fs1_my_feature_3", dtype=Array(String)),
            Field(name="fs1_my_feature_4", dtype=Array(Bytes)),
        ],
        entities=["fs1_my_entity_1"],
        tags={"team": "matchmaking"},
        batch_source=batch_source,
        ttl=timedelta(minutes=5),
    )

    project = "project"

    # Register data source and feature view
    test_registry.apply_data_source(batch_source, project, commit=False)
    test_registry.apply_feature_view(fv1, project, commit=True)

    registry_feature_views = test_registry.list_feature_views(project)
    registry_data_sources = test_registry.list_data_sources(project)
    assert len(registry_feature_views) == 1
    assert len(registry_data_sources) == 1
    registry_feature_view = registry_feature_views[0]
    assert registry_feature_view.batch_source == batch_source
    registry_data_source = registry_data_sources[0]
    assert registry_data_source == batch_source

    # Check that change to batch source propagates
    batch_source.timestamp_field = "new_ts_col"
    test_registry.apply_data_source(batch_source, project, commit=False)
    test_registry.apply_feature_view(fv1, project, commit=True)
    registry_feature_views = test_registry.list_feature_views(project)
    registry_data_sources = test_registry.list_data_sources(project)
    assert len(registry_feature_views) == 1
    assert len(registry_data_sources) == 1
    registry_feature_view = registry_feature_views[0]
    assert registry_feature_view.batch_source == batch_source
    registry_batch_source = test_registry.list_data_sources(project)[0]
    assert registry_batch_source == batch_source

    test_registry.teardown()

    # Will try to reload registry, which will fail because the file has been deleted
    with pytest.raises(FileNotFoundError):
        test_registry._get_registry_proto()
Exemple #2
0
def apply_diff_to_registry(registry: Registry,
                           registry_diff: RegistryDiff,
                           project: str,
                           commit: bool = True):
    """
    Applies the given diff to the given Feast project in the registry.

    Args:
        registry: The registry to be updated.
        registry_diff: The diff to apply.
        project: Feast project to be updated.
        commit: Whether the change should be persisted immediately
    """
    for feast_object_diff in registry_diff.feast_object_diffs:
        # There is no need to delete the object on an update, since applying the new object
        # will automatically delete the existing object.
        if feast_object_diff.transition_type == TransitionType.DELETE:
            if feast_object_diff.feast_object_type == FeastObjectType.ENTITY:
                entity_obj = cast(Entity,
                                  feast_object_diff.current_feast_object)
                registry.delete_entity(entity_obj.name, project, commit=False)
            elif feast_object_diff.feast_object_type == FeastObjectType.FEATURE_SERVICE:
                feature_service_obj = cast(
                    FeatureService, feast_object_diff.current_feast_object)
                registry.delete_feature_service(feature_service_obj.name,
                                                project,
                                                commit=False)
            elif feast_object_diff.feast_object_type in [
                    FeastObjectType.FEATURE_VIEW,
                    FeastObjectType.ON_DEMAND_FEATURE_VIEW,
                    FeastObjectType.REQUEST_FEATURE_VIEW,
            ]:
                feature_view_obj = cast(BaseFeatureView,
                                        feast_object_diff.current_feast_object)
                registry.delete_feature_view(
                    feature_view_obj.name,
                    project,
                    commit=False,
                )

        if feast_object_diff.transition_type in [
                TransitionType.CREATE,
                TransitionType.UPDATE,
        ]:
            if feast_object_diff.feast_object_type == FeastObjectType.DATA_SOURCE:
                registry.apply_data_source(
                    cast(DataSource, feast_object_diff.new_feast_object),
                    project,
                    commit=False,
                )
            if feast_object_diff.feast_object_type == FeastObjectType.ENTITY:
                registry.apply_entity(
                    cast(Entity, feast_object_diff.new_feast_object),
                    project,
                    commit=False,
                )
            elif feast_object_diff.feast_object_type == FeastObjectType.FEATURE_SERVICE:
                registry.apply_feature_service(
                    cast(FeatureService, feast_object_diff.new_feast_object),
                    project,
                    commit=False,
                )
            elif feast_object_diff.feast_object_type in [
                    FeastObjectType.FEATURE_VIEW,
                    FeastObjectType.ON_DEMAND_FEATURE_VIEW,
                    FeastObjectType.REQUEST_FEATURE_VIEW,
            ]:
                registry.apply_feature_view(
                    cast(BaseFeatureView, feast_object_diff.new_feast_object),
                    project,
                    commit=False,
                )

    if commit:
        registry.commit()