1616# under the License.
1717import importlib
1818import logging
19+ import uuid
1920from abc import ABC , abstractmethod
2021from typing import Optional
2122
2930
3031
3132class LocationProvider (ABC ):
32- """A base class for location providers, that provide data file locations for a table's write tasks.
33+ """A base class for location providers, that provide file locations for a table's write tasks.
3334
3435 Args:
3536 table_location (str): The table's base storage location.
@@ -40,6 +41,7 @@ class LocationProvider(ABC):
4041 table_properties : Properties
4142
4243 data_path : str
44+ metadata_path : str
4345
4446 def __init__ (self , table_location : str , table_properties : Properties ):
4547 self .table_location = table_location
@@ -52,6 +54,11 @@ def __init__(self, table_location: str, table_properties: Properties):
5254 else :
5355 self .data_path = f"{ self .table_location .rstrip ('/' )} /data"
5456
57+ if path := table_properties .get (TableProperties .WRITE_METADATA_PATH ):
58+ self .metadata_path = path .rstrip ("/" )
59+ else :
60+ self .metadata_path = f"{ self .table_location .rstrip ('/' )} /metadata"
61+
5562 @abstractmethod
5663 def new_data_location (self , data_file_name : str , partition_key : Optional [PartitionKey ] = None ) -> str :
5764 """Return a fully-qualified data file location for the given filename.
@@ -64,6 +71,35 @@ def new_data_location(self, data_file_name: str, partition_key: Optional[Partiti
6471 str: A fully-qualified location URI for the data file.
6572 """
6673
74+ def new_table_metadata_file_location (self , new_version : int = 0 ) -> str :
75+ """Return a fully-qualified metadata file location for a new table version.
76+
77+ Args:
78+ new_version (int): Version number of the metadata file.
79+
80+ Returns:
81+ str: fully-qualified URI for the new table metadata file.
82+
83+ Raises:
84+ ValueError: If the version is negative.
85+ """
86+ if new_version < 0 :
87+ raise ValueError (f"Table metadata version: `{ new_version } ` must be a non-negative integer" )
88+
89+ file_name = f"{ new_version :05d} -{ uuid .uuid4 ()} .metadata.json"
90+ return self .new_metadata_location (file_name )
91+
92+ def new_metadata_location (self , metadata_file_name : str ) -> str :
93+ """Return a fully-qualified metadata file location for the given filename.
94+
95+ Args:
96+ metadata_file_name (str): Name of the metadata file.
97+
98+ Returns:
99+ str: A fully-qualified location URI for the metadata file.
100+ """
101+ return f"{ self .metadata_path } /{ metadata_file_name } "
102+
67103
68104class SimpleLocationProvider (LocationProvider ):
69105 def __init__ (self , table_location : str , table_properties : Properties ):
0 commit comments