Skip to content

Commit 3b847ce

Browse files
author
Lautaro Ortega
committed
updated implementation
1 parent d2bbd63 commit 3b847ce

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

awswrangler/athena/_write_iceberg.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff 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_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+
568580
# if mode == "overwrite_partitions", drop matched partitions
569581
if mode == "overwrite_partitions":
570582
delete_from_iceberg_table(

0 commit comments

Comments
 (0)