Skip to content

Commit adf3212

Browse files
authored
chore: Refactor StreamFeatureViewMeta to FeatureViewMeta and dedupe (#2915)
* chore: Refactor StreamFeatureViewMeta to FeatureViewMeta and deduplicate code Signed-off-by: Achal Shah <[email protected]> * ttl_duration Signed-off-by: Achal Shah <[email protected]> * nits Signed-off-by: Achal Shah <[email protected]>
1 parent 38fd001 commit adf3212

File tree

3 files changed

+25
-50
lines changed

3 files changed

+25
-50
lines changed

protos/feast/core/StreamFeatureView.proto

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import "feast/core/Aggregation.proto";
3434
message StreamFeatureView {
3535
// User-specified specifications of this feature view.
3636
StreamFeatureViewSpec spec = 1;
37-
StreamFeatureViewMeta meta = 2;
37+
FeatureViewMeta meta = 2;
3838
}
3939

4040
// Next available id: 17
@@ -90,13 +90,3 @@ message StreamFeatureViewSpec {
9090
string timestamp_field = 16;
9191
}
9292

93-
message StreamFeatureViewMeta {
94-
// Time where this Feature View is created
95-
google.protobuf.Timestamp created_timestamp = 1;
96-
97-
// Time where this Feature View is last updated
98-
google.protobuf.Timestamp last_updated_timestamp = 2;
99-
100-
// List of pairs (start_time, end_time) for which this feature view has been materialized.
101-
repeated MaterializationInterval materialization_intervals = 3;
102-
}

sdk/python/feast/feature_view.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -407,21 +407,8 @@ def to_proto(self) -> FeatureViewProto:
407407
Returns:
408408
A FeatureViewProto protobuf.
409409
"""
410-
meta = FeatureViewMetaProto(materialization_intervals=[])
411-
if self.created_timestamp:
412-
meta.created_timestamp.FromDatetime(self.created_timestamp)
413-
if self.last_updated_timestamp:
414-
meta.last_updated_timestamp.FromDatetime(self.last_updated_timestamp)
415-
for interval in self.materialization_intervals:
416-
interval_proto = MaterializationIntervalProto()
417-
interval_proto.start_time.FromDatetime(interval[0])
418-
interval_proto.end_time.FromDatetime(interval[1])
419-
meta.materialization_intervals.append(interval_proto)
420-
421-
ttl_duration = None
422-
if self.ttl is not None:
423-
ttl_duration = Duration()
424-
ttl_duration.FromTimedelta(self.ttl)
410+
meta = self.to_proto_meta()
411+
ttl_duration = self.get_ttl_duration()
425412

426413
batch_source_proto = self.batch_source.to_proto()
427414
batch_source_proto.data_source_class_type = f"{self.batch_source.__class__.__module__}.{self.batch_source.__class__.__name__}"
@@ -447,6 +434,26 @@ def to_proto(self) -> FeatureViewProto:
447434

448435
return FeatureViewProto(spec=spec, meta=meta)
449436

437+
def to_proto_meta(self):
438+
meta = FeatureViewMetaProto(materialization_intervals=[])
439+
if self.created_timestamp:
440+
meta.created_timestamp.FromDatetime(self.created_timestamp)
441+
if self.last_updated_timestamp:
442+
meta.last_updated_timestamp.FromDatetime(self.last_updated_timestamp)
443+
for interval in self.materialization_intervals:
444+
interval_proto = MaterializationIntervalProto()
445+
interval_proto.start_time.FromDatetime(interval[0])
446+
interval_proto.end_time.FromDatetime(interval[1])
447+
meta.materialization_intervals.append(interval_proto)
448+
return meta
449+
450+
def get_ttl_duration(self):
451+
ttl_duration = None
452+
if self.ttl is not None:
453+
ttl_duration = Duration()
454+
ttl_duration.FromTimedelta(self.ttl)
455+
return ttl_duration
456+
450457
@classmethod
451458
def from_proto(cls, feature_view_proto: FeatureViewProto):
452459
"""

sdk/python/feast/stream_feature_view.py

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from typing import Dict, List, Optional, Tuple, Union
77

88
import dill
9-
from google.protobuf.duration_pb2 import Duration
109
from typeguard import typechecked
1110

1211
from feast import utils
@@ -16,18 +15,12 @@
1615
from feast.feature_view import FeatureView
1716
from feast.field import Field
1817
from feast.protos.feast.core.DataSource_pb2 import DataSource as DataSourceProto
19-
from feast.protos.feast.core.FeatureView_pb2 import (
20-
MaterializationInterval as MaterializationIntervalProto,
21-
)
2218
from feast.protos.feast.core.OnDemandFeatureView_pb2 import (
2319
UserDefinedFunction as UserDefinedFunctionProto,
2420
)
2521
from feast.protos.feast.core.StreamFeatureView_pb2 import (
2622
StreamFeatureView as StreamFeatureViewProto,
2723
)
28-
from feast.protos.feast.core.StreamFeatureView_pb2 import (
29-
StreamFeatureViewMeta as StreamFeatureViewMetaProto,
30-
)
3124
from feast.protos.feast.core.StreamFeatureView_pb2 import (
3225
StreamFeatureViewSpec as StreamFeatureViewSpecProto,
3326
)
@@ -170,23 +163,8 @@ def __hash__(self) -> int:
170163
return super().__hash__()
171164

172165
def to_proto(self):
173-
meta = StreamFeatureViewMetaProto(materialization_intervals=[])
174-
if self.created_timestamp:
175-
meta.created_timestamp.FromDatetime(self.created_timestamp)
176-
177-
if self.last_updated_timestamp:
178-
meta.last_updated_timestamp.FromDatetime(self.last_updated_timestamp)
179-
180-
for interval in self.materialization_intervals:
181-
interval_proto = MaterializationIntervalProto()
182-
interval_proto.start_time.FromDatetime(interval[0])
183-
interval_proto.end_time.FromDatetime(interval[1])
184-
meta.materialization_intervals.append(interval_proto)
185-
186-
ttl_duration = None
187-
if self.ttl is not None:
188-
ttl_duration = Duration()
189-
ttl_duration.FromTimedelta(self.ttl)
166+
meta = self.to_proto_meta()
167+
ttl_duration = self.get_ttl_duration()
190168

191169
batch_source_proto = None
192170
if self.batch_source:

0 commit comments

Comments
 (0)