@@ -155,6 +155,21 @@ def __str__(self):
155155 def __hash__ (self ):
156156 return hash ((id (self ), self .name ))
157157
158+ def __copy__ (self ):
159+ fv = FeatureView (
160+ name = self .name ,
161+ entities = self .entities ,
162+ ttl = self .ttl ,
163+ input = self .input ,
164+ batch_source = self .batch_source ,
165+ stream_source = self .stream_source ,
166+ features = self .features ,
167+ tags = self .tags ,
168+ online = self .online ,
169+ )
170+ fv .projection = copy .copy (self .projection )
171+ return fv
172+
158173 def __getitem__ (self , item ):
159174 assert isinstance (item , list )
160175
@@ -163,7 +178,8 @@ def __getitem__(self, item):
163178 if feature .name in item :
164179 referenced_features .append (feature )
165180
166- self .projection .features = referenced_features
181+ cp = self .__copy__ ()
182+ cp .projection .features = referenced_features
167183
168184 return self
169185
@@ -207,30 +223,54 @@ def is_valid(self):
207223
208224 def with_name (self , name : str ):
209225 """
210- Produces a copy of this FeatureView with the passed name.
226+ Renames this feature view by returning a copy of this feature view with an alias
227+ set for the feature view name. This rename operation is only used as part of query
228+ operations and will not modify the underlying FeatureView.
211229
212230 Args:
213231 name: Name to assign to the FeatureView copy.
214232
215233 Returns:
216234 A copy of this FeatureView with the name replaced with the 'name' input.
217235 """
218- fv = FeatureView (
219- name = self .name ,
220- entities = self .entities ,
221- ttl = self .ttl ,
222- input = self .input ,
223- batch_source = self .batch_source ,
224- stream_source = self .stream_source ,
225- features = self .features ,
226- tags = self .tags ,
227- online = self .online ,
228- )
236+ cp = self .__copy__ ()
237+ cp .projection .name_alias = name
229238
230- fv .set_projection (copy .copy (self .projection ))
231- fv .projection .name_to_use = name
239+ return cp
232240
233- return fv
241+ def with_projection (self , feature_view_projection : FeatureViewProjection ):
242+ """
243+ Sets the feature view projection by returning a copy of this feature view
244+ with its projection set to the given projection. A projection is an
245+ object that stores the modifications to a feature view that is used during
246+ query operations.
247+
248+ Args:
249+ feature_view_projection: The FeatureViewProjection object to link to this
250+ OnDemandFeatureView.
251+
252+ Returns:
253+ A copy of this FeatureView with its projection replaced with the 'feature_view_projection'
254+ argument.
255+ """
256+ if feature_view_projection .name != self .name :
257+ raise ValueError (
258+ f"The projection for the { self .name } FeatureView cannot be applied because it differs in name. "
259+ f"The projection is named { feature_view_projection .name } and the name indicates which "
260+ "FeatureView the projection is for."
261+ )
262+
263+ for feature in feature_view_projection .features :
264+ if feature not in self .features :
265+ raise ValueError (
266+ f"The projection for { self .name } cannot be applied because it contains { feature .name } which the "
267+ "FeatureView doesn't have."
268+ )
269+
270+ cp = self .__copy__ ()
271+ cp .projection = feature_view_projection
272+
273+ return cp
234274
235275 def to_proto (self ) -> FeatureViewProto :
236276 """
@@ -416,31 +456,3 @@ def infer_features_from_batch_source(self, config: RepoConfig):
416456 "FeatureView" ,
417457 f"Could not infer Features for the FeatureView named { self .name } ." ,
418458 )
419-
420- def set_projection (self , feature_view_projection : FeatureViewProjection ) -> None :
421- """
422- Setter for the projection object held by this FeatureView. A projection is an
423- object that stores the modifications to a FeatureView that is applied to the FeatureView
424- when the FeatureView is used such as during feature_store.get_historical_features.
425- This method also performs checks to ensure the projection is consistent with this
426- FeatureView before doing the set.
427-
428- Args:
429- feature_view_projection: The FeatureViewProjection object to set this FeatureView's
430- 'projection' field to.
431- """
432- if feature_view_projection .name != self .name :
433- raise ValueError (
434- f"The projection for the { self .name } FeatureView cannot be applied because it differs in name. "
435- f"The projection is named { feature_view_projection .name } and the name indicates which "
436- "FeatureView the projection is for."
437- )
438-
439- for feature in feature_view_projection .features :
440- if feature not in self .features :
441- raise ValueError (
442- f"The projection for { self .name } cannot be applied because it contains { feature .name } which the "
443- "FeatureView doesn't have."
444- )
445-
446- self .projection = feature_view_projection
0 commit comments