GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — feast/sdk/python/feast/repo_config.py at master · luodinglin/feast Expand file tree/ Copy pathrepo_config.pyMore file actions 548 lines (448 loc) · 23 KB / Copy pathrepo_config.pyFile metadata and controls548 lines (448 loc) · 23 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 import logging import os import warnings from pathlib import Path from typing import Any, Dict, Optional import yaml from pydantic import ( BaseModel, ConfigDict, Field, StrictInt, StrictStr, ValidationError, field_validator, model_validator, ) from feast.errors import ( FeastFeatureServerTypeInvalidError, FeastFeatureServerTypeSetError, FeastOfflineStoreInvalidName, FeastOnlineStoreInvalidName, FeastProviderNotSetError, FeastRegistryNotSetError, FeastRegistryTypeInvalidError, ) from feast.importer import import_class from feast.usage import log_exceptions warnings.simplefilter("once", RuntimeWarning) _logger = logging.getLogger(__name__) # These dict exists so that: # - existing values for the online store type in featurestore.yaml files continue to work in a backwards compatible way # - first party and third party implementations can use the same class loading code path. REGISTRY_CLASS_FOR_TYPE = { "file": "feast.infra.registry.registry.Registry", "sql": "feast.infra.registry.sql.SqlRegistry", "snowflake.registry": "feast.infra.registry.snowflake.SnowflakeRegistry", "remote": "feast.infra.registry.remote.RemoteRegistry", } BATCH_ENGINE_CLASS_FOR_TYPE = { "local": "feast.infra.materialization.local_engine.LocalMaterializationEngine", "snowflake.engine": "feast.infra.materialization.snowflake_engine.SnowflakeMaterializationEngine", "lambda": "feast.infra.materialization.aws_lambda.lambda_engine.LambdaMaterializationEngine", "k8s": "feast.infra.materialization.kubernetes.kubernetes_materialization_engine.KubernetesMaterializationEngine", "spark.engine": "feast.infra.materialization.contrib.spark.spark_materialization_engine.SparkMaterializationEngine", } ONLINE_STORE_CLASS_FOR_TYPE = { "sqlite": "feast.infra.online_stores.sqlite.SqliteOnlineStore", "datastore": "feast.infra.online_stores.datastore.DatastoreOnlineStore", "redis": "feast.infra.online_stores.redis.RedisOnlineStore", "dynamodb": "feast.infra.online_stores.dynamodb.DynamoDBOnlineStore", "snowflake.online": "feast.infra.online_stores.snowflake.SnowflakeOnlineStore", "bigtable": "feast.infra.online_stores.bigtable.BigtableOnlineStore", "postgres": "feast.infra.online_stores.contrib.postgres.PostgreSQLOnlineStore", "hbase": "feast.infra.online_stores.contrib.hbase_online_store.hbase.HbaseOnlineStore", "cassandra": "feast.infra.online_stores.contrib.cassandra_online_store.cassandra_online_store.CassandraOnlineStore", "mysql": "feast.infra.online_stores.contrib.mysql_online_store.mysql.MySQLOnlineStore", "rockset": "feast.infra.online_stores.contrib.rockset_online_store.rockset.RocksetOnlineStore", "hazelcast": "feast.infra.online_stores.contrib.hazelcast_online_store.hazelcast_online_store.HazelcastOnlineStore", "ikv": "feast.infra.online_stores.contrib.ikv_online_store.ikv.IKVOnlineStore", } OFFLINE_STORE_CLASS_FOR_TYPE = { "file": "feast.infra.offline_stores.file.FileOfflineStore", "bigquery": "feast.infra.offline_stores.bigquery.BigQueryOfflineStore", "redshift": "feast.infra.offline_stores.redshift.RedshiftOfflineStore", "snowflake.offline": "feast.infra.offline_stores.snowflake.SnowflakeOfflineStore", "spark": "feast.infra.offline_stores.contrib.spark_offline_store.spark.SparkOfflineStore", "trino": "feast.infra.offline_stores.contrib.trino_offline_store.trino.TrinoOfflineStore", "postgres": "feast.infra.offline_stores.contrib.postgres_offline_store.postgres.PostgreSQLOfflineStore", "athena": "feast.infra.offline_stores.contrib.athena_offline_store.athena.AthenaOfflineStore", "mssql": "feast.infra.offline_stores.contrib.mssql_offline_store.mssql.MsSqlServerOfflineStore", "duckdb": "feast.infra.offline_stores.duckdb.DuckDBOfflineStore", } FEATURE_SERVER_CONFIG_CLASS_FOR_TYPE = { "aws_lambda": "feast.infra.feature_servers.aws_lambda.config.AwsLambdaFeatureServerConfig", "gcp_cloudrun": "feast.infra.feature_servers.gcp_cloudrun.config.GcpCloudRunFeatureServerConfig", "local": "feast.infra.feature_servers.local_process.config.LocalFeatureServerConfig", } FEATURE_SERVER_TYPE_FOR_PROVIDER = { "aws": "aws_lambda", "gcp": "gcp_cloudrun", "local": "local", } class FeastBaseModel(BaseModel): """Feast Pydantic Configuration Class""" model_config = ConfigDict(arbitrary_types_allowed=True, extra="allow") class FeastConfigBaseModel(BaseModel): """Feast Pydantic Configuration Class""" model_config = ConfigDict(arbitrary_types_allowed=True, extra="forbid") class RegistryConfig(FeastBaseModel): """Metadata Store Configuration. Configuration that relates to reading from and writing to the Feast registry.""" registry_type: StrictStr = "file" """ str: Provider name or a class name that implements Registry.""" registry_store_type: Optional[StrictStr] = None """ str: Provider name or a class name that implements RegistryStore. """ path: StrictStr = "" """ str: Path to metadata store. If registry_type is 'file', then an be a local path, or remote object storage path, e.g. a GCS URI If registry_type is 'sql', then this is a database URL as expected by SQLAlchemy """ cache_ttl_seconds: StrictInt = 600 """int: The cache TTL is the amount of time registry state will be cached in memory. If this TTL is exceeded then the registry will be refreshed when any feature store method asks for access to registry state. The TTL can be set to infinity by setting TTL to 0 seconds, which means the cache will only be loaded once and will never expire. Users can manually refresh the cache by calling feature_store.refresh_registry() """ s3_additional_kwargs: Optional[Dict[str, str]] = None """ Dict[str, str]: Extra arguments to pass to boto3 when writing the registry file to S3. """ sqlalchemy_config_kwargs: Dict[str, Any] = {} """ Dict[str, Any]: Extra arguments to pass to SQLAlchemy.create_engine. """ class RepoConfig(FeastBaseModel): """Repo config. Typically loaded from `feature_store.yaml`""" project: StrictStr """ str: Feast project id. This can be any alphanumeric string up to 16 characters. You can have multiple independent feature repositories deployed to the same cloud provider account, as long as they have different project ids. """ provider: StrictStr """ str: local or gcp or aws """ registry_config: Any = Field(alias="registry", default="data/registry.db") """ Configures the registry. Can be: 1. str: a path to a file based registry (a local path, or remote object storage path, e.g. a GCS URI) 2. RegistryConfig: A fully specified file based registry or SQL based registry 3. SnowflakeRegistryConfig: Using a Snowflake table to store the registry """ online_config: Any = Field(None, alias="online_store") """ OnlineStoreConfig: Online store configuration (optional depending on provider) """ offline_config: Any = Field(None, alias="offline_store") """ OfflineStoreConfig: Offline store configuration (optional depending on provider) """ batch_engine_config: Any = Field(None, alias="batch_engine") """ BatchMaterializationEngine: Batch materialization configuration (optional depending on provider)""" feature_server: Optional[Any] = None """ FeatureServerConfig: Feature server configuration (optional depending on provider) """ flags: Any = None """ Flags (deprecated field): Feature flags for experimental features """ repo_path: Optional[Path] = None entity_key_serialization_version: StrictInt = 1 """ Entity key serialization version: This version is used to control what serialization scheme is used when writing data to the online store. A value <= 1 uses the serialization scheme used by feast up to Feast 0.22. A value of 2 uses a newer serialization scheme, supported as of Feast 0.23. The main difference between the two scheme is that the serialization scheme v1 stored `long` values as `int`s, which would result in errors trying to serialize a range of values. v2 fixes this error, but v1 is kept around to ensure backwards compatibility - specifically the ability to read feature values for entities that have already been written into the online store. """ coerce_tz_aware: Optional[bool] = True """ If True, coerces entity_df timestamp columns to be timezone aware (to UTC by default). """ def __init__(self, **data: Any): super().__init__(**data) self._registry = None if "registry" not in data: raise FeastRegistryNotSetError() self.registry_config = data["registry"] self._offline_store = None if "offline_store" in data: self.offline_config = data["offline_store"] else: if data["provider"] == "local": self.offline_config = "file" elif data["provider"] == "gcp": self.offline_config = "bigquery" elif data["provider"] == "aws": self.offline_config = "redshift" elif data["provider"] == "azure": self.offline_config = "mssql" self._online_store = None if "online_store" in data: self.online_config = data["online_store"] else: if data["provider"] == "local": self.online_config = "sqlite" elif data["provider"] == "gcp": self.online_config = "datastore" elif data["provider"] == "aws": self.online_config = "dynamodb" elif data["provider"] == "rockset": self.online_config = "rockset" self._batch_engine = None if "batch_engine" in data: self.batch_engine_config = data["batch_engine"] elif "batch_engine_config" in data: self.batch_engine_config = data["batch_engine_config"] else: # Defaults to using local in-process materialization engine. self.batch_engine_config = "local" if isinstance(self.feature_server, Dict): self.feature_server = get_feature_server_config_from_type( self.feature_server["type"] )(**self.feature_server) if self.entity_key_serialization_version <= 1: warnings.warn( "`entity_key_serialization_version` is either not specified in the feature_store.yaml, " "or is specified to a value <= 1." "This serialization version may cause errors when trying to write fields with the `Long` data type" " into the online store. Specifying `entity_key_serialization_version` to 2 is recommended for" " new projects. ", RuntimeWarning, ) @property def registry(self): if not self._registry: if isinstance(self.registry_config, Dict): if "registry_type" in self.registry_config: self._registry = get_registry_config_from_type( self.registry_config["registry_type"] )(**self.registry_config) else: # This may be a custom registry store, which does not need a 'registry_type' self._registry = RegistryConfig(**self.registry_config) elif isinstance(self.registry_config, str): # User passed in just a path to file registry self._registry = get_registry_config_from_type("file")( path=self.registry_config ) elif self.registry_config: self._registry = self.registry_config return self._registry @property def offline_store(self): if not self._offline_store: if isinstance(self.offline_config, Dict): self._offline_store = get_offline_config_from_type( self.offline_config["type"] )(**self.offline_config) elif isinstance(self.offline_config, str): self._offline_store = get_offline_config_from_type( self.offline_config )() elif self.offline_config: self._offline_store = self.offline_config return self._offline_store @property def online_store(self): if not self._online_store: if isinstance(self.online_config, Dict): self._online_store = get_online_config_from_type( self.online_config["type"] )(**self.online_config) elif isinstance(self.online_config, str): self._online_store = get_online_config_from_type(self.online_config)() elif self.online_config: self._online_store = self.online_config return self._online_store @property def batch_engine(self): if not self._batch_engine: if isinstance(self.batch_engine_config, Dict): self._batch_engine = get_batch_engine_config_from_type( self.batch_engine_config["type"] )(**self.batch_engine_config) elif isinstance(self.batch_engine_config, str): self._batch_engine = get_batch_engine_config_from_type( self.batch_engine_config )() elif self.batch_engine_config: self._batch_engine = self._batch_engine return self._batch_engine @model_validator(mode="before") @log_exceptions def _validate_online_store_config(cls, values: Any) -> Any: # This method will validate whether the online store configurations are set correctly. This explicit validation # is necessary because Pydantic Unions throw very verbose and cryptic exceptions. We also use this method to # impute the default online store type based on the selected provider. For the time being this method should be # considered tech debt until we can implement https://github.com/samuelcolvin/pydantic/issues/619 or a more # granular configuration system # Set empty online_store config if it isn't set explicitly if "online_store" not in values: values["online_store"] = dict() # Skip if we aren't creating the configuration from a dict or online store is null or it is a string like "None" or "null" if not isinstance(values["online_store"], Dict): if isinstance(values["online_store"], str) and values[ "online_store" ].lower() in {"none", "null"}: values["online_store"] = None return values # Make sure that the provider configuration is set. We need it to set the defaults if "provider" not in values: raise FeastProviderNotSetError() # Set the default type # This is only direct reference to a provider or online store that we should have # for backwards compatibility. if "type" not in values["online_store"]: if values["provider"] == "local": values["online_store"]["type"] = "sqlite" elif values["provider"] == "gcp": values["online_store"]["type"] = "datastore" elif values["provider"] == "aws": values["online_store"]["type"] = "dynamodb" online_store_type = values["online_store"]["type"] # Validate the dict to ensure one of the union types match try: online_config_class = get_online_config_from_type(online_store_type) online_config_class(**values["online_store"]) except ValidationError as e: raise e return values @model_validator(mode="before") @classmethod def _validate_offline_store_config(cls, values: Any) -> Any: # Set empty offline_store config if it isn't set explicitly if "offline_store" not in values: values["offline_store"] = dict() # Skip if we aren't creating the configuration from a dict if not isinstance(values["offline_store"], Dict): return values # Make sure that the provider configuration is set. We need it to set the defaults if "provider" not in values: raise FeastProviderNotSetError() # Set the default type if "type" not in values["offline_store"]: if values["provider"] == "local": values["offline_store"]["type"] = "file" elif values["provider"] == "gcp": values["offline_store"]["type"] = "bigquery" elif values["provider"] == "aws": values["offline_store"]["type"] = "redshift" if values["provider"] == "azure": values["offline_store"]["type"] = "mssql" offline_store_type = values["offline_store"]["type"] # Validate the dict to ensure one of the union types match try: offline_config_class = get_offline_config_from_type(offline_store_type) offline_config_class(**values["offline_store"]) except ValidationError as e: raise e return values @model_validator(mode="before") @classmethod def _validate_feature_server_config(cls, values: Any) -> Any: # Having no feature server is the default. if "feature_server" not in values: return values # Skip if we aren't creating the configuration from a dict if not isinstance(values["feature_server"], Dict): return values # Make sure that the provider configuration is set. We need it to set the defaults if "provider" not in values: raise FeastProviderNotSetError() default_type = FEATURE_SERVER_TYPE_FOR_PROVIDER.get(values["provider"]) defined_type = values["feature_server"].get("type", default_type) # Make sure that the type is either not set, or set correctly, since it's defined by the provider if defined_type not in (default_type, "local"): raise FeastFeatureServerTypeSetError(defined_type) values["feature_server"]["type"] = defined_type # Validate the dict to ensure one of the union types match try: feature_server_config_class = get_feature_server_config_from_type( defined_type ) feature_server_config_class(**values["feature_server"]) except ValidationError as e: raise e return values @field_validator("project") @classmethod def _validate_project_name(cls, v: str) -> str: from feast.repo_operations import is_valid_name if not is_valid_name(v): raise ValueError( f"Project name, {v}, should only have " f"alphanumerical values and underscores but not start with an underscore." ) return v @field_validator("flags") @classmethod def _validate_flags(cls, v: Optional[dict]) -> Optional[dict]: if not isinstance(v, dict): return v _logger.warning( "Flags are no longer necessary in Feast. Experimental features will log warnings instead." ) return v def write_to_path(self, repo_path: Path): config_path = repo_path / "feature_store.yaml" with open(config_path, mode="w") as f: yaml.dump( yaml.safe_load( self.json( exclude={"repo_path"}, exclude_unset=True, ) ), f, sort_keys=False, ) model_config = ConfigDict(populate_by_name=True) class FeastConfigError(Exception): def __init__(self, error_message, config_path): self._error_message = error_message self._config_path = config_path super().__init__(self._error_message) def __str__(self) -> str: return f"{self._error_message}\nat {self._config_path}" def __repr__(self) -> str: return ( f"FeastConfigError({repr(self._error_message)}, {repr(self._config_path)})" ) def get_data_source_class_from_type(data_source_type: str): module_name, config_class_name = data_source_type.rsplit(".", 1) return import_class(module_name, config_class_name, "DataSource") def get_registry_config_from_type(registry_type: str): # We do not support custom registry's right now if registry_type not in REGISTRY_CLASS_FOR_TYPE: raise FeastRegistryTypeInvalidError(registry_type) registry_type = REGISTRY_CLASS_FOR_TYPE[registry_type] module_name, registry_class_type = registry_type.rsplit(".", 1) config_class_name = f"{registry_class_type}Config" return import_class(module_name, config_class_name, config_class_name) def get_batch_engine_config_from_type(batch_engine_type: str): if batch_engine_type in BATCH_ENGINE_CLASS_FOR_TYPE: batch_engine_type = BATCH_ENGINE_CLASS_FOR_TYPE[batch_engine_type] else: assert batch_engine_type.endswith("Engine") module_name, batch_engine_class_type = batch_engine_type.rsplit(".", 1) config_class_name = f"{batch_engine_class_type}Config" return import_class(module_name, config_class_name, config_class_name) def get_online_config_from_type(online_store_type: str): if online_store_type in ONLINE_STORE_CLASS_FOR_TYPE: online_store_type = ONLINE_STORE_CLASS_FOR_TYPE[online_store_type] elif not online_store_type.endswith("OnlineStore"): raise FeastOnlineStoreInvalidName(online_store_type) module_name, online_store_class_type = online_store_type.rsplit(".", 1) config_class_name = f"{online_store_class_type}Config" return import_class(module_name, config_class_name, config_class_name) def get_offline_config_from_type(offline_store_type: str): if offline_store_type in OFFLINE_STORE_CLASS_FOR_TYPE: offline_store_type = OFFLINE_STORE_CLASS_FOR_TYPE[offline_store_type] elif not offline_store_type.endswith("OfflineStore"): raise FeastOfflineStoreInvalidName(offline_store_type) module_name, offline_store_class_type = offline_store_type.rsplit(".", 1) config_class_name = f"{offline_store_class_type}Config" return import_class(module_name, config_class_name, config_class_name) def get_feature_server_config_from_type(feature_server_type: str): # We do not support custom feature servers right now. if feature_server_type not in FEATURE_SERVER_CONFIG_CLASS_FOR_TYPE: raise FeastFeatureServerTypeInvalidError(feature_server_type) feature_server_type = FEATURE_SERVER_CONFIG_CLASS_FOR_TYPE[feature_server_type] module_name, config_class_name = feature_server_type.rsplit(".", 1) return import_class(module_name, config_class_name, config_class_name) def load_repo_config(repo_path: Path, fs_yaml_file: Path) -> RepoConfig: config_path = fs_yaml_file with open(config_path) as f: raw_config = yaml.safe_load(os.path.expandvars(f.read())) try: c = RepoConfig(**raw_config) c.repo_path = repo_path return c except ValidationError as e: raise FeastConfigError(e, config_path) |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |