@@ -61,12 +61,12 @@ class OnDemandFeatureView(BaseFeatureView):
6161 maintainer.
6262 """
6363
64- # TODO(adchia): remove inputs from proto and declaration
6564 name : str
6665 features : List [Field ]
6766 source_feature_view_projections : Dict [str , FeatureViewProjection ]
6867 source_request_sources : Dict [str , RequestSource ]
6968 udf : FunctionType
69+ udf_string : str
7070 description : str
7171 tags : Dict [str , str ]
7272 owner : str
@@ -81,6 +81,7 @@ def __init__( # noqa: C901
8181 List [Any ]
8282 ] = None , # Typed as Any because @typechecked can't deal with the List[Union]
8383 udf : Optional [FunctionType ] = None ,
84+ udf_string : str = "" ,
8485 inputs : Optional [
8586 Dict [str , Union [FeatureView , FeatureViewProjection , RequestSource ]]
8687 ] = None ,
@@ -99,8 +100,9 @@ def __init__( # noqa: C901
99100 sources (optional): A map from input source names to the actual input sources,
100101 which may be feature views, or request data sources.
101102 These sources serve as inputs to the udf, which will refer to them by name.
102- udf (optional) : The user defined transformation function, which must take pandas
103+ udf: The user defined transformation function, which must take pandas
103104 dataframes as inputs.
105+ udf_string: The source code version of the udf (for diffing and displaying in Web UI)
104106 inputs (optional): (Deprecated) A map from input source names to the actual input sources,
105107 which may be feature views, feature view projections, or request data sources.
106108 These sources serve as inputs to the udf, which will refer to them by name.
@@ -233,9 +235,8 @@ def __init__( # noqa: C901
233235 odfv_source .name
234236 ] = odfv_source .projection
235237
236- if _udf is None :
237- raise ValueError ("The `udf` parameter must be specified." )
238- self .udf = _udf # type: ignore
238+ self .udf = udf # type: ignore
239+ self .udf_string = udf_string
239240
240241 @property
241242 def proto_class (self ) -> Type [OnDemandFeatureViewProto ]:
@@ -249,6 +250,7 @@ def __copy__(self):
249250 sources = list (self .source_feature_view_projections .values ())
250251 + list (self .source_request_sources .values ()),
251252 udf = self .udf ,
253+ udf_string = self .udf_string ,
252254 description = self .description ,
253255 tags = self .tags ,
254256 owner = self .owner ,
@@ -269,6 +271,7 @@ def __eq__(self, other):
269271 self .source_feature_view_projections
270272 != other .source_feature_view_projections
271273 or self .source_request_sources != other .source_request_sources
274+ or self .udf_string != other .udf_string
272275 or self .udf .__code__ .co_code != other .udf .__code__ .co_code
273276 ):
274277 return False
@@ -305,7 +308,9 @@ def to_proto(self) -> OnDemandFeatureViewProto:
305308 features = [feature .to_proto () for feature in self .features ],
306309 sources = sources ,
307310 user_defined_function = UserDefinedFunctionProto (
308- name = self .udf .__name__ , body = dill .dumps (self .udf , recurse = True ),
311+ name = self .udf .__name__ ,
312+ body = dill .dumps (self .udf , recurse = True ),
313+ body_text = self .udf_string ,
309314 ),
310315 description = self .description ,
311316 tags = self .tags ,
@@ -354,6 +359,7 @@ def from_proto(cls, on_demand_feature_view_proto: OnDemandFeatureViewProto):
354359 udf = dill .loads (
355360 on_demand_feature_view_proto .spec .user_defined_function .body
356361 ),
362+ udf_string = on_demand_feature_view_proto .spec .user_defined_function .body_text ,
357363 description = on_demand_feature_view_proto .spec .description ,
358364 tags = dict (on_demand_feature_view_proto .spec .tags ),
359365 owner = on_demand_feature_view_proto .spec .owner ,
@@ -641,6 +647,7 @@ def mainify(obj):
641647 obj .__module__ = "__main__"
642648
643649 def decorator (user_function ):
650+ udf_string = dill .source .getsource (user_function )
644651 mainify (user_function )
645652 on_demand_feature_view_obj = OnDemandFeatureView (
646653 name = user_function .__name__ ,
@@ -650,6 +657,7 @@ def decorator(user_function):
650657 description = description ,
651658 tags = tags ,
652659 owner = owner ,
660+ udf_string = udf_string ,
653661 )
654662 functools .update_wrapper (
655663 wrapper = on_demand_feature_view_obj , wrapped = user_function
0 commit comments