Generate Python code for Feast objects from dbt models. Args: models: List of DbtModel objects to generate code for entity_columns: Entity column name(s) - single string or list of strings manifest_path: Path to the dbt manifest (for documentatio
(
self,
models: List[DbtModel],
entity_columns: Union[str, List[str]],
manifest_path: str = "",
project_name: str = "",
exclude_columns: Optional[List[str]] = None,
online: bool = True,
)
| 218 | self.template = self.env.from_string(FEAST_FILE_TEMPLATE) |
| 219 | |
| 220 | def generate( |
| 221 | self, |
| 222 | models: List[DbtModel], |
| 223 | entity_columns: Union[str, List[str]], |
| 224 | manifest_path: str = "", |
| 225 | project_name: str = "", |
| 226 | exclude_columns: Optional[List[str]] = None, |
| 227 | online: bool = True, |
| 228 | ) -> str: |
| 229 | """ |
| 230 | Generate Python code for Feast objects from dbt models. |
| 231 | |
| 232 | Args: |
| 233 | models: List of DbtModel objects to generate code for |
| 234 | entity_columns: Entity column name(s) - single string or list of strings |
| 235 | manifest_path: Path to the dbt manifest (for documentation) |
| 236 | project_name: dbt project name (for documentation) |
| 237 | exclude_columns: Columns to exclude from features |
| 238 | online: Whether to enable online serving |
| 239 | |
| 240 | Returns: |
| 241 | Generated Python code as a string |
| 242 | """ |
| 243 | # Normalize entity_columns to list |
| 244 | entity_cols: List[str] = ( |
| 245 | [entity_columns] if isinstance(entity_columns, str) else entity_columns |
| 246 | ) |
| 247 | |
| 248 | if not entity_cols: |
| 249 | raise ValueError("At least one entity column must be specified") |
| 250 | |
| 251 | # Note: entity columns should NOT be excluded - FeatureView.__init__ |
| 252 | # expects entity columns to be in the schema and will extract them |
| 253 | excluded = {self.timestamp_field} |
| 254 | if exclude_columns: |
| 255 | excluded.update(exclude_columns) |
| 256 | |
| 257 | # Collect all Feast types used for imports |
| 258 | type_imports: Set[str] = set() |
| 259 | |
| 260 | # Prepare entity data - create one entity per entity column |
| 261 | entities = [] |
| 262 | entity_vars = [] # Track variable names for feature views |
| 263 | for entity_col in entity_cols: |
| 264 | entity_var = _make_var_name(entity_col) |
| 265 | entity_vars.append(entity_var) |
| 266 | entities.append( |
| 267 | { |
| 268 | "var_name": entity_var, |
| 269 | "name": entity_col, |
| 270 | "join_key": entity_col, |
| 271 | "description": "Entity key for dbt models", |
| 272 | "tags": {"source": "dbt"}, |
| 273 | } |
| 274 | ) |
| 275 | |
| 276 | # Prepare data sources and feature views |
| 277 | data_sources = [] |