2020
2121class TableFormatType (Enum ):
2222 """Enum for supported table formats"""
23+
2324 DELTA = "delta"
2425 ICEBERG = "iceberg"
2526 HUDI = "hudi"
@@ -32,9 +33,9 @@ class TableFormat(ABC):
3233 table storage formats like Iceberg, Delta Lake, Hudi, etc.
3334 """
3435
35- def __init__ (self ,
36- format_type : TableFormatType ,
37- properties : Optional [ Dict [ str , str ]] = None ):
36+ def __init__ (
37+ self , format_type : TableFormatType , properties : Optional [ Dict [ str , str ]] = None
38+ ):
3839 self .format_type = format_type
3940 self .properties = properties or {}
4041
@@ -45,20 +46,15 @@ def to_dict(self) -> Dict:
4546
4647 @classmethod
4748 @abstractmethod
48- def from_dict (cls ,
49- data : Dict ) -> "TableFormat" :
49+ def from_dict (cls , data : Dict ) -> "TableFormat" :
5050 """Create table format from dictionary representation"""
5151 pass
5252
53- def get_property (self ,
54- key : str ,
55- default : Optional [str ] = None ) -> Optional [str ]:
53+ def get_property (self , key : str , default : Optional [str ] = None ) -> Optional [str ]:
5654 """Get a table format property"""
5755 return self .properties .get (key , default )
5856
59- def set_property (self ,
60- key : str ,
61- value : str ) -> None :
57+ def set_property (self , key : str , value : str ) -> None :
6258 """Set a table format property"""
6359 self .properties [key ] = value
6460
@@ -71,11 +67,11 @@ class IcebergTableFormat(TableFormat):
7167 """
7268
7369 def __init__ (
74- self ,
75- catalog : Optional [str ] = None ,
76- namespace : Optional [str ] = None ,
77- catalog_properties : Optional [Dict [str , str ]] = None ,
78- table_properties : Optional [Dict [str , str ]] = None ,
70+ self ,
71+ catalog : Optional [str ] = None ,
72+ namespace : Optional [str ] = None ,
73+ catalog_properties : Optional [Dict [str , str ]] = None ,
74+ table_properties : Optional [Dict [str , str ]] = None ,
7975 ):
8076 super ().__init__ (TableFormatType .ICEBERG )
8177 self .catalog = catalog
@@ -104,8 +100,7 @@ def to_dict(self) -> Dict:
104100 }
105101
106102 @classmethod
107- def from_dict (cls ,
108- data : Dict ) -> "IcebergTableFormat" :
103+ def from_dict (cls , data : Dict ) -> "IcebergTableFormat" :
109104 return cls (
110105 catalog = data .get ("catalog" ),
111106 namespace = data .get ("namespace" ),
@@ -122,9 +117,9 @@ class DeltaTableFormat(TableFormat):
122117 """
123118
124119 def __init__ (
125- self ,
126- table_properties : Optional [Dict [str , str ]] = None ,
127- checkpoint_location : Optional [str ] = None ,
120+ self ,
121+ table_properties : Optional [Dict [str , str ]] = None ,
122+ checkpoint_location : Optional [str ] = None ,
128123 ):
129124 super ().__init__ (TableFormatType .DELTA )
130125 self .table_properties = table_properties or {}
@@ -145,8 +140,7 @@ def to_dict(self) -> Dict:
145140 }
146141
147142 @classmethod
148- def from_dict (cls ,
149- data : Dict ) -> "DeltaTableFormat" :
143+ def from_dict (cls , data : Dict ) -> "DeltaTableFormat" :
150144 return cls (
151145 table_properties = data .get ("table_properties" , {}),
152146 checkpoint_location = data .get ("checkpoint_location" ),
@@ -161,11 +155,11 @@ class HudiTableFormat(TableFormat):
161155 """
162156
163157 def __init__ (
164- self ,
165- table_type : Optional [str ] = None , # COPY_ON_WRITE or MERGE_ON_READ
166- record_key : Optional [str ] = None ,
167- precombine_field : Optional [str ] = None ,
168- table_properties : Optional [Dict [str , str ]] = None ,
158+ self ,
159+ table_type : Optional [str ] = None , # COPY_ON_WRITE or MERGE_ON_READ
160+ record_key : Optional [str ] = None ,
161+ precombine_field : Optional [str ] = None ,
162+ table_properties : Optional [Dict [str , str ]] = None ,
169163 ):
170164 super ().__init__ (TableFormatType .HUDI )
171165 self .table_type = table_type
@@ -180,7 +174,9 @@ def __init__(
180174 if record_key :
181175 all_properties ["hoodie.datasource.write.recordkey.field" ] = record_key
182176 if precombine_field :
183- all_properties ["hoodie.datasource.write.precombine.field" ] = precombine_field
177+ all_properties ["hoodie.datasource.write.precombine.field" ] = (
178+ precombine_field
179+ )
184180
185181 self .properties = all_properties
186182
@@ -194,8 +190,7 @@ def to_dict(self) -> Dict:
194190 }
195191
196192 @classmethod
197- def from_dict (cls ,
198- data : Dict ) -> "HudiTableFormat" :
193+ def from_dict (cls , data : Dict ) -> "HudiTableFormat" :
199194 return cls (
200195 table_type = data .get ("table_type" ),
201196 record_key = data .get ("record_key" ),
@@ -204,8 +199,7 @@ def from_dict(cls,
204199 )
205200
206201
207- def create_table_format (format_type : TableFormatType ,
208- ** kwargs ) -> TableFormat :
202+ def create_table_format (format_type : TableFormatType , ** kwargs ) -> TableFormat :
209203 """
210204 Factory function to create appropriate TableFormat instance based on type.
211205 """
0 commit comments