@@ -75,13 +75,15 @@ def array_of_primitive(self, name: str, quoted: bool = False) -> TableAlterColum
7575 )
7676
7777 @classmethod
78- def from_struct_kwarg (self , struct : exp .StructKwarg ) -> TableAlterColumn :
78+ def from_struct_kwarg (self , struct : exp .ColumnDef ) -> TableAlterColumn :
7979 name = struct .alias_or_name
8080 quoted = struct .this .quoted
81- if struct .expression .is_type (exp .DataType .Type .STRUCT ):
81+ kwarg_type = struct .args ["kind" ]
82+
83+ if kwarg_type .is_type (exp .DataType .Type .STRUCT ):
8284 return self .struct (name , quoted = quoted )
83- elif struct . expression .is_type (exp .DataType .Type .ARRAY ):
84- if struct . expression .expressions [0 ].is_type (exp .DataType .Type .STRUCT ):
85+ elif kwarg_type .is_type (exp .DataType .Type .ARRAY ):
86+ if kwarg_type .expressions [0 ].is_type (exp .DataType .Type .STRUCT ):
8587 return self .array_of_struct (name , quoted = quoted )
8688 else :
8789 return self .array_of_primitive (name , quoted = quoted )
@@ -128,7 +130,7 @@ def middle(self, after: t.Union[str, exp.Identifier]) -> TableAlterColumnPositio
128130 def create (
129131 self ,
130132 pos : int ,
131- current_kwargs : t .List [exp .StructKwarg ],
133+ current_kwargs : t .List [exp .ColumnDef ],
132134 replacing_col : bool = False ,
133135 ) -> TableAlterColumnPosition :
134136 is_first = pos == 0
@@ -296,7 +298,7 @@ def _dict_to_struct(cls, value: t.Dict[str, exp.DataType]) -> exp.DataType:
296298 return exp .DataType (
297299 this = exp .DataType .Type .STRUCT ,
298300 expressions = [
299- exp .StructKwarg (this = exp .to_identifier (k ), expression = v ) for k , v in value .items ()
301+ exp .ColumnDef (this = exp .to_identifier (k ), kind = v ) for k , v in value .items ()
300302 ],
301303 nested = True ,
302304 )
@@ -310,10 +312,10 @@ def _is_compatible_type(self, current_type: exp.DataType, new_type: exp.DataType
310312
311313 def _get_matching_kwarg (
312314 self ,
313- current_kwarg : t .Union [str , exp .StructKwarg ],
315+ current_kwarg : t .Union [str , exp .ColumnDef ],
314316 new_struct : exp .DataType ,
315317 current_pos : int ,
316- ) -> t .Tuple [t .Optional [int ], t .Optional [exp .StructKwarg ]]:
318+ ) -> t .Tuple [t .Optional [int ], t .Optional [exp .ColumnDef ]]:
317319 current_name = (
318320 exp .to_identifier (current_kwarg )
319321 if isinstance (current_kwarg , str )
@@ -346,7 +348,7 @@ def _drop_operation(
346348 assert column_kwarg
347349 struct .expressions .pop (column_pos )
348350 operations .append (
349- TableAlterOperation .drop (columns , root_struct .copy (), column_kwarg .expression )
351+ TableAlterOperation .drop (columns , root_struct .copy (), column_kwarg .args [ "kind" ] )
350352 )
351353 return operations
352354
@@ -371,7 +373,7 @@ def _add_operation(
371373 self ,
372374 columns : t .List [TableAlterColumn ],
373375 new_pos : int ,
374- new_kwarg : exp .StructKwarg ,
376+ new_kwarg : exp .ColumnDef ,
375377 current_struct : exp .DataType ,
376378 root_struct : exp .DataType ,
377379 ) -> t .List [TableAlterOperation ]:
@@ -384,7 +386,7 @@ def _add_operation(
384386 return [
385387 TableAlterOperation .add (
386388 columns ,
387- new_kwarg .expression ,
389+ new_kwarg .args [ "kind" ] ,
388390 root_struct .copy (),
389391 col_pos ,
390392 )
@@ -415,7 +417,7 @@ def _alter_operation(
415417 new_type : exp .DataType ,
416418 current_type : t .Union [str , exp .DataType ],
417419 root_struct : exp .DataType ,
418- new_kwarg : exp .StructKwarg ,
420+ new_kwarg : exp .ColumnDef ,
419421 ) -> t .List [TableAlterOperation ]:
420422 current_type = exp .DataType .build (current_type )
421423 if self .support_nested_operations :
@@ -552,5 +554,5 @@ def compare_columns(
552554 )
553555
554556
555- def _get_name_and_type (struct : exp .StructKwarg ) -> t .Tuple [exp .Identifier , exp .DataType ]:
556- return struct .this , struct .expression
557+ def _get_name_and_type (struct : exp .ColumnDef ) -> t .Tuple [exp .Identifier , exp .DataType ]:
558+ return struct .this , struct .args [ "kind" ]
0 commit comments