Maps dbt models to Feast objects. Supports creating DataSource, Entity, and FeatureView objects from dbt model metadata. Example:: mapper = DbtToFeastMapper(data_source_type="bigquery") data_source = mapper.create_data_source(model) feature_view = mapper.c
| 168 | |
| 169 | |
| 170 | class DbtToFeastMapper: |
| 171 | """ |
| 172 | Maps dbt models to Feast objects. |
| 173 | |
| 174 | Supports creating DataSource, Entity, and FeatureView objects from |
| 175 | dbt model metadata. |
| 176 | |
| 177 | Example:: |
| 178 | |
| 179 | mapper = DbtToFeastMapper(data_source_type="bigquery") |
| 180 | data_source = mapper.create_data_source(model) |
| 181 | feature_view = mapper.create_feature_view( |
| 182 | model, data_source, entity_column="driver_id" |
| 183 | ) |
| 184 | |
| 185 | Args: |
| 186 | data_source_type: Type of data source ('bigquery', 'snowflake', 'file') |
| 187 | timestamp_field: Default timestamp field name |
| 188 | ttl_days: Default TTL in days for feature views |
| 189 | """ |
| 190 | |
| 191 | def __init__( |
| 192 | self, |
| 193 | data_source_type: str = "bigquery", |
| 194 | timestamp_field: str = "event_timestamp", |
| 195 | ttl_days: int = 1, |
| 196 | ): |
| 197 | self.data_source_type = data_source_type.lower() |
| 198 | self.timestamp_field = timestamp_field |
| 199 | self.ttl_days = ttl_days |
| 200 | |
| 201 | def _infer_entity_value_type(self, model: DbtModel, entity_col: str) -> ValueType: |
| 202 | """Infer entity ValueType from dbt model column type.""" |
| 203 | for column in model.columns: |
| 204 | if column.name == entity_col: |
| 205 | feast_type = map_dbt_type_to_feast_type(column.data_type) |
| 206 | return feast_type_to_value_type(feast_type) |
| 207 | return ValueType.UNKNOWN |
| 208 | |
| 209 | def create_data_source( |
| 210 | self, |
| 211 | model: DbtModel, |
| 212 | timestamp_field: Optional[str] = None, |
| 213 | created_timestamp_column: Optional[str] = None, |
| 214 | ) -> Any: |
| 215 | """ |
| 216 | Create a Feast DataSource from a dbt model. |
| 217 | |
| 218 | Args: |
| 219 | model: The DbtModel to create a DataSource from |
| 220 | timestamp_field: Override the default timestamp field |
| 221 | created_timestamp_column: Column for created timestamp (dedup) |
| 222 | |
| 223 | Returns: |
| 224 | A Feast DataSource (BigQuerySource, SnowflakeSource, or FileSource) |
| 225 | |
| 226 | Raises: |
| 227 | ValueError: If data_source_type is not supported |
no outgoing calls