示例#1
0
    def from_dict(dct, explicit_partitions=True):
        """
        Load dataset metadata from a dictionary.

        This must have no external references. Otherwise use ``load_from_dict``
        to have them resolved automatically.
        """

        # Use the builder class for reconstruction to have a single point for metadata version changes
        builder = DatasetMetadataBuilder(
            uuid=dct[naming.UUID_KEY],
            metadata_version=dct[naming.METADATA_VERSION_KEY],
            explicit_partitions=explicit_partitions,
            partition_keys=dct.get("partition_keys", None)
            if dct[naming.METADATA_VERSION_KEY] >= 4
            else None,
            table_meta=dct.get("table_meta", None)
            if dct[naming.METADATA_VERSION_KEY] >= 4
            else None,
        )

        for key, value in six.iteritems(dct.get("metadata", {})):
            builder.add_metadata(key, value)
        for partition_label, part_dct in six.iteritems(dct.get("partitions", {})):
            builder.add_partition(
                partition_label, Partition.from_v2_dict(partition_label, part_dct)
            )
        for column, index_dct in six.iteritems(dct.get("indices", {})):
            if isinstance(index_dct, IndexBase):
                builder.add_embedded_index(column, index_dct)
            else:
                builder.add_embedded_index(
                    column, ExplicitSecondaryIndex.from_v2(column, index_dct)
                )
        return builder.to_dataset()
示例#2
0
def test_roundtrip():
    expected = {"files": {"Queejeb3": "file.parquet"}}
    result = Partition.from_v2_dict("partition_label", expected).to_dict()
    assert expected == result