Skip to content

Commit 22333cf

Browse files
committed
add test case
1 parent 1ac85a9 commit 22333cf

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

tests/unit/test_athena_iceberg.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,3 +1159,55 @@ def test_to_iceberg_fill_missing_columns_with_complex_types(
11591159
schema_evolution=True,
11601160
fill_missing_columns_in_df=True,
11611161
)
1162+
1163+
1164+
def test_athena_to_iceberg_alter_schema(
1165+
path: str,
1166+
path2: str,
1167+
glue_database: str,
1168+
glue_table: str,
1169+
) -> None:
1170+
df = pd.DataFrame(
1171+
{
1172+
"id": pd.Series([1, 2, 3, 4, 5], dtype="Int64"),
1173+
"name": pd.Series(["a", "b", "c", "d", "e"], dtype="string"),
1174+
},
1175+
).reset_index(drop=True)
1176+
1177+
split_index = 3
1178+
1179+
wr.athena.to_iceberg(
1180+
df=df[:split_index],
1181+
database=glue_database,
1182+
table=glue_table,
1183+
table_location=path,
1184+
temp_path=path2,
1185+
schema_evolution=True,
1186+
keep_files=False,
1187+
)
1188+
1189+
wr.athena.start_query_execution(
1190+
sql=f"ALTER TABLE {glue_table} CHANGE COLUMN id new_id bigint",
1191+
database=glue_database,
1192+
wait=True,
1193+
)
1194+
1195+
df = df.rename(columns={"id": "new_id"})
1196+
1197+
wr.athena.to_iceberg(
1198+
df=df[split_index:],
1199+
database=glue_database,
1200+
table=glue_table,
1201+
table_location=path,
1202+
temp_path=path2,
1203+
schema_evolution=True,
1204+
keep_files=False,
1205+
)
1206+
1207+
df_actual = wr.athena.read_sql_query(
1208+
sql=f"SELECT new_id, name FROM '{glue_table}' ORDER BY new_id",
1209+
database=glue_database,
1210+
ctas_approach=False,
1211+
)
1212+
1213+
assert_pandas_equals(df, df_actual)

0 commit comments

Comments
 (0)