File tree Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -544,10 +544,6 @@ def to_iceberg(
544544
545545 schema_differences ["missing_columns" ] = {}
546546
547- # Ensure that the ordering of the DF is the same as in the catalog.
548- # This is required for the INSERT command to work.
549- df = df [catalog_cols + list (schema_differences ["new_columns" ].keys ())]
550-
551547 if schema_evolution is False and any ([schema_differences [x ] for x in schema_differences ]): # type: ignore[literal-required]
552548 raise exceptions .InvalidArgumentValue (f"Schema change detected: { schema_differences } " )
553549
@@ -565,6 +561,22 @@ def to_iceberg(
565561 boto3_session = boto3_session ,
566562 )
567563
564+ # Ensure that the ordering of the DF is the same as in the catalog.
565+ # This is required for the INSERT command to work.
566+ # update catalog_cols after altering table
567+ catalog_cols = typing .cast (
568+ Dict [str , str ],
569+ catalog .get_table_types (
570+ database = database ,
571+ table = table ,
572+ catalog_id = catalog_id ,
573+ filter_iceberg_current = True ,
574+ boto3_session = boto3_session ,
575+ ),
576+ )
577+ catalog_cols = [key for key in catalog_cols ]
578+ df = df [catalog_cols ]
579+
568580 # if mode == "overwrite_partitions", drop matched partitions
569581 if mode == "overwrite_partitions" :
570582 delete_from_iceberg_table (
You can’t perform that action at this time.
0 commit comments