Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions docs/reference/data-sources/push.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,22 @@ streamingDF.writeStream.foreachBatch(feast_writer).start()
```

This can also be used under the hood by a contrib stream processor (see [Tutorial: Building streaming features](../../tutorials/building-streaming-features.md))

## External Pipeline Lineage (upstream_feature_view_names)

When feature transformations occurring outside Feast consume upstream Feast feature views before pushing results into Feast, this dependency metadata can be captured by setting `upstream_feature_view_names` on `PushSource` to visualize the relationship in the Feast Web UI lineage graph:

```python
push_source2 = PushSource(
name="push_source2",
upstream_feature_view_names=[fv],
)

fv2 = FeatureView(
name="feature view 2",
entities=[user],
schema=[Field(name="derived_value", dtype=Int64)],
source=push_source2,
)
```

3 changes: 3 additions & 0 deletions protos/feast/core/DataSource.proto
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ message DataSource {
// the online store on-demand, such as by stream consumers.
message PushOptions {
reserved 1;
// Names of upstream FeatureViews/LabelViews consumed by the external process feeding this PushSource.
// Represents external pipeline lineage metadata; does not trigger Feast-managed DAG execution.
repeated string upstream_feature_view_names = 2;
}


Expand Down
50 changes: 46 additions & 4 deletions sdk/python/feast/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import warnings
from abc import ABC, abstractmethod
from datetime import datetime, timedelta, timezone
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple
from typing import Any, Callable, Dict, Iterable, List, Optional, Sequence, Tuple, Union

from google.protobuf.duration_pb2 import Duration
from google.protobuf.json_format import MessageToJson
Expand Down Expand Up @@ -876,12 +876,14 @@ class PushSource(DataSource):
# TODO(adchia): consider adding schema here in case where Feast manages pushing events to the offline store
# TODO(adchia): consider a "mode" to support pushing raw vs transformed events
batch_source: Optional[DataSource] = None
upstream_feature_view_names: List[str] = []

def __init__(
self,
*,
name: str,
batch_source: Optional[DataSource] = None,
upstream_feature_view_names: Optional[Sequence[Union[Any, str]]] = None,
description: Optional[str] = "",
tags: Optional[Dict[str, str]] = None,
owner: Optional[str] = "",
Expand All @@ -890,9 +892,14 @@ def __init__(
Creates a PushSource object.

Args:
name: Name of the push source
batch_source: The batch source that backs this push source. It's used when materializing from the offline
store to the online store, and when retrieving historical features.
name: Name of the push source.
batch_source (optional): The batch source that backs this push source. It's used when
materializing from the offline store to the online store, and when retrieving
historical features.
upstream_feature_view_names (optional): Sequence of upstream FeatureView/LabelView
objects or names consumed by the external process feeding this push source.
Represents external pipeline lineage metadata and does not trigger Feast-managed
DAG execution.
description (optional): A human-readable description.
tags (optional): A dictionary of key-value pairs to store arbitrary metadata.
owner (optional): The owner of the data source, typically the email of the primary
Expand All @@ -901,6 +908,27 @@ def __init__(
super().__init__(name=name, description=description, tags=tags, owner=owner)
self.batch_source = batch_source

normalized_upstream_names: List[str] = []
if upstream_feature_view_names is not None:
for item in upstream_feature_view_names:
if hasattr(item, "name"):
name_val = item.name
if not isinstance(name_val, str) or not name_val.strip():
raise ValueError(
f"Upstream feature view object {item} has an invalid or empty name"
)
normalized_upstream_names.append(name_val.strip())
elif isinstance(item, str):
if not item.strip():
raise ValueError("Upstream feature view name cannot be empty")
normalized_upstream_names.append(item.strip())
else:
raise TypeError(
f"Unsupported type for upstream feature view: {type(item)}. "
"Expected str or object with a 'name' attribute (e.g. FeatureView, LabelView)."
)
self.upstream_feature_view_names = normalized_upstream_names

def __eq__(self, other):
if not isinstance(other, PushSource):
return False
Expand All @@ -911,6 +939,9 @@ def __eq__(self, other):
if self.batch_source != other.batch_source:
return False

if self.upstream_feature_view_names != other.upstream_feature_view_names:
return False

return True

def __hash__(self):
Expand All @@ -932,9 +963,16 @@ def from_proto(data_source: DataSourceProto):
else None
)

upstream_feature_view_names = (
list(data_source.push_options.upstream_feature_view_names)
if data_source.HasField("push_options")
else []
)

return PushSource(
name=data_source.name,
batch_source=batch_source,
upstream_feature_view_names=upstream_feature_view_names,
description=data_source.description,
tags=dict(data_source.tags),
owner=data_source.owner,
Expand All @@ -949,6 +987,10 @@ def _to_proto_impl(self) -> DataSourceProto:
owner=self.owner,
)

data_source_proto.push_options.upstream_feature_view_names.extend(
self.upstream_feature_view_names
)

# Only set timestamp fields if we have a batch source and this PushSource doesn't have its own fields
if self.batch_source and not (
self.timestamp_field or self.created_timestamp_column or self.field_mapping
Expand Down
53 changes: 49 additions & 4 deletions sdk/python/feast/feature_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -1474,7 +1474,16 @@ def plan(
desired_repo_contents.stream_feature_views,
desired_repo_contents.label_views,
)
_validate_data_sources(desired_repo_contents.data_sources)
all_fvs_for_validation = [
*desired_repo_contents.feature_views,
*desired_repo_contents.on_demand_feature_views,
*desired_repo_contents.stream_feature_views,
*desired_repo_contents.label_views,
]
_validate_data_sources(
desired_repo_contents.data_sources,
all_feature_views=all_fvs_for_validation,
)
self._make_inferences(
desired_repo_contents.data_sources,
desired_repo_contents.entities,
Expand Down Expand Up @@ -1749,14 +1758,24 @@ def apply(
# Handle all entityless feature views by using DUMMY_ENTITY as a placeholder entity.
entities_to_update.append(DUMMY_ENTITY)

# Validate all feature views and make inferences.
# Validate all feature views and data sources, then make inferences.
if not skip_feature_view_validation:
self._validate_all_feature_views(
views_to_update,
odfvs_to_update,
sfvs_to_update,
lvs_to_update,
)
all_fvs_for_validation = [
*views_to_update,
*odfvs_to_update,
*sfvs_to_update,
*(lvs_to_update or []),
]
_validate_data_sources(
data_sources_to_update,
all_feature_views=all_fvs_for_validation,
)
self._make_inferences(
data_sources_to_update,
entities_to_update,
Expand Down Expand Up @@ -5156,12 +5175,38 @@ def _validate_feature_views(feature_views: List[BaseFeatureView]):
fv_by_name[case_insensitive_fv_name] = fv


def _validate_data_sources(data_sources: List[DataSource]):
"""Verify data sources have case-insensitively unique names."""
def _validate_data_sources(
data_sources: List[DataSource],
all_feature_views: Optional[
Sequence[
Union[
BaseFeatureView,
FeatureView,
StreamFeatureView,
OnDemandFeatureView,
LabelView,
]
]
] = None,
):
"""Verify data sources have case-insensitively unique names and validate PushSource upstream references."""
ds_names = set()
for ds in data_sources:
case_insensitive_ds_name = ds.name.lower()
if case_insensitive_ds_name in ds_names:
raise DataSourceRepeatNamesException(case_insensitive_ds_name)
else:
ds_names.add(case_insensitive_ds_name)

if all_feature_views is not None:
known_fv_names = {fv.name for fv in all_feature_views if hasattr(fv, "name")}
for ds in data_sources:
if isinstance(ds, PushSource) and ds.upstream_feature_view_names:
for upstream_name in ds.upstream_feature_view_names:
if upstream_name not in known_fv_names:
warnings.warn(
f"PushSource '{ds.name}' references upstream feature view '{upstream_name}' "
"which was not found in the current feature repository.",
UserWarning,
stacklevel=2,
)
87 changes: 87 additions & 0 deletions sdk/python/feast/lineage/registry_lineage.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,27 @@ def _parse_direct_relationships(self, registry: Registry) -> List[EntityRelation
)
relationships.append(rel)

# Stream source -> FeatureView relationships
if (
hasattr(feature_view.spec, "stream_source")
and feature_view.spec.stream_source
):
stream_source_name = getattr(
feature_view.spec.stream_source, "name", None
)
if stream_source_name:
relationships.append(
EntityRelation(
source=EntityReference(
FeastObjectType.DATA_SOURCE, stream_source_name
),
target=EntityReference(
FeastObjectType.FEATURE_VIEW,
feature_view.spec.name,
),
)
)

# Batch source relationship
if (
hasattr(feature_view.spec, "batch_source")
Expand Down Expand Up @@ -455,6 +476,72 @@ def _parse_direct_relationships(self, registry: Registry) -> List[EntityRelation
)
)

# Upstream FeatureView -> DataSource (PushSource) relationships
push_sources = {
ds.name: ds
for ds in registry.data_sources
if hasattr(ds, "name")
and ds.name
and hasattr(ds, "push_options")
and ds.push_options
}
for fv in registry.feature_views:
if (
hasattr(fv, "spec")
and fv.spec
and hasattr(fv.spec, "stream_source")
and fv.spec.stream_source
and hasattr(fv.spec.stream_source, "name")
and fv.spec.stream_source.name
and hasattr(fv.spec.stream_source, "push_options")
and fv.spec.stream_source.push_options
):
push_sources[fv.spec.stream_source.name] = fv.spec.stream_source
for sfv in registry.stream_feature_views:
if (
hasattr(sfv, "spec")
and sfv.spec
and hasattr(sfv.spec, "stream_source")
and sfv.spec.stream_source
and hasattr(sfv.spec.stream_source, "name")
and sfv.spec.stream_source.name
and hasattr(sfv.spec.stream_source, "push_options")
and sfv.spec.stream_source.push_options
):
push_sources[sfv.spec.stream_source.name] = sfv.spec.stream_source
for lv in registry.label_views:
if (
hasattr(lv, "spec")
and lv.spec
and hasattr(lv.spec, "source")
and lv.spec.source
and hasattr(lv.spec.source, "name")
and lv.spec.source.name
and hasattr(lv.spec.source, "push_options")
and lv.spec.source.push_options
):
push_sources[lv.spec.source.name] = lv.spec.source

for ds in push_sources.values():
if (
not hasattr(ds, "push_options")
or not hasattr(ds.push_options, "upstream_feature_view_names")
or not ds.push_options.upstream_feature_view_names
):
continue
for upstream_fv in ds.push_options.upstream_feature_view_names:
source_type = (
FeastObjectType.LABEL_VIEW
if upstream_fv in label_view_names
else FeastObjectType.FEATURE_VIEW
)
relationships.append(
EntityRelation(
source=EntityReference(source_type, upstream_fv),
target=EntityReference(FeastObjectType.DATA_SOURCE, ds.name),
)
)

# SavedDataset relationships
ds_location_index = _build_datasource_location_index(registry)

Expand Down
Loading
Loading