From 40b76499fee6943c7f2de659b18419d57e3ee5ed Mon Sep 17 00:00:00 2001 From: Chaitany Patel Date: Fri, 18 Sep 2026 15:51:47 +0530 Subject: [PATCH 1/3] feat: Add online sequence configuration foundation Signed-off-by: Chaitany Patel --- docs/getting-started/concepts/feature-view.md | 28 ++++ protos/feast/core/FeatureView.proto | 36 ++++- sdk/python/feast/__init__.py | 2 + sdk/python/feast/batch_feature_view.py | 6 + sdk/python/feast/cli/feature_views.py | 12 ++ sdk/python/feast/feature_view.py | 27 +++- sdk/python/feast/infra/registry/registry.py | 9 ++ sdk/python/feast/online_config.py | 138 ++++++++++++++++++ .../protos/feast/core/FeatureView_pb2.py | 32 ++-- .../protos/feast/core/FeatureView_pb2.pyi | 75 +++++++++- .../tests/unit/cli/test_feature_views.py | 40 +++++ sdk/python/tests/unit/test_feature_views.py | 37 +++++ sdk/python/tests/unit/test_online_config.py | 55 +++++++ .../tests/unit/test_online_config_apply.py | 74 ++++++++++ 14 files changed, 553 insertions(+), 18 deletions(-) create mode 100644 sdk/python/feast/online_config.py create mode 100644 sdk/python/tests/unit/cli/test_feature_views.py create mode 100644 sdk/python/tests/unit/test_online_config.py create mode 100644 sdk/python/tests/unit/test_online_config_apply.py diff --git a/docs/getting-started/concepts/feature-view.md b/docs/getting-started/concepts/feature-view.md index 45440e71e68..abb43c60878 100644 --- a/docs/getting-started/concepts/feature-view.md +++ b/docs/getting-started/concepts/feature-view.md @@ -26,6 +26,7 @@ Feature views consist of: * (optional) `owner`: the email of the primary maintainer * (optional) `org`: the organizational unit that owns the feature view (e.g. `"ads"`, `"search"`); useful for grouping feature views by team or product area * (optional) a TTL, which limits how far back Feast will look when generating historical datasets. During online retrieval, values older than the TTL are still returned, but their field status is `OUTSIDE_MAX_AGE` instead of `PRESENT` +* (optional) `online_config`, which declares online retention and write semantics * (optional) `enable_validation=True`, which enables schema validation during materialization (see [Schema Validation](#schema-validation) below) Feature views allow Feast to model your existing feature data in a consistent way in both an offline (training) and online (serving) environment. Feature views generally contain features that are properties of a specific object, in which case that object is defined as an entity and included in the feature view. @@ -59,6 +60,33 @@ Feature views are used during * Loading of feature values into an online store. Feature views determine the storage schema in the online store. Feature values can be loaded from batch sources or from [stream sources](../../reference/data-sources/push.md). * Retrieval of features from the online store. Feature views provide the schema definition to Feast in order to look up features from the online store. +## Online retention configuration + +`OnlineConfig` declares whether a feature view uses the current latest-value model or a bounded sequence of historical values per entity. Sequence mode requires append writes and a positive maximum length. An optional maximum age adds a second retention limit. + +```python +from datetime import timedelta + +from feast import FeatureView, OnlineConfig + +user_interactions = FeatureView( + name="user_interactions", + entities=[user], + schema=[...], + source=interactions_source, + online_config=OnlineConfig( + mode="sequence", + max_length=50, + max_age=timedelta(days=90), + write_mode="append", + ), +) +``` + +{% hint style="warning" %} +Sequence configuration is currently an experimental registry contract. Online stores continue to use their existing latest-value behavior until they explicitly implement sequence append, retrieval, and eviction support. +{% endhint %} + ## Feature views without entities If a feature view contains features that are not related to a specific entity, the feature view can be defined without entities (only timestamps are needed for this feature view). diff --git a/protos/feast/core/FeatureView.proto b/protos/feast/core/FeatureView.proto index e9fab625bb4..dcc123c9d16 100644 --- a/protos/feast/core/FeatureView.proto +++ b/protos/feast/core/FeatureView.proto @@ -56,7 +56,38 @@ message FeatureView { FeatureViewMeta meta = 2; } -// Next available id: 20 +// Configuration for how feature values are retained in an online store. +// This message is currently a declarative contract; online store implementations +// opt into sequence behavior separately. +message OnlineConfig { + enum Mode { + // Preserve the current behavior: one latest value per entity. + LATEST = 0; + + // Retain an ordered sequence of values per entity. + SEQUENCE = 1; + } + + Mode mode = 1; + + // Maximum number of events retained per entity. 0 means unset. + int32 max_length = 2; + + // Maximum event age in whole seconds. 0 means unset. + int64 max_age_seconds = 3; + + enum WriteMode { + // Preserve the current upsert behavior. + OVERWRITE = 0; + + // Append a new event without overwriting earlier events. + APPEND = 1; + } + + WriteMode write_mode = 4; +} + +// Next available id: 22 // TODO(adchia): refactor common fields from this and ODFV into separate metadata proto message FeatureViewSpec { // Name of the feature view. Must be unique. Not updated. @@ -125,6 +156,9 @@ message FeatureViewSpec { // When true, the feature view will not serve online features or be materialized. // Defaults to false (enabled) for backward compatibility. bool disabled = 20; + + // Online retention and write semantics for this feature view. + OnlineConfig online_config = 21; } message FeatureViewMeta { diff --git a/sdk/python/feast/__init__.py b/sdk/python/feast/__init__.py index a8e427d6f89..d96a5b71d9b 100644 --- a/sdk/python/feast/__init__.py +++ b/sdk/python/feast/__init__.py @@ -39,6 +39,7 @@ from .filter_models import FilterTranslator from .labeling import ConflictPolicy, LabelView from .on_demand_feature_view import OnDemandFeatureView +from .online_config import OnlineConfig from .project import Project from .repo_config import RepoConfig from .stream_feature_view import StreamFeatureView @@ -69,6 +70,7 @@ "LabelView", "ConflictPolicy", "OnDemandFeatureView", + "OnlineConfig", "RepoConfig", "StreamFeatureView", "ValueType", diff --git a/sdk/python/feast/batch_feature_view.py b/sdk/python/feast/batch_feature_view.py index b4f43d6459e..b6fd7ffc0be 100644 --- a/sdk/python/feast/batch_feature_view.py +++ b/sdk/python/feast/batch_feature_view.py @@ -13,6 +13,7 @@ from feast.entity import Entity from feast.feature_view import FeatureView from feast.field import Field +from feast.online_config import OnlineConfig from feast.protos.feast.core.DataSource_pb2 import DataSource as DataSourceProto from feast.transformation.base import Transformation from feast.transformation.mode import TransformationMode @@ -45,6 +46,7 @@ class BatchFeatureView(FeatureView): columns. If not specified, can be inferred from the underlying data source. source: The batch source of data where this group of features is stored. online: A boolean indicating whether online retrieval and write to online store is enabled for this feature view. + online_config: Optional online retention and write semantics. offline: A boolean indicating whether offline retrieval and write to offline store is enabled for this feature view. description: A human-readable description. tags: A dictionary of key-value pairs to store arbitrary metadata. @@ -92,6 +94,7 @@ def __init__( ttl: Optional[timedelta] = None, tags: Optional[Dict[str, str]] = None, online: bool = False, + online_config: Optional[OnlineConfig] = None, offline: bool = False, description: str = "", owner: str = "", @@ -151,6 +154,7 @@ def __init__( ttl=ttl, tags=tags, online=online, + online_config=online_config, offline=offline, description=description, owner=owner, @@ -277,6 +281,7 @@ def batch_feature_view( source: Optional[DataSource] = None, tags: Optional[Dict[str, str]] = None, online: bool = True, + online_config: Optional[OnlineConfig] = None, offline: bool = True, description: str = "", owner: str = "", @@ -308,6 +313,7 @@ def decorator(user_function): source=source, tags=tags, online=online, + online_config=online_config, offline=offline, description=description, owner=owner, diff --git a/sdk/python/feast/cli/feature_views.py b/sdk/python/feast/cli/feature_views.py index 44357b0c1c1..4b42f260e5b 100644 --- a/sdk/python/feast/cli/feature_views.py +++ b/sdk/python/feast/cli/feature_views.py @@ -44,6 +44,18 @@ def feature_view_describe(ctx: click.Context, name: str): data["enabled"] = feature_view.enabled if hasattr(feature_view, "state"): data["state"] = feature_view.state.name + if feature_view.online_config is not None: + online_config = feature_view.online_config + data["spec"]["onlineConfig"] = { + "mode": online_config.mode, + "maxLength": online_config.max_length, + "maxAgeSeconds": ( + int(online_config.max_age.total_seconds()) + if online_config.max_age is not None + else None + ), + "writeMode": online_config.write_mode, + } print(yaml.dump(data, default_flow_style=False, sort_keys=False)) diff --git a/sdk/python/feast/feature_view.py b/sdk/python/feast/feature_view.py index f9e0c460a2d..cb3ce68dc5a 100644 --- a/sdk/python/feast/feature_view.py +++ b/sdk/python/feast/feature_view.py @@ -27,6 +27,7 @@ from feast.entity import Entity from feast.feature_view_projection import FeatureViewProjection from feast.field import Field +from feast.online_config import OnlineConfig from feast.proto_utils import ( mode_to_string, serialize_data_source, @@ -129,6 +130,8 @@ class FeatureView(BaseFeatureView): can be inferred from the underlying data source. online: A boolean indicating whether online retrieval is enabled for this feature view. + online_config: Optional online retention and write semantics. Sequence mode is + declarative until implemented by an online store. description: A human-readable description. tags: A dictionary of key-value pairs to store arbitrary metadata. owner: The owner of the feature view, typically the email of the primary @@ -149,6 +152,7 @@ class FeatureView(BaseFeatureView): entity_columns: List[Field] features: List[Field] online: bool + online_config: Optional[OnlineConfig] offline: bool description: str tags: Dict[str, str] @@ -171,6 +175,7 @@ def __init__( entities: Optional[List[Entity]] = None, ttl: Optional[timedelta] = timedelta(days=0), online: bool = True, + online_config: Optional[OnlineConfig] = None, offline: bool = False, description: str = "", tags: Optional[Dict[str, str]] = None, @@ -198,6 +203,8 @@ def __init__( can result in extremely computationally intensive queries. online (optional): A boolean indicating whether online retrieval is enabled for this feature view. + online_config (optional): Online retention and write semantics for this feature + view. Defaults to the current latest-value behavior when omitted. offline (optional): A boolean indicating whether write to offline store is enabled for this feature view. description (optional): A human-readable description. @@ -223,6 +230,7 @@ def __init__( self.enable_validation = enable_validation self.entities = [e.name for e in entities] if entities else [DUMMY_ENTITY_NAME] self.ttl = ttl + self.online_config = online_config schema = schema or [] self.mode = mode @@ -353,6 +361,7 @@ def __copy__(self): schema=self.schema, tags=self.tags, online=self.online, + online_config=self.online_config, offline=self.offline, sink_source=self.batch_source if self.source_views else None, enable_validation=self.enable_validation, @@ -389,7 +398,7 @@ def _schema_or_udf_changed(self, other: "BaseFeatureView") -> bool: # Skip UDF-related data source fields: batch_source, stream_source # (treat as deployment configuration, not schema changes) - # Skip configuration: ttl, online, offline, enable_validation + # Skip configuration: ttl, online, online_config, offline, enable_validation # Skip metadata: materialization_intervals (excluded in current equality) return False @@ -404,6 +413,7 @@ def __eq__(self, other): sorted(self.entities) != sorted(other.entities) or self.ttl != other.ttl or self.online != other.online + or self.online_config != other.online_config or self.offline != other.offline or self.batch_source != other.batch_source or self.stream_source != other.stream_source @@ -437,6 +447,9 @@ def ensure_valid(self): """ super().ensure_valid() + if self.online_config is not None: + self.online_config.validate() + if not self.entities: raise ValueError("Feature view has no entities.") @@ -549,6 +562,11 @@ def to_proto_spec( org=self.org, ttl=(ttl_duration if ttl_duration is not None else None), online=self.online, + online_config=( + self.online_config.to_proto() + if self.online_config is not None + else None + ), offline=self.offline, batch_source=batch_source_proto, stream_source=stream_source_proto, @@ -633,6 +651,11 @@ def _from_proto_internal( ) for view_spec in feature_view_proto.spec.source_views ] + online_config = ( + OnlineConfig.from_proto(feature_view_proto.spec.online_config) + if feature_view_proto.spec.HasField("online_config") + else None + ) from feast.batch_feature_view import BatchFeatureView @@ -685,6 +708,7 @@ def _from_proto_internal( owner=feature_view_proto.spec.owner, org=feature_view_proto.spec.org, online=feature_view_proto.spec.online, + online_config=online_config, offline=feature_view_proto.spec.offline, ttl=( timedelta(days=0) @@ -714,6 +738,7 @@ def _from_proto_internal( owner=feature_view_proto.spec.owner, org=feature_view_proto.spec.org, online=feature_view_proto.spec.online, + online_config=online_config, offline=feature_view_proto.spec.offline, ttl=( timedelta(days=0) diff --git a/sdk/python/feast/infra/registry/registry.py b/sdk/python/feast/infra/registry/registry.py index a16c4538a92..baa8620140e 100644 --- a/sdk/python/feast/infra/registry/registry.py +++ b/sdk/python/feast/infra/registry/registry.py @@ -615,6 +615,15 @@ def _update_metadata_fields( existing_proto.spec.enable_validation = getattr( updated_fv, "enable_validation" ) + if hasattr(existing_proto.spec, "online_config") and isinstance( + updated_fv, FeatureView + ): + if updated_fv.online_config is None: + existing_proto.spec.ClearField("online_config") + else: + existing_proto.spec.online_config.CopyFrom( + updated_fv.online_config.to_proto() + ) # Enabled/disabled state if hasattr(existing_proto.spec, "disabled") and hasattr(updated_fv, "enabled"): diff --git a/sdk/python/feast/online_config.py b/sdk/python/feast/online_config.py new file mode 100644 index 00000000000..e574da2f088 --- /dev/null +++ b/sdk/python/feast/online_config.py @@ -0,0 +1,138 @@ +# Copyright 2026 The Feast Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +from __future__ import annotations + +from dataclasses import dataclass +from datetime import timedelta +from typing import Optional + +from feast.protos.feast.core.FeatureView_pb2 import OnlineConfig as OnlineConfigProto + + +@dataclass +class OnlineConfig: + """Online retention and write semantics for a feature view. + + Sequence mode is a declarative contract in this foundation release. Online + stores must add explicit sequence support before these settings affect data + storage or retrieval. + """ + + mode: str = "latest" + max_length: Optional[int] = None + max_age: Optional[timedelta] = None + write_mode: str = "overwrite" + + def __post_init__(self) -> None: + self.validate() + + def validate(self) -> None: + """Validate that the configuration represents supported semantics.""" + if self.mode not in {"latest", "sequence"}: + raise ValueError("OnlineConfig mode must be either 'latest' or 'sequence'.") + if self.write_mode not in {"overwrite", "append"}: + raise ValueError( + "OnlineConfig write_mode must be either 'overwrite' or 'append'." + ) + + if self.max_length is not None: + if ( + isinstance(self.max_length, bool) + or not isinstance(self.max_length, int) + or self.max_length <= 0 + ): + raise ValueError("OnlineConfig max_length must be a positive integer.") + if self.max_length > 2_147_483_647: + raise ValueError( + "OnlineConfig max_length must fit in a signed 32-bit integer." + ) + + if self.max_age is not None: + if not isinstance(self.max_age, timedelta) or self.max_age <= timedelta(0): + raise ValueError("OnlineConfig max_age must be a positive timedelta.") + total_seconds = self.max_age.total_seconds() + if not total_seconds.is_integer(): + raise ValueError( + "OnlineConfig max_age must use whole seconds because registry " + "serialization stores max_age_seconds." + ) + + if self.mode == "sequence": + if self.write_mode != "append": + raise ValueError( + "OnlineConfig mode='sequence' requires write_mode='append'." + ) + if self.max_length is None: + raise ValueError( + "OnlineConfig mode='sequence' requires max_length to be set." + ) + else: + if self.write_mode != "overwrite": + raise ValueError( + "OnlineConfig mode='latest' requires write_mode='overwrite'." + ) + if self.max_length is not None or self.max_age is not None: + raise ValueError( + "OnlineConfig retention limits are only valid when mode='sequence'." + ) + + def to_proto(self) -> OnlineConfigProto: + """Convert this configuration to its registry protobuf representation.""" + self.validate() + return OnlineConfigProto( + mode=( + OnlineConfigProto.SEQUENCE + if self.mode == "sequence" + else OnlineConfigProto.LATEST + ), + max_length=self.max_length or 0, + max_age_seconds=( + int(self.max_age.total_seconds()) if self.max_age is not None else 0 + ), + write_mode=( + OnlineConfigProto.APPEND + if self.write_mode == "append" + else OnlineConfigProto.OVERWRITE + ), + ) + + @classmethod + def from_proto(cls, config_proto: OnlineConfigProto) -> OnlineConfig: + """Create an OnlineConfig from its registry protobuf representation.""" + try: + mode = OnlineConfigProto.Mode.Name(config_proto.mode).lower() + except ValueError as e: + raise ValueError( + f"Unknown OnlineConfig mode enum value: {config_proto.mode}." + ) from e + try: + write_mode = OnlineConfigProto.WriteMode.Name( + config_proto.write_mode + ).lower() + except ValueError as e: + raise ValueError( + "Unknown OnlineConfig write_mode enum value: " + f"{config_proto.write_mode}." + ) from e + + return cls( + mode=mode, + max_length=config_proto.max_length or None, + max_age=( + timedelta(seconds=config_proto.max_age_seconds) + if config_proto.max_age_seconds + else None + ), + write_mode=write_mode, + ) diff --git a/sdk/python/feast/protos/feast/core/FeatureView_pb2.py b/sdk/python/feast/protos/feast/core/FeatureView_pb2.py index 71766558c82..f786d4cbc78 100644 --- a/sdk/python/feast/protos/feast/core/FeatureView_pb2.py +++ b/sdk/python/feast/protos/feast/core/FeatureView_pb2.py @@ -19,7 +19,7 @@ from feast.protos.feast.core import Transformation_pb2 as feast_dot_core_dot_Transformation__pb2 -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1c\x66\x65\x61st/core/FeatureView.proto\x12\nfeast.core\x1a\x1egoogle/protobuf/duration.proto\x1a\x1fgoogle/protobuf/timestamp.proto\x1a\x1b\x66\x65\x61st/core/DataSource.proto\x1a\x18\x66\x65\x61st/core/Feature.proto\x1a\x1f\x66\x65\x61st/core/Transformation.proto\"c\n\x0b\x46\x65\x61tureView\x12)\n\x04spec\x18\x01 \x01(\x0b\x32\x1b.feast.core.FeatureViewSpec\x12)\n\x04meta\x18\x02 \x01(\x0b\x32\x1b.feast.core.FeatureViewMeta\"\x9f\x05\n\x0f\x46\x65\x61tureViewSpec\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0f\n\x07project\x18\x02 \x01(\t\x12\x10\n\x08\x65ntities\x18\x03 \x03(\t\x12+\n\x08\x66\x65\x61tures\x18\x04 \x03(\x0b\x32\x19.feast.core.FeatureSpecV2\x12\x33\n\x04tags\x18\x05 \x03(\x0b\x32%.feast.core.FeatureViewSpec.TagsEntry\x12&\n\x03ttl\x18\x06 \x01(\x0b\x32\x19.google.protobuf.Duration\x12,\n\x0c\x62\x61tch_source\x18\x07 \x01(\x0b\x32\x16.feast.core.DataSource\x12\x0e\n\x06online\x18\x08 \x01(\x08\x12-\n\rstream_source\x18\t \x01(\x0b\x32\x16.feast.core.DataSource\x12\x13\n\x0b\x64\x65scription\x18\n \x01(\t\x12\r\n\x05owner\x18\x0b \x01(\t\x12\x31\n\x0e\x65ntity_columns\x18\x0c \x03(\x0b\x32\x19.feast.core.FeatureSpecV2\x12\x0f\n\x07offline\x18\r \x01(\x08\x12\x31\n\x0csource_views\x18\x0e \x03(\x0b\x32\x1b.feast.core.FeatureViewSpec\x12\x43\n\x16\x66\x65\x61ture_transformation\x18\x0f \x01(\x0b\x32#.feast.core.FeatureTransformationV2\x12\x0c\n\x04mode\x18\x10 \x01(\t\x12\x19\n\x11\x65nable_validation\x18\x11 \x01(\x08\x12\x0f\n\x07version\x18\x12 \x01(\t\x12\x0b\n\x03org\x18\x13 \x01(\t\x12\x10\n\x08\x64isabled\x18\x14 \x01(\x08\x1a+\n\tTagsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"\xad\x02\n\x0f\x46\x65\x61tureViewMeta\x12\x35\n\x11\x63reated_timestamp\x18\x01 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12:\n\x16last_updated_timestamp\x18\x02 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12\x46\n\x19materialization_intervals\x18\x03 \x03(\x0b\x32#.feast.core.MaterializationInterval\x12\x1e\n\x16\x63urrent_version_number\x18\x04 \x01(\x05\x12\x12\n\nversion_id\x18\x05 \x01(\t\x12+\n\x05state\x18\x06 \x01(\x0e\x32\x1c.feast.core.FeatureViewState\"w\n\x17MaterializationInterval\x12.\n\nstart_time\x18\x01 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12,\n\x08\x65nd_time\x18\x02 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\"@\n\x0f\x46\x65\x61tureViewList\x12-\n\x0c\x66\x65\x61tureviews\x18\x01 \x03(\x0b\x32\x17.feast.core.FeatureView*n\n\x10\x46\x65\x61tureViewState\x12\x15\n\x11STATE_UNSPECIFIED\x10\x00\x12\x0b\n\x07\x43REATED\x10\x01\x12\r\n\tGENERATED\x10\x02\x12\x11\n\rMATERIALIZING\x10\x03\x12\x14\n\x10\x41VAILABLE_ONLINE\x10\x04\x42U\n\x10\x66\x65\x61st.proto.coreB\x10\x46\x65\x61tureViewProtoZ/github.com/feast-dev/feast/go/protos/feast/coreb\x06proto3') +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1c\x66\x65\x61st/core/FeatureView.proto\x12\nfeast.core\x1a\x1egoogle/protobuf/duration.proto\x1a\x1fgoogle/protobuf/timestamp.proto\x1a\x1b\x66\x65\x61st/core/DataSource.proto\x1a\x18\x66\x65\x61st/core/Feature.proto\x1a\x1f\x66\x65\x61st/core/Transformation.proto\"c\n\x0b\x46\x65\x61tureView\x12)\n\x04spec\x18\x01 \x01(\x0b\x32\x1b.feast.core.FeatureViewSpec\x12)\n\x04meta\x18\x02 \x01(\x0b\x32\x1b.feast.core.FeatureViewMeta\"\xea\x01\n\x0cOnlineConfig\x12+\n\x04mode\x18\x01 \x01(\x0e\x32\x1d.feast.core.OnlineConfig.Mode\x12\x12\n\nmax_length\x18\x02 \x01(\x05\x12\x17\n\x0fmax_age_seconds\x18\x03 \x01(\x03\x12\x36\n\nwrite_mode\x18\x04 \x01(\x0e\x32\".feast.core.OnlineConfig.WriteMode\" \n\x04Mode\x12\n\n\x06LATEST\x10\x00\x12\x0c\n\x08SEQUENCE\x10\x01\"&\n\tWriteMode\x12\r\n\tOVERWRITE\x10\x00\x12\n\n\x06\x41PPEND\x10\x01\"\xd0\x05\n\x0f\x46\x65\x61tureViewSpec\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0f\n\x07project\x18\x02 \x01(\t\x12\x10\n\x08\x65ntities\x18\x03 \x03(\t\x12+\n\x08\x66\x65\x61tures\x18\x04 \x03(\x0b\x32\x19.feast.core.FeatureSpecV2\x12\x33\n\x04tags\x18\x05 \x03(\x0b\x32%.feast.core.FeatureViewSpec.TagsEntry\x12&\n\x03ttl\x18\x06 \x01(\x0b\x32\x19.google.protobuf.Duration\x12,\n\x0c\x62\x61tch_source\x18\x07 \x01(\x0b\x32\x16.feast.core.DataSource\x12\x0e\n\x06online\x18\x08 \x01(\x08\x12-\n\rstream_source\x18\t \x01(\x0b\x32\x16.feast.core.DataSource\x12\x13\n\x0b\x64\x65scription\x18\n \x01(\t\x12\r\n\x05owner\x18\x0b \x01(\t\x12\x31\n\x0e\x65ntity_columns\x18\x0c \x03(\x0b\x32\x19.feast.core.FeatureSpecV2\x12\x0f\n\x07offline\x18\r \x01(\x08\x12\x31\n\x0csource_views\x18\x0e \x03(\x0b\x32\x1b.feast.core.FeatureViewSpec\x12\x43\n\x16\x66\x65\x61ture_transformation\x18\x0f \x01(\x0b\x32#.feast.core.FeatureTransformationV2\x12\x0c\n\x04mode\x18\x10 \x01(\t\x12\x19\n\x11\x65nable_validation\x18\x11 \x01(\x08\x12\x0f\n\x07version\x18\x12 \x01(\t\x12\x0b\n\x03org\x18\x13 \x01(\t\x12\x10\n\x08\x64isabled\x18\x14 \x01(\x08\x12/\n\ronline_config\x18\x15 \x01(\x0b\x32\x18.feast.core.OnlineConfig\x1a+\n\tTagsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"\xad\x02\n\x0f\x46\x65\x61tureViewMeta\x12\x35\n\x11\x63reated_timestamp\x18\x01 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12:\n\x16last_updated_timestamp\x18\x02 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12\x46\n\x19materialization_intervals\x18\x03 \x03(\x0b\x32#.feast.core.MaterializationInterval\x12\x1e\n\x16\x63urrent_version_number\x18\x04 \x01(\x05\x12\x12\n\nversion_id\x18\x05 \x01(\t\x12+\n\x05state\x18\x06 \x01(\x0e\x32\x1c.feast.core.FeatureViewState\"w\n\x17MaterializationInterval\x12.\n\nstart_time\x18\x01 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12,\n\x08\x65nd_time\x18\x02 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\"@\n\x0f\x46\x65\x61tureViewList\x12-\n\x0c\x66\x65\x61tureviews\x18\x01 \x03(\x0b\x32\x17.feast.core.FeatureView*n\n\x10\x46\x65\x61tureViewState\x12\x15\n\x11STATE_UNSPECIFIED\x10\x00\x12\x0b\n\x07\x43REATED\x10\x01\x12\r\n\tGENERATED\x10\x02\x12\x11\n\rMATERIALIZING\x10\x03\x12\x14\n\x10\x41VAILABLE_ONLINE\x10\x04\x42U\n\x10\x66\x65\x61st.proto.coreB\x10\x46\x65\x61tureViewProtoZ/github.com/feast-dev/feast/go/protos/feast/coreb\x06proto3') _globals = globals() _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) @@ -29,18 +29,24 @@ _globals['DESCRIPTOR']._serialized_options = b'\n\020feast.proto.coreB\020FeatureViewProtoZ/github.com/feast-dev/feast/go/protos/feast/core' _globals['_FEATUREVIEWSPEC_TAGSENTRY']._options = None _globals['_FEATUREVIEWSPEC_TAGSENTRY']._serialized_options = b'8\001' - _globals['_FEATUREVIEWSTATE']._serialized_start=1463 - _globals['_FEATUREVIEWSTATE']._serialized_end=1573 + _globals['_FEATUREVIEWSTATE']._serialized_start=1749 + _globals['_FEATUREVIEWSTATE']._serialized_end=1859 _globals['_FEATUREVIEW']._serialized_start=197 _globals['_FEATUREVIEW']._serialized_end=296 - _globals['_FEATUREVIEWSPEC']._serialized_start=299 - _globals['_FEATUREVIEWSPEC']._serialized_end=970 - _globals['_FEATUREVIEWSPEC_TAGSENTRY']._serialized_start=927 - _globals['_FEATUREVIEWSPEC_TAGSENTRY']._serialized_end=970 - _globals['_FEATUREVIEWMETA']._serialized_start=973 - _globals['_FEATUREVIEWMETA']._serialized_end=1274 - _globals['_MATERIALIZATIONINTERVAL']._serialized_start=1276 - _globals['_MATERIALIZATIONINTERVAL']._serialized_end=1395 - _globals['_FEATUREVIEWLIST']._serialized_start=1397 - _globals['_FEATUREVIEWLIST']._serialized_end=1461 + _globals['_ONLINECONFIG']._serialized_start=299 + _globals['_ONLINECONFIG']._serialized_end=533 + _globals['_ONLINECONFIG_MODE']._serialized_start=461 + _globals['_ONLINECONFIG_MODE']._serialized_end=493 + _globals['_ONLINECONFIG_WRITEMODE']._serialized_start=495 + _globals['_ONLINECONFIG_WRITEMODE']._serialized_end=533 + _globals['_FEATUREVIEWSPEC']._serialized_start=536 + _globals['_FEATUREVIEWSPEC']._serialized_end=1256 + _globals['_FEATUREVIEWSPEC_TAGSENTRY']._serialized_start=1213 + _globals['_FEATUREVIEWSPEC_TAGSENTRY']._serialized_end=1256 + _globals['_FEATUREVIEWMETA']._serialized_start=1259 + _globals['_FEATUREVIEWMETA']._serialized_end=1560 + _globals['_MATERIALIZATIONINTERVAL']._serialized_start=1562 + _globals['_MATERIALIZATIONINTERVAL']._serialized_end=1681 + _globals['_FEATUREVIEWLIST']._serialized_start=1683 + _globals['_FEATUREVIEWLIST']._serialized_end=1747 # @@protoc_insertion_point(module_scope) diff --git a/sdk/python/feast/protos/feast/core/FeatureView_pb2.pyi b/sdk/python/feast/protos/feast/core/FeatureView_pb2.pyi index e73bc66a555..a264866d0e3 100644 --- a/sdk/python/feast/protos/feast/core/FeatureView_pb2.pyi +++ b/sdk/python/feast/protos/feast/core/FeatureView_pb2.pyi @@ -99,8 +99,72 @@ class FeatureView(google.protobuf.message.Message): global___FeatureView = FeatureView +class OnlineConfig(google.protobuf.message.Message): + """Configuration for how feature values are retained in an online store. + This message is currently a declarative contract; online store implementations + opt into sequence behavior separately. + """ + + DESCRIPTOR: google.protobuf.descriptor.Descriptor + + class _Mode: + ValueType = typing.NewType("ValueType", builtins.int) + V: typing_extensions.TypeAlias = ValueType + + class _ModeEnumTypeWrapper(google.protobuf.internal.enum_type_wrapper._EnumTypeWrapper[OnlineConfig._Mode.ValueType], builtins.type): # noqa: F821 + DESCRIPTOR: google.protobuf.descriptor.EnumDescriptor + LATEST: OnlineConfig._Mode.ValueType # 0 + """Preserve the current behavior: one latest value per entity.""" + SEQUENCE: OnlineConfig._Mode.ValueType # 1 + """Retain an ordered sequence of values per entity.""" + + class Mode(_Mode, metaclass=_ModeEnumTypeWrapper): ... + LATEST: OnlineConfig.Mode.ValueType # 0 + """Preserve the current behavior: one latest value per entity.""" + SEQUENCE: OnlineConfig.Mode.ValueType # 1 + """Retain an ordered sequence of values per entity.""" + + class _WriteMode: + ValueType = typing.NewType("ValueType", builtins.int) + V: typing_extensions.TypeAlias = ValueType + + class _WriteModeEnumTypeWrapper(google.protobuf.internal.enum_type_wrapper._EnumTypeWrapper[OnlineConfig._WriteMode.ValueType], builtins.type): # noqa: F821 + DESCRIPTOR: google.protobuf.descriptor.EnumDescriptor + OVERWRITE: OnlineConfig._WriteMode.ValueType # 0 + """Preserve the current upsert behavior.""" + APPEND: OnlineConfig._WriteMode.ValueType # 1 + """Append a new event without overwriting earlier events.""" + + class WriteMode(_WriteMode, metaclass=_WriteModeEnumTypeWrapper): ... + OVERWRITE: OnlineConfig.WriteMode.ValueType # 0 + """Preserve the current upsert behavior.""" + APPEND: OnlineConfig.WriteMode.ValueType # 1 + """Append a new event without overwriting earlier events.""" + + MODE_FIELD_NUMBER: builtins.int + MAX_LENGTH_FIELD_NUMBER: builtins.int + MAX_AGE_SECONDS_FIELD_NUMBER: builtins.int + WRITE_MODE_FIELD_NUMBER: builtins.int + mode: global___OnlineConfig.Mode.ValueType + max_length: builtins.int + """Maximum number of events retained per entity. 0 means unset.""" + max_age_seconds: builtins.int + """Maximum event age in whole seconds. 0 means unset.""" + write_mode: global___OnlineConfig.WriteMode.ValueType + def __init__( + self, + *, + mode: global___OnlineConfig.Mode.ValueType = ..., + max_length: builtins.int = ..., + max_age_seconds: builtins.int = ..., + write_mode: global___OnlineConfig.WriteMode.ValueType = ..., + ) -> None: ... + def ClearField(self, field_name: typing_extensions.Literal["max_age_seconds", b"max_age_seconds", "max_length", b"max_length", "mode", b"mode", "write_mode", b"write_mode"]) -> None: ... + +global___OnlineConfig = OnlineConfig + class FeatureViewSpec(google.protobuf.message.Message): - """Next available id: 20 + """Next available id: 22 TODO(adchia): refactor common fields from this and ODFV into separate metadata proto """ @@ -141,6 +205,7 @@ class FeatureViewSpec(google.protobuf.message.Message): VERSION_FIELD_NUMBER: builtins.int ORG_FIELD_NUMBER: builtins.int DISABLED_FIELD_NUMBER: builtins.int + ONLINE_CONFIG_FIELD_NUMBER: builtins.int name: builtins.str """Name of the feature view. Must be unique. Not updated.""" project: builtins.str @@ -202,6 +267,9 @@ class FeatureViewSpec(google.protobuf.message.Message): When true, the feature view will not serve online features or be materialized. Defaults to false (enabled) for backward compatibility. """ + @property + def online_config(self) -> global___OnlineConfig: + """Online retention and write semantics for this feature view.""" def __init__( self, *, @@ -225,9 +293,10 @@ class FeatureViewSpec(google.protobuf.message.Message): version: builtins.str = ..., org: builtins.str = ..., disabled: builtins.bool = ..., + online_config: global___OnlineConfig | None = ..., ) -> None: ... - def HasField(self, field_name: typing_extensions.Literal["batch_source", b"batch_source", "feature_transformation", b"feature_transformation", "stream_source", b"stream_source", "ttl", b"ttl"]) -> builtins.bool: ... - def ClearField(self, field_name: typing_extensions.Literal["batch_source", b"batch_source", "description", b"description", "disabled", b"disabled", "enable_validation", b"enable_validation", "entities", b"entities", "entity_columns", b"entity_columns", "feature_transformation", b"feature_transformation", "features", b"features", "mode", b"mode", "name", b"name", "offline", b"offline", "online", b"online", "org", b"org", "owner", b"owner", "project", b"project", "source_views", b"source_views", "stream_source", b"stream_source", "tags", b"tags", "ttl", b"ttl", "version", b"version"]) -> None: ... + def HasField(self, field_name: typing_extensions.Literal["batch_source", b"batch_source", "feature_transformation", b"feature_transformation", "online_config", b"online_config", "stream_source", b"stream_source", "ttl", b"ttl"]) -> builtins.bool: ... + def ClearField(self, field_name: typing_extensions.Literal["batch_source", b"batch_source", "description", b"description", "disabled", b"disabled", "enable_validation", b"enable_validation", "entities", b"entities", "entity_columns", b"entity_columns", "feature_transformation", b"feature_transformation", "features", b"features", "mode", b"mode", "name", b"name", "offline", b"offline", "online", b"online", "online_config", b"online_config", "org", b"org", "owner", b"owner", "project", b"project", "source_views", b"source_views", "stream_source", b"stream_source", "tags", b"tags", "ttl", b"ttl", "version", b"version"]) -> None: ... global___FeatureViewSpec = FeatureViewSpec diff --git a/sdk/python/tests/unit/cli/test_feature_views.py b/sdk/python/tests/unit/cli/test_feature_views.py new file mode 100644 index 00000000000..d9f0dd7d565 --- /dev/null +++ b/sdk/python/tests/unit/cli/test_feature_views.py @@ -0,0 +1,40 @@ +from datetime import timedelta +from unittest.mock import Mock, patch + +import yaml +from click.testing import CliRunner + +from feast import FeatureView, OnlineConfig +from feast.cli.feature_views import feature_views_cmd + + +def _describe(feature_view: FeatureView) -> dict: + store = Mock() + store.get_feature_view.return_value = feature_view + + with patch("feast.cli.feature_views.create_feature_store", return_value=store): + result = CliRunner().invoke(feature_views_cmd, ["describe", feature_view.name]) + + assert result.exit_code == 0, result.output + return yaml.safe_load(result.output) + + +def test_feature_view_describe_shows_sequence_online_config() -> None: + data = _describe( + FeatureView( + name="events", + online_config=OnlineConfig( + mode="sequence", + max_length=50, + max_age=timedelta(days=90), + write_mode="append", + ), + ) + ) + + assert data["spec"]["onlineConfig"] == { + "mode": "sequence", + "maxLength": 50, + "maxAgeSeconds": 90 * 24 * 60 * 60, + "writeMode": "append", + } diff --git a/sdk/python/tests/unit/test_feature_views.py b/sdk/python/tests/unit/test_feature_views.py index dfbb9a9cc07..f61dc340f12 100644 --- a/sdk/python/tests/unit/test_feature_views.py +++ b/sdk/python/tests/unit/test_feature_views.py @@ -13,6 +13,7 @@ from feast.feature_view import FeatureView from feast.field import Field from feast.infra.offline_stores.file_source import FileSource +from feast.online_config import OnlineConfig from feast.protos.feast.core.FeatureView_pb2 import FeatureView as FeatureViewProto from feast.protos.feast.core.FeatureView_pb2 import ( FeatureViewMeta as FeatureViewMetaProto, @@ -101,6 +102,7 @@ def test_hash(): ], source=file_source, ) + feature_view_2 = FeatureView( name="my-feature-view", entities=[], @@ -158,6 +160,41 @@ def test_proto_conversion(): ) +def test_online_config_feature_view_round_trip() -> None: + file_source = FileSource(name="events-source", path="events.parquet") + online_config = OnlineConfig( + mode="sequence", + max_length=50, + max_age=timedelta(days=90), + write_mode="append", + ) + feature_view = FeatureView( + name="events", + entities=[], + schema=[Field(name="value", dtype=Float32)], + source=file_source, + online_config=online_config, + ) + + proto = feature_view.to_proto() + assert proto.spec.HasField("online_config") + assert proto.spec.online_config.mode == proto.spec.online_config.SEQUENCE + assert proto.spec.online_config.max_length == 50 + assert proto.spec.online_config.max_age_seconds == 90 * 24 * 60 * 60 + assert proto.spec.online_config.write_mode == proto.spec.online_config.APPEND + + round_tripped = FeatureView.from_proto(proto) + assert round_tripped.online_config == online_config + assert round_tripped == feature_view + + +def test_online_config_is_absent_by_default() -> None: + feature_view = FeatureView(name="events") + + assert not feature_view.to_proto().spec.HasField("online_config") + assert FeatureView.from_proto(feature_view.to_proto()).online_config is None + + # TODO(felixwang9817): Add tests for field mapping logic. diff --git a/sdk/python/tests/unit/test_online_config.py b/sdk/python/tests/unit/test_online_config.py new file mode 100644 index 00000000000..6d4e4fc8efc --- /dev/null +++ b/sdk/python/tests/unit/test_online_config.py @@ -0,0 +1,55 @@ +from datetime import timedelta + +import pytest + +from feast import OnlineConfig + + +def test_online_config_defaults() -> None: + config = OnlineConfig() + + assert config.mode == "latest" + assert config.max_length is None + assert config.max_age is None + assert config.write_mode == "overwrite" + + +def test_online_config_proto_round_trip() -> None: + config = OnlineConfig( + mode="sequence", + max_length=50, + max_age=timedelta(days=90), + write_mode="append", + ) + + proto = config.to_proto() + assert proto.mode == proto.SEQUENCE + assert proto.max_length == 50 + assert proto.max_age_seconds == 90 * 24 * 60 * 60 + assert proto.write_mode == proto.APPEND + assert OnlineConfig.from_proto(proto) == config + + +@pytest.mark.parametrize( + ("kwargs", "message"), + [ + ({"mode": "invalid"}, "mode must be"), + ({"write_mode": "invalid"}, "write_mode must be"), + ( + {"mode": "sequence", "max_length": 0, "write_mode": "append"}, + "max_length must be a positive integer", + ), + ({"max_age": timedelta(0)}, "max_age must be a positive timedelta"), + ( + {"mode": "sequence", "max_length": 10}, + "mode='sequence' requires write_mode='append'", + ), + ( + {"mode": "sequence", "write_mode": "append"}, + "mode='sequence' requires max_length to be set", + ), + ], +) +def test_online_config_validation(kwargs: dict, message: str) -> None: + with pytest.raises(ValueError, match=message): + OnlineConfig(**kwargs) diff --git a/sdk/python/tests/unit/test_online_config_apply.py b/sdk/python/tests/unit/test_online_config_apply.py new file mode 100644 index 00000000000..f28d2cb679c --- /dev/null +++ b/sdk/python/tests/unit/test_online_config_apply.py @@ -0,0 +1,74 @@ +from datetime import timedelta +from pathlib import Path +from typing import Optional + +from feast import Entity, FeatureStore, FeatureView, Field, OnlineConfig, ValueType +from feast.infra.offline_stores.file_source import FileSource +from feast.infra.online_stores.sqlite import SqliteOnlineStoreConfig +from feast.repo_config import RepoConfig +from feast.types import Float32, Int64 + + +def _feature_store(tmp_path: Path) -> FeatureStore: + return FeatureStore( + config=RepoConfig( + registry=str(tmp_path / "registry.db"), + project="online_config_test", + provider="local", + online_store=SqliteOnlineStoreConfig(path=str(tmp_path / "online.db")), + entity_key_serialization_version=3, + ) + ) + + +def test_apply_persists_updates_and_clears_online_config(tmp_path: Path) -> None: + store = _feature_store(tmp_path) + source = FileSource( + path="events.parquet", + timestamp_field="event_timestamp", + created_timestamp_column="created_timestamp", + ) + entity = Entity(name="event", join_keys=["event_id"], value_type=ValueType.INT64) + schema = [ + Field(name="event_id", dtype=Int64), + Field(name="event_value", dtype=Float32), + ] + + def feature_view(online_config: Optional[OnlineConfig]) -> FeatureView: + return FeatureView( + name="events", + entities=[entity], + schema=schema, + source=source, + online_config=online_config, + ) + + try: + initial_config = OnlineConfig( + mode="sequence", max_length=10, write_mode="append" + ) + store.apply([entity, feature_view(initial_config)]) + assert store.get_feature_view("events").online_config == initial_config + versions_before_config_update = store.list_feature_view_versions("events") + + updated_config = OnlineConfig( + mode="sequence", + max_length=50, + max_age=timedelta(days=90), + write_mode="append", + ) + store.apply([entity, feature_view(updated_config)]) + assert store.get_feature_view("events").online_config == updated_config + assert ( + store.list_feature_view_versions("events") == versions_before_config_update + ) + + store.apply([entity, feature_view(None)]) + stored = store.get_feature_view("events") + assert stored.online_config is None + assert not stored.to_proto().spec.HasField("online_config") + assert ( + store.list_feature_view_versions("events") == versions_before_config_update + ) + finally: + store.teardown() From 591c1ffe20bda6e0387d6b14b3e924f4735eafc1 Mon Sep 17 00:00:00 2001 From: Chaitany Patel Date: Wed, 18 Nov 2026 13:31:58 +0530 Subject: [PATCH 2/3] fix: Preserve online config in batch view copies and registry diffs BatchFeatureView.__copy__ now passes online_config, so version pinning and unpromoted version snapshots keep the configuration. Registry diffing now checks presence for online_config, so feast apply detects switching between no config and OnlineConfig() with defaults. Signed-off-by: Chaitany Patel --- sdk/python/feast/batch_feature_view.py | 1 + sdk/python/feast/diff/registry_diff.py | 18 +++++++++++++++++- .../tests/unit/diff/test_registry_diff.py | 17 +++++++++++++++++ sdk/python/tests/unit/test_feature_views.py | 17 +++++++++++++++++ 4 files changed, 52 insertions(+), 1 deletion(-) diff --git a/sdk/python/feast/batch_feature_view.py b/sdk/python/feast/batch_feature_view.py index b6fd7ffc0be..5bdd46c5c18 100644 --- a/sdk/python/feast/batch_feature_view.py +++ b/sdk/python/feast/batch_feature_view.py @@ -190,6 +190,7 @@ def __copy__(self) -> "BatchFeatureView": aggregations=self.aggregations, enable_validation=self.enable_validation, version=self.version, + online_config=self.online_config, ) fv.enabled = self.enabled fv.state = self.state diff --git a/sdk/python/feast/diff/registry_diff.py b/sdk/python/feast/diff/registry_diff.py index 68fcd856985..f179426158f 100644 --- a/sdk/python/feast/diff/registry_diff.py +++ b/sdk/python/feast/diff/registry_diff.py @@ -122,6 +122,20 @@ def tag_objects_for_keep_delete_update_add( FIELDS_TO_IGNORE = {"project"} +# Message fields where "unset" and "set with all default values" mean different +# things. Protobuf compares both as equal by value, so check presence too. +PRESENCE_AWARE_FIELDS = {"online_config"} + + +def _presence_changed( + current_spec: FeastObjectSpecProto, new_spec: FeastObjectSpecProto, field: str +) -> bool: + if field not in PRESENCE_AWARE_FIELDS: + return False + return cast(Any, current_spec).HasField(field) != cast(Any, new_spec).HasField( + field + ) + def diff_registry_objects( current: FeastObject, new: FeastObject, object_type: FeastObjectType @@ -147,7 +161,9 @@ def diff_registry_objects( for _field in current_spec.DESCRIPTOR.fields: if _field.name in FIELDS_TO_IGNORE: continue - elif getattr(current_spec, _field.name) != getattr(new_spec, _field.name): + elif getattr(current_spec, _field.name) != getattr( + new_spec, _field.name + ) or _presence_changed(current_spec, new_spec, _field.name): if _field.name == "feature_transformation": current_spec = cast(OnDemandFeatureViewSpec, current_spec) new_spec = cast(OnDemandFeatureViewSpec, new_spec) diff --git a/sdk/python/tests/unit/diff/test_registry_diff.py b/sdk/python/tests/unit/diff/test_registry_diff.py index e637537a4d2..9b460c47732 100644 --- a/sdk/python/tests/unit/diff/test_registry_diff.py +++ b/sdk/python/tests/unit/diff/test_registry_diff.py @@ -2,6 +2,7 @@ from feast import Field, PushSource from feast.batch_feature_view import batch_feature_view +from feast.diff.property_diff import TransitionType from feast.diff.registry_diff import ( diff_registry_objects, tag_objects_for_keep_delete_update_add, @@ -10,6 +11,7 @@ from feast.feast_object import ALL_RESOURCE_TYPES from feast.feature_view import FeatureView from feast.on_demand_feature_view import on_demand_feature_view +from feast.online_config import OnlineConfig from feast.permissions.action import AuthzedAction from feast.permissions.permission import Permission from feast.permissions.policy import RoleBasedPolicy @@ -101,6 +103,21 @@ def test_diff_registry_objects_feature_views(simple_dataset_1): } +def test_diff_registry_objects_online_config_presence(): + without_config = FeatureView(name="fv") + with_default_config = FeatureView(name="fv", online_config=OnlineConfig()) + + for current, new in [ + (without_config, with_default_config), + (with_default_config, without_config), + ]: + feast_object_diffs = diff_registry_objects(current, new, "feature view") + assert feast_object_diffs.transition_type == TransitionType.UPDATE + assert [ + p.property_name for p in feast_object_diffs.feast_object_property_diffs + ] == ["online_config"] + + def test_diff_odfv(simple_dataset_1): with prep_file_source(df=simple_dataset_1, timestamp_field="ts_1") as file_source: entity = Entity(name="id", join_keys=["id"]) diff --git a/sdk/python/tests/unit/test_feature_views.py b/sdk/python/tests/unit/test_feature_views.py index f61dc340f12..672a1a57faf 100644 --- a/sdk/python/tests/unit/test_feature_views.py +++ b/sdk/python/tests/unit/test_feature_views.py @@ -483,6 +483,23 @@ def transform_udf(df: pd.DataFrame) -> pd.DataFrame: assert projected.to_proto().spec.HasField("feature_transformation") +def test_batch_feature_view_copy_keeps_online_config() -> None: + online_config = OnlineConfig(mode="sequence", max_length=50, write_mode="append") + bfv = BatchFeatureView( + name="events", + entities=[], + schema=[Field(name="value", dtype=Float32)], + source=FileSource( + name="events-source", + path="events.parquet", + timestamp_field="event_timestamp", + ), + online_config=online_config, + ) + + assert copy.copy(bfv).online_config == online_config + + def test_transformation_mode_serialization(): """ Test that transformation mode is properly serialized to proto and deserialized back. From 95d2cc23b5650ceb71d188100ed77a7ceae96e53 Mon Sep 17 00:00:00 2001 From: Chaitany Patel Date: Sun, 22 Nov 2026 21:06:01 +0530 Subject: [PATCH 3/3] feat: Allow unlimited sequences in OnlineConfig Sequence mode no longer requires max_length. Leaving max_length or max_age unset (proto 0) now means no limit of that kind, so a sequence with neither set keeps every event. Signed-off-by: Chaitany Patel --- docs/getting-started/concepts/feature-view.md | 2 +- protos/feast/core/FeatureView.proto | 4 ++-- sdk/python/feast/online_config.py | 8 ++++---- .../feast/protos/feast/core/FeatureView_pb2.pyi | 4 ++-- sdk/python/tests/unit/test_online_config.py | 13 +++++++++---- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/docs/getting-started/concepts/feature-view.md b/docs/getting-started/concepts/feature-view.md index abb43c60878..5d8efe23d9c 100644 --- a/docs/getting-started/concepts/feature-view.md +++ b/docs/getting-started/concepts/feature-view.md @@ -62,7 +62,7 @@ Feature views are used during ## Online retention configuration -`OnlineConfig` declares whether a feature view uses the current latest-value model or a bounded sequence of historical values per entity. Sequence mode requires append writes and a positive maximum length. An optional maximum age adds a second retention limit. +`OnlineConfig` declares whether a feature view uses the current latest-value model or a sequence of historical values per entity. Sequence mode requires append writes. A maximum length and a maximum age are optional retention limits; leave both unset to keep an unlimited sequence. ```python from datetime import timedelta diff --git a/protos/feast/core/FeatureView.proto b/protos/feast/core/FeatureView.proto index dcc123c9d16..5d9ed95c58e 100644 --- a/protos/feast/core/FeatureView.proto +++ b/protos/feast/core/FeatureView.proto @@ -70,10 +70,10 @@ message OnlineConfig { Mode mode = 1; - // Maximum number of events retained per entity. 0 means unset. + // Maximum number of events retained per entity. 0 means no length limit. int32 max_length = 2; - // Maximum event age in whole seconds. 0 means unset. + // Maximum event age in whole seconds. 0 means no age limit. int64 max_age_seconds = 3; enum WriteMode { diff --git a/sdk/python/feast/online_config.py b/sdk/python/feast/online_config.py index e574da2f088..90f40ad863a 100644 --- a/sdk/python/feast/online_config.py +++ b/sdk/python/feast/online_config.py @@ -27,6 +27,10 @@ class OnlineConfig: Sequence mode is a declarative contract in this foundation release. Online stores must add explicit sequence support before these settings affect data storage or retrieval. + + In sequence mode, ``max_length`` and ``max_age`` are optional retention + limits. Leaving either unset (``None``) means no limit of that kind, so a + sequence with neither set is unlimited. """ mode: str = "latest" @@ -73,10 +77,6 @@ def validate(self) -> None: raise ValueError( "OnlineConfig mode='sequence' requires write_mode='append'." ) - if self.max_length is None: - raise ValueError( - "OnlineConfig mode='sequence' requires max_length to be set." - ) else: if self.write_mode != "overwrite": raise ValueError( diff --git a/sdk/python/feast/protos/feast/core/FeatureView_pb2.pyi b/sdk/python/feast/protos/feast/core/FeatureView_pb2.pyi index a264866d0e3..0a27b33d9d4 100644 --- a/sdk/python/feast/protos/feast/core/FeatureView_pb2.pyi +++ b/sdk/python/feast/protos/feast/core/FeatureView_pb2.pyi @@ -147,9 +147,9 @@ class OnlineConfig(google.protobuf.message.Message): WRITE_MODE_FIELD_NUMBER: builtins.int mode: global___OnlineConfig.Mode.ValueType max_length: builtins.int - """Maximum number of events retained per entity. 0 means unset.""" + """Maximum number of events retained per entity. 0 means no length limit.""" max_age_seconds: builtins.int - """Maximum event age in whole seconds. 0 means unset.""" + """Maximum event age in whole seconds. 0 means no age limit.""" write_mode: global___OnlineConfig.WriteMode.ValueType def __init__( self, diff --git a/sdk/python/tests/unit/test_online_config.py b/sdk/python/tests/unit/test_online_config.py index 6d4e4fc8efc..2459ec7992a 100644 --- a/sdk/python/tests/unit/test_online_config.py +++ b/sdk/python/tests/unit/test_online_config.py @@ -30,6 +30,15 @@ def test_online_config_proto_round_trip() -> None: assert OnlineConfig.from_proto(proto) == config +def test_online_config_sequence_without_limits_is_unlimited() -> None: + config = OnlineConfig(mode="sequence", write_mode="append") + + proto = config.to_proto() + assert proto.max_length == 0 + assert proto.max_age_seconds == 0 + assert OnlineConfig.from_proto(proto) == config + + @pytest.mark.parametrize( ("kwargs", "message"), [ @@ -44,10 +53,6 @@ def test_online_config_proto_round_trip() -> None: {"mode": "sequence", "max_length": 10}, "mode='sequence' requires write_mode='append'", ), - ( - {"mode": "sequence", "write_mode": "append"}, - "mode='sequence' requires max_length to be set", - ), ], ) def test_online_config_validation(kwargs: dict, message: str) -> None: