MCPcopy
hub / github.com/feast-dev/feast / table_format_from_dict

Function table_format_from_dict

sdk/python/feast/table_format.py:469–509  ·  view source on GitHub ↗

Create TableFormat instance from dictionary representation. This function deserializes a dictionary (typically from JSON or protobuf) back into the appropriate TableFormat instance. The dictionary must contain a 'format_type' field that indicates which format class to instantiate.

(data: Dict)

Source from the content-addressed store, hash-verified

467
468
469def table_format_from_dict(data: Dict) -> TableFormat:
470 """
471 Create TableFormat instance from dictionary representation.
472
473 This function deserializes a dictionary (typically from JSON or protobuf)
474 back into the appropriate TableFormat instance. The dictionary must contain
475 a 'format_type' field that indicates which format class to instantiate.
476
477 Args:
478 data (Dict): Dictionary containing table format configuration. Must include
479 'format_type' field with value 'iceberg', 'delta', or 'hudi'.
480
481 Returns:
482 TableFormat: An instance of the appropriate TableFormat subclass.
483
484 Raises:
485 ValueError: If format_type is not recognized.
486 KeyError: If format_type field is missing from data.
487
488 Examples:
489 Deserialize an Iceberg format:
490
491 >>> data = {
492 ... "format_type": "iceberg",
493 ... "catalog": "my_catalog",
494 ... "namespace": "my_db"
495 ... }
496 >>> iceberg_format = table_format_from_dict(data)
497 """
498 if "format_type" not in data:
499 raise KeyError("Missing 'format_type' field in data")
500 format_type = data["format_type"]
501
502 if format_type == TableFormatType.ICEBERG.value:
503 return IcebergFormat.from_dict(data)
504 elif format_type == TableFormatType.DELTA.value:
505 return DeltaFormat.from_dict(data)
506 elif format_type == TableFormatType.HUDI.value:
507 return HudiFormat.from_dict(data)
508 else:
509 raise ValueError(f"Unknown table format type: {format_type}")
510
511
512def table_format_from_json(json_str: str) -> TableFormat:

Calls 1

from_dictMethod · 0.45