@@ -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
@@ -310,6 +313,7 @@ def to_proto(self) -> OnDemandFeatureViewProto:
310313 user_defined_function = UserDefinedFunctionProto (
311314 name = self .udf .__name__ ,
312315 body = dill .dumps (self .udf , recurse = True ),
316+ body_text = self .udf_string ,
313317 ),
314318 description = self .description ,
315319 tags = self .tags ,
@@ -362,6 +366,7 @@ def from_proto(cls, on_demand_feature_view_proto: OnDemandFeatureViewProto):
362366 udf = dill .loads (
363367 on_demand_feature_view_proto .spec .user_defined_function .body
364368 ),
369+ udf_string = on_demand_feature_view_proto .spec .user_defined_function .body_text ,
365370 description = on_demand_feature_view_proto .spec .description ,
366371 tags = dict (on_demand_feature_view_proto .spec .tags ),
367372 owner = on_demand_feature_view_proto .spec .owner ,
@@ -651,6 +656,7 @@ def mainify(obj):
651656 obj .__module__ = "__main__"
652657
653658 def decorator (user_function ):
659+ udf_string = dill .source .getsource (user_function )
654660 mainify (user_function )
655661 on_demand_feature_view_obj = OnDemandFeatureView (
656662 name = user_function .__name__ ,
@@ -660,6 +666,7 @@ def decorator(user_function):
660666 description = description ,
661667 tags = tags ,
662668 owner = owner ,
669+ udf_string = udf_string ,
663670 )
664671 functools .update_wrapper (
665672 wrapper = on_demand_feature_view_obj , wrapped = user_function
0 commit comments