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(
544
544
545
545
schema_differences ["missing_columns" ] = {}
546
546
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
-
551
547
if schema_evolution is False and any ([schema_differences [x ] for x in schema_differences ]): # type: ignore[literal-required]
552
548
raise exceptions .InvalidArgumentValue (f"Schema change detected: { schema_differences } " )
553
549
@@ -565,6 +561,22 @@ def to_iceberg(
565
561
boto3_session = boto3_session ,
566
562
)
567
563
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_column_types = 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_column_types ]
578
+ df = df [catalog_cols ]
579
+
568
580
# if mode == "overwrite_partitions", drop matched partitions
569
581
if mode == "overwrite_partitions" :
570
582
delete_from_iceberg_table (
You can’t perform that action at this time.
0 commit comments