@@ -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 ] = []
@@ -325,6 +354,7 @@ def __copy__(self):
325354 schema = self .features ,
326355 sources = list (self .source_feature_view_projections .values ())
327356 + list (self .source_request_sources .values ()),
357+ input_schema = self .input_schema ,
328358 feature_transformation = self .feature_transformation ,
329359 mode = self .mode ,
330360 description = self .description ,
@@ -334,6 +364,7 @@ def __copy__(self):
334364 singleton = self .singleton ,
335365 version = self .version ,
336366 track_metrics = self .track_metrics ,
367+ aggregations = self .aggregations ,
337368 )
338369 fv .entities = self .entities
339370 fv .features = self .features
@@ -556,7 +587,7 @@ def to_proto(self) -> OnDemandFeatureViewProto:
556587 owner = self .owner ,
557588 write_to_online_store = self .write_to_online_store ,
558589 singleton = self .singleton or False ,
559- aggregations = self .aggregations ,
590+ aggregations = [ agg . to_proto () for agg in self .aggregations ] ,
560591 version = self .version ,
561592 )
562593 return OnDemandFeatureViewProto (spec = spec , meta = meta )
@@ -580,6 +611,19 @@ def from_proto(
580611 # Parse sources from proto
581612 sources = cls ._parse_sources_from_proto (on_demand_feature_view_proto )
582613
614+ # Detect and strip input_schema sentinel from sources
615+ input_schema : Optional [List [Field ]] = None
616+ sources_without_sentinel : List [OnDemandSourceType ] = []
617+ for source in sources :
618+ if (
619+ isinstance (source , RequestSource )
620+ and source .name .startswith (cls ._INPUT_SCHEMA_SOURCE_PREFIX )
621+ ):
622+ input_schema = source .schema
623+ else :
624+ sources_without_sentinel .append (source )
625+ sources = sources_without_sentinel
626+
583627 # Parse transformation from proto
584628 transformation = cls ._parse_transformation_from_proto (
585629 on_demand_feature_view_proto
@@ -602,6 +646,7 @@ def from_proto(
602646 name = on_demand_feature_view_proto .spec .name ,
603647 schema = cls ._parse_features_from_proto (on_demand_feature_view_proto ),
604648 sources = cast (List [OnDemandSourceType ], sources ),
649+ input_schema = input_schema ,
605650 feature_transformation = transformation ,
606651 mode = on_demand_feature_view_proto .spec .mode or "pandas" ,
607652 description = on_demand_feature_view_proto .spec .description ,
@@ -1079,7 +1124,7 @@ def _is_array_type(self, dtype) -> bool:
10791124 """Check if the dtype represents an array type."""
10801125 # Use proper type checking instead of string comparison
10811126 dtype_str = str (dtype )
1082- return "Array" in dtype_str or "List" in dtype_str
1127+ return "Array" in dtype_str or "List" in dtype_str or "Set" in dtype_str
10831128
10841129 def _construct_random_input (
10851130 self , singleton : bool = False
@@ -1211,13 +1256,17 @@ def on_demand_feature_view(
12111256 name : Optional [str ] = None ,
12121257 entities : Optional [List [Entity ]] = None ,
12131258 schema : list [Field ],
1214- sources : list [
1215- Union [
1216- FeatureView ,
1217- RequestSource ,
1218- FeatureViewProjection ,
1259+ sources : Optional [
1260+ list [
1261+ Union [
1262+ FeatureView ,
1263+ RequestSource ,
1264+ FeatureViewProjection ,
1265+ ]
12191266 ]
1220- ],
1267+ ] = None ,
1268+ input_schema : Optional [list [Field ]] = None ,
1269+ aggregations : Optional [List [Aggregation ]] = None ,
12211270 mode : str = "pandas" ,
12221271 description : str = "" ,
12231272 tags : Optional [dict [str , str ]] = None ,
@@ -1239,6 +1288,8 @@ def on_demand_feature_view(
12391288 sources: A map from input source names to the actual input sources, which may be
12401289 feature views, or request data sources. These sources serve as inputs to the udf,
12411290 which will refer to them by name.
1291+ input_schema (optional): A list of Fields describing the schema of the input data
1292+ for aggregation-based views. When provided, sources is not required.
12421293 mode: The mode of execution (e.g,. Pandas or Python Native)
12431294 description (optional): A human-readable description.
12441295 tags (optional): A dictionary of key-value pairs to store arbitrary metadata.
@@ -1266,6 +1317,7 @@ def decorator(user_function):
12661317 on_demand_feature_view_obj = OnDemandFeatureView (
12671318 name = name if name is not None else user_function .__name__ ,
12681319 sources = sources ,
1320+ input_schema = input_schema ,
12691321 schema = schema ,
12701322 mode = mode ,
12711323 description = description ,
@@ -1275,6 +1327,7 @@ def decorator(user_function):
12751327 entities = entities ,
12761328 singleton = singleton ,
12771329 track_metrics = track_metrics ,
1330+ aggregations = aggregations ,
12781331 udf = user_function ,
12791332 udf_string = udf_string ,
12801333 version = version ,
0 commit comments