1010
1111from jinja2 import BaseLoader , Environment
1212
13- from feast .dbt .mapper import map_dbt_type_to_feast_type
13+ from feast .dbt .mapper import (
14+ _resolve_file_path ,
15+ _validate_file_path_template ,
16+ map_dbt_type_to_feast_type ,
17+ )
1418from feast .dbt .parser import DbtModel
1519from feast .types import (
1620 Array ,
9094{% elif data_source_type == 'file' %}
9195{{ source.var_name }} = FileSource(
9296 name="{{ source.name }}",
93- path=" {{ source.path }}" ,
97+ path={{ source.path_literal }},
9498 timestamp_field="{{ source.timestamp_field }}",
9599 description="{{ source.description }}",
96100 tags={{ source.tags }},
@@ -182,6 +186,9 @@ class DbtCodeGenerator:
182186 This class creates complete, importable Python files containing
183187 Entity, DataSource, and FeatureView definitions.
184188
189+ For file sources, ``file_path_template`` optionally replaces the default
190+ ``/data/{model}.parquet`` path, using the dbt model name for ``{model}``.
191+
185192 Example::
186193
187194 generator = DbtCodeGenerator(
@@ -204,10 +211,13 @@ def __init__(
204211 data_source_type : str = "bigquery" ,
205212 timestamp_field : str = "event_timestamp" ,
206213 ttl_days : int = 1 ,
214+ file_path_template : Optional [str ] = None ,
207215 ):
208216 self .data_source_type = data_source_type .lower ()
209217 self .timestamp_field = timestamp_field
210218 self .ttl_days = ttl_days
219+ _validate_file_path_template (file_path_template , self .data_source_type )
220+ self .file_path_template = file_path_template
211221
212222 # Set up Jinja2 environment
213223 self .env = Environment (
@@ -309,7 +319,9 @@ def generate(
309319 source_data ["schema" ] = model .schema
310320 source_data ["table" ] = model .alias
311321 elif self .data_source_type == "file" :
312- source_data ["path" ] = f"/data/{ model .name } .parquet"
322+ source_data ["path_literal" ] = repr (
323+ _resolve_file_path (self .file_path_template , model .name )
324+ )
313325
314326 data_sources .append (source_data )
315327
@@ -389,6 +401,7 @@ def generate_feast_code(
389401 project_name : str = "" ,
390402 exclude_columns : Optional [List [str ]] = None ,
391403 online : bool = True ,
404+ file_path_template : Optional [str ] = None ,
392405) -> str :
393406 """
394407 Convenience function to generate Feast code from dbt models.
@@ -403,6 +416,7 @@ def generate_feast_code(
403416 project_name: Project name for documentation
404417 exclude_columns: Columns to exclude from features
405418 online: Whether to enable online serving
419+ file_path_template: Optional file source path, with {model} replaced by the model name
406420
407421 Returns:
408422 Generated Python code as a string
@@ -411,6 +425,7 @@ def generate_feast_code(
411425 data_source_type = data_source_type ,
412426 timestamp_field = timestamp_field ,
413427 ttl_days = ttl_days ,
428+ file_path_template = file_path_template ,
414429 )
415430
416431 return generator .generate (
0 commit comments