1
1
from datetime import timedelta
2
- from typing import Any , Callable , Dict , List , Optional , Union
2
+ from typing import Any , Callable , Dict , List , Optional , Union , TYPE_CHECKING
3
3
4
4
from feast .transformation .base import Transformation
5
5
from feast .transformation .mode import TransformationMode
6
6
7
+ if TYPE_CHECKING :
8
+ from feast .feature_view import FeatureView
9
+ from feast .data_source import DataSource
10
+ from feast .field import Field
11
+
7
12
8
13
class TileConfiguration :
9
14
"""
@@ -54,6 +59,8 @@ def __init__(
54
59
udf : Callable [[Any ], Any ],
55
60
udf_string : str ,
56
61
tile_config : TileConfiguration ,
62
+ sources : Optional [List [Union [str , "FeatureView" , "DataSource" ]]] = None ,
63
+ schema : Optional [List ["Field" ]] = None ,
57
64
name : Optional [str ] = None ,
58
65
tags : Optional [Dict [str , str ]] = None ,
59
66
description : str = "" ,
@@ -71,6 +78,8 @@ def __init__(
71
78
owner = owner ,
72
79
)
73
80
self .tile_config = tile_config
81
+ self .sources = sources or []
82
+ self .schema = schema or []
74
83
self .aggregation_functions = aggregation_functions or []
75
84
self .chaining_functions = chaining_functions or []
76
85
@@ -177,6 +186,8 @@ def infer_features(self, *args, **kwargs) -> Any:
177
186
def tiled_transformation (
178
187
tile_size : timedelta ,
179
188
mode : str = "pandas" ,
189
+ sources : Optional [List [Union [str , "FeatureView" , "DataSource" ]]] = None ,
190
+ schema : Optional [List ["Field" ]] = None ,
180
191
overlap : Optional [timedelta ] = None ,
181
192
max_tiles_in_memory : int = 10 ,
182
193
enable_late_data_handling : bool = True ,
@@ -193,6 +204,8 @@ def tiled_transformation(
193
204
Args:
194
205
tile_size: The size of each time tile (e.g., timedelta(hours=1))
195
206
mode: The transformation mode - currently supports "pandas"
207
+ sources: List of source feature views or data sources that this transformation depends on
208
+ schema: List of Field definitions specifying output feature names and data types
196
209
overlap: Optional overlap between tiles for continuity
197
210
max_tiles_in_memory: Maximum number of tiles to keep in memory
198
211
enable_late_data_handling: Whether to handle late-arriving data
@@ -207,11 +220,19 @@ def tiled_transformation(
207
220
@tiled_transformation(
208
221
tile_size=timedelta(hours=1),
209
222
mode="pandas",
223
+ sources=["transaction_source_fv"],
224
+ schema=[
225
+ Field(name="rolling_avg", dtype=Float64),
226
+ Field(name="cumulative_amount", dtype=Float64),
227
+ ],
210
228
overlap=timedelta(minutes=5),
211
229
aggregation_functions=[lambda df: df.groupby('entity_id').sum()]
212
230
)
213
231
def my_tiled_feature(df):
214
- return df.assign(derived_feature=df['value'] * 2)
232
+ return df.assign(
233
+ rolling_avg=df['value'].rolling(window=10).mean(),
234
+ cumulative_amount=df['value'].cumsum()
235
+ )
215
236
"""
216
237
def decorator (user_function ):
217
238
import dill
@@ -238,6 +259,8 @@ def mainify(obj):
238
259
udf = user_function ,
239
260
udf_string = udf_string ,
240
261
tile_config = tile_config ,
262
+ sources = sources ,
263
+ schema = schema ,
241
264
name = name or user_function .__name__ ,
242
265
tags = tags ,
243
266
description = description ,
@@ -251,6 +274,8 @@ def mainify(obj):
251
274
udf = user_function ,
252
275
udf_string = udf_string ,
253
276
tile_config = tile_config ,
277
+ sources = sources ,
278
+ schema = schema ,
254
279
name = name or user_function .__name__ ,
255
280
tags = tags ,
256
281
description = description ,
0 commit comments