File tree Expand file tree Collapse file tree
sqlmesh/core/engine_adapter
tests/core/engine_adapter Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -82,6 +82,16 @@ def alter_table(
8282 ) -> None :
8383 alter_table = exp .AlterTable (this = exp .to_table (table_name ))
8484
85+ if dropped_columns :
86+ drop_columns = exp .Drop (
87+ this = exp .Schema (
88+ expressions = [exp .to_identifier (column_name ) for column_name in dropped_columns ]
89+ ),
90+ kind = "COLUMNS" ,
91+ )
92+ alter_table .set ("actions" , [drop_columns ])
93+ self .execute (alter_table )
94+
8595 if added_columns :
8696 add_columns = exp .Schema (
8797 expressions = [
@@ -95,16 +105,6 @@ def alter_table(
95105 alter_table .set ("actions" , [add_columns ])
96106 self .execute (alter_table )
97107
98- if dropped_columns :
99- drop_columns = exp .Drop (
100- this = exp .Schema (
101- expressions = [exp .to_identifier (column_name ) for column_name in dropped_columns ]
102- ),
103- kind = "COLUMNS" ,
104- )
105- alter_table .set ("actions" , [drop_columns ])
106- self .execute (alter_table )
107-
108108 def _create_table_properties (
109109 self ,
110110 storage_format : t .Optional [str ] = None ,
Original file line number Diff line number Diff line change @@ -59,8 +59,8 @@ def test_alter_table(mocker: MockerFixture):
5959 cursor_mock .execute .assert_has_calls (
6060 [
6161 # 1st call.
62- call ("""ALTER TABLE `test_table` ADD COLUMNS (`a` INT, `b` STRING)""" ),
6362 call ("""ALTER TABLE `test_table` DROP COLUMNS (`c`, `d`)""" ),
63+ call ("""ALTER TABLE `test_table` ADD COLUMNS (`a` INT, `b` STRING)""" ),
6464 # 2nd call.
6565 call ("""ALTER TABLE `test_table` ADD COLUMNS (`e` DOUBLE)""" ),
6666 # 3d call.
You can’t perform that action at this time.
0 commit comments