Skip to content

Commit 991f610

Browse files
committed
Added additional validation and removed unhandled action.
1 parent 12802ad commit 991f610

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

awswrangler/athena/_write_iceberg.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ def _validate_args(
259259
"merge_conditional_clauses must be provided when merge_condition is 'conditional_merge'."
260260
)
261261

262+
seen_not_matched = False
262263
for i, clause in enumerate(merge_conditional_clauses):
263264
if "when" not in clause:
264265
raise exceptions.InvalidArgumentValue(
@@ -272,9 +273,17 @@ def _validate_args(
272273
raise exceptions.InvalidArgumentValue(
273274
f"merge_conditional_clauses[{i}]['when'] must be one of ['MATCHED', 'NOT MATCHED', 'NOT MATCHED BY SOURCE']."
274275
)
275-
if clause["action"] not in ["UPDATE", "DELETE", "INSERT", "IGNORE"]:
276+
if clause["action"] not in ["UPDATE", "DELETE", "INSERT"]:
276277
raise exceptions.InvalidArgumentValue(
277-
f"merge_conditional_clauses[{i}]['action'] must be one of ['UPDATE', 'DELETE', 'INSERT', 'IGNORE']."
278+
f"merge_conditional_clauses[{i}]['action'] must be one of ['UPDATE', 'DELETE', 'INSERT']."
279+
)
280+
281+
if clause["when"] in ["NOT MATCHED", "NOT MATCHED BY SOURCE"]:
282+
seen_not_matched = True
283+
elif clause["when"] == "MATCHED" and seen_not_matched:
284+
raise exceptions.InvalidArgumentValue(
285+
f"merge_conditional_clauses[{i}]['when'] is MATCHED but appears after a NOT MATCHED clause. "
286+
"WHEN MATCHED must come before WHEN NOT MATCHED or WHEN NOT MATCHED BY SOURCE."
278287
)
279288

280289
if mode == "overwrite_partitions":

0 commit comments

Comments
 (0)