@@ -134,6 +134,7 @@ class OnDemandFeatureView(BaseFeatureView):
134134 """
135135
136136 _TRACK_METRICS_TAG = "feast:track_metrics"
137+ _INPUT_SCHEMA_SOURCE_PREFIX = "__input_schema__"
137138
138139 name : str
139140 entities : Optional [List [str ]]
@@ -158,7 +159,8 @@ def __init__( # noqa: C901
158159 name : str ,
159160 entities : Optional [List [Entity ]] = None ,
160161 schema : Optional [List [Field ]] = None ,
161- sources : List [OnDemandSourceType ],
162+ sources : Optional [List [OnDemandSourceType ]] = None ,
163+ input_schema : Optional [List [Field ]] = None ,
162164 udf : Optional [FunctionType ] = None ,
163165 udf_string : Optional [str ] = "" ,
164166 feature_transformation : Optional [Transformation ] = None ,
@@ -183,6 +185,9 @@ def __init__( # noqa: C901
183185 sources: A map from input source names to the actual input sources, which may be
184186 feature views, or request data sources. These sources serve as inputs to the udf,
185187 which will refer to them by name.
188+ input_schema (optional): A list of Fields describing the schema of the input data
189+ for aggregation-based views. When provided, sources is not required — an
190+ internal RequestSource will be created automatically.
186191 udf: The user defined transformation function, which must take pandas
187192 dataframes as inputs.
188193 udf_string: The source code version of the udf (for diffing and displaying in Web UI)
@@ -214,15 +219,39 @@ def __init__( # noqa: C901
214219 self .version = version
215220 schema = schema or []
216221 self .entities = [e .name for e in entities ] if entities else [DUMMY_ENTITY_NAME ]
217- self .sources = sources
222+ self .input_schema = input_schema
218223 self .mode = mode .lower ()
219224 self .udf = udf
220225 self .udf_string = udf_string
221226 self .source_feature_view_projections : dict [str , FeatureViewProjection ] = {}
222227 self .source_request_sources : dict [str , RequestSource ] = {}
223228
229+ # Strip any existing sentinel from sources (handles __copy__ round-trip)
230+ effective_sources : List [OnDemandSourceType ] = [
231+ s
232+ for s in (sources or [])
233+ if not (
234+ isinstance (s , RequestSource )
235+ and s .name .startswith (self ._INPUT_SCHEMA_SOURCE_PREFIX )
236+ )
237+ ]
238+
239+ if input_schema is not None :
240+ # Automatically create an internal RequestSource from input_schema
241+ sentinel = RequestSource (
242+ name = f"{ self ._INPUT_SCHEMA_SOURCE_PREFIX } { name } " ,
243+ schema = input_schema ,
244+ )
245+ self .source_request_sources [sentinel .name ] = sentinel
246+ elif not effective_sources :
247+ raise ValueError (
248+ "Either 'sources' or 'input_schema' must be provided for OnDemandFeatureView."
249+ )
250+
251+ self .sources = effective_sources
252+
224253 # Process each source with explicit type handling
225- for odfv_source in sources :
254+ for odfv_source in effective_sources :
226255 self ._add_source_to_collections (odfv_source )
227256
228257 features : List [Field ] = []
@@ -328,6 +357,7 @@ def __copy__(self):
328357 schema = self .features ,
329358 sources = list (self .source_feature_view_projections .values ())
330359 + list (self .source_request_sources .values ()),
360+ input_schema = self .input_schema ,
331361 feature_transformation = self .feature_transformation ,
332362 mode = self .mode ,
333363 description = self .description ,
@@ -337,6 +367,7 @@ def __copy__(self):
337367 singleton = self .singleton ,
338368 version = self .version ,
339369 track_metrics = self .track_metrics ,
370+ aggregations = self .aggregations ,
340371 )
341372 fv .entities = self .entities
342373 fv .features = self .features
@@ -559,7 +590,7 @@ def to_proto(self) -> OnDemandFeatureViewProto:
559590 owner = self .owner ,
560591 write_to_online_store = self .write_to_online_store ,
561592 singleton = self .singleton or False ,
562- aggregations = self .aggregations ,
593+ aggregations = [ agg . to_proto () for agg in self .aggregations ] ,
563594 version = self .version ,
564595 )
565596 return OnDemandFeatureViewProto (spec = spec , meta = meta )
@@ -585,6 +616,19 @@ def from_proto(
585616 on_demand_feature_view_proto , skip_udf = skip_udf
586617 )
587618
619+ # Detect and strip input_schema sentinel from sources
620+ input_schema : Optional [List [Field ]] = None
621+ sources_without_sentinel : List [OnDemandSourceType ] = []
622+ for source in sources :
623+ if (
624+ isinstance (source , RequestSource )
625+ and source .name .startswith (cls ._INPUT_SCHEMA_SOURCE_PREFIX )
626+ ):
627+ input_schema = source .schema
628+ else :
629+ sources_without_sentinel .append (source )
630+ sources = sources_without_sentinel
631+
588632 # Parse transformation from proto (skip UDF deserialization if requested)
589633 transformation = cls ._parse_transformation_from_proto (
590634 on_demand_feature_view_proto , skip_udf = skip_udf
@@ -607,6 +651,7 @@ def from_proto(
607651 name = on_demand_feature_view_proto .spec .name ,
608652 schema = cls ._parse_features_from_proto (on_demand_feature_view_proto ),
609653 sources = cast (List [OnDemandSourceType ], sources ),
654+ input_schema = input_schema ,
610655 feature_transformation = transformation ,
611656 mode = on_demand_feature_view_proto .spec .mode or "pandas" ,
612657 description = on_demand_feature_view_proto .spec .description ,
@@ -1092,7 +1137,7 @@ def _is_array_type(self, dtype) -> bool:
10921137 """Check if the dtype represents an array type."""
10931138 # Use proper type checking instead of string comparison
10941139 dtype_str = str (dtype )
1095- return "Array" in dtype_str or "List" in dtype_str
1140+ return "Array" in dtype_str or "List" in dtype_str or "Set" in dtype_str
10961141
10971142 def _construct_random_input (
10981143 self , singleton : bool = False
@@ -1224,13 +1269,17 @@ def on_demand_feature_view(
12241269 name : Optional [str ] = None ,
12251270 entities : Optional [List [Entity ]] = None ,
12261271 schema : list [Field ],
1227- sources : list [
1228- Union [
1229- FeatureView ,
1230- RequestSource ,
1231- FeatureViewProjection ,
1272+ sources : Optional [
1273+ list [
1274+ Union [
1275+ FeatureView ,
1276+ RequestSource ,
1277+ FeatureViewProjection ,
1278+ ]
12321279 ]
1233- ],
1280+ ] = None ,
1281+ input_schema : Optional [list [Field ]] = None ,
1282+ aggregations : Optional [List [Aggregation ]] = None ,
12341283 mode : str = "pandas" ,
12351284 description : str = "" ,
12361285 tags : Optional [dict [str , str ]] = None ,
@@ -1252,6 +1301,8 @@ def on_demand_feature_view(
12521301 sources: A map from input source names to the actual input sources, which may be
12531302 feature views, or request data sources. These sources serve as inputs to the udf,
12541303 which will refer to them by name.
1304+ input_schema (optional): A list of Fields describing the schema of the input data
1305+ for aggregation-based views. When provided, sources is not required.
12551306 mode: The mode of execution (e.g,. Pandas or Python Native)
12561307 description (optional): A human-readable description.
12571308 tags (optional): A dictionary of key-value pairs to store arbitrary metadata.
@@ -1279,6 +1330,7 @@ def decorator(user_function):
12791330 on_demand_feature_view_obj = OnDemandFeatureView (
12801331 name = name if name is not None else user_function .__name__ ,
12811332 sources = sources ,
1333+ input_schema = input_schema ,
12821334 schema = schema ,
12831335 mode = mode ,
12841336 description = description ,
@@ -1288,6 +1340,7 @@ def decorator(user_function):
12881340 entities = entities ,
12891341 singleton = singleton ,
12901342 track_metrics = track_metrics ,
1343+ aggregations = aggregations ,
12911344 udf = user_function ,
12921345 udf_string = udf_string ,
12931346 version = version ,
0 commit comments