Skip to content

Commit 3f7ca50

Browse files
committed
refactor: _validate_args refactor to comply with ruff check
1 parent 262bfc6 commit 3f7ca50

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

awswrangler/athena/_write_iceberg.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from awswrangler import _data_types, _utils, catalog, exceptions, s3
1515
from awswrangler._config import apply_configs
1616
from awswrangler.athena._executions import wait_query
17-
from awswrangler.athena._utils import _get_workgroup_config, _start_query_execution, _WorkGroupConfig, _MergeClause
17+
from awswrangler.athena._utils import _get_workgroup_config, _MergeClause, _start_query_execution, _WorkGroupConfig
1818
from awswrangler.typing import GlueTableSettings
1919

2020
_logger: logging.Logger = logging.getLogger(__name__)
@@ -228,6 +228,29 @@ def _validate_args(
228228
"Either path or workgroup path must be specified to store the temporary results."
229229
)
230230

231+
_validate_merge_arguments(
232+
merge_cols, merge_on_clause, merge_condition,
233+
merge_conditional_clauses, merge_match_nulls
234+
)
235+
236+
if mode == "overwrite_partitions":
237+
if not partition_cols:
238+
raise exceptions.InvalidArgumentCombination(
239+
"When mode is 'overwrite_partitions' partition_cols must be specified."
240+
)
241+
if merge_cols:
242+
raise exceptions.InvalidArgumentCombination(
243+
"When mode is 'overwrite_partitions' merge_cols must not be specified."
244+
)
245+
246+
247+
def _validate_merge_arguments(
248+
merge_cols: list[str] | None,
249+
merge_on_clause: str | None,
250+
merge_condition: Literal["update", "ignore", "conditional_merge"],
251+
merge_conditional_clauses: list[_MergeClause] | None,
252+
merge_match_nulls: bool,
253+
) -> None:
231254
if merge_cols and merge_on_clause:
232255
raise exceptions.InvalidArgumentCombination(
233256
"Cannot specify both merge_cols and merge_on_clause. Use either merge_cols for simple equality matching or merge_on_clause for custom logic."
@@ -275,16 +298,6 @@ def _validate_args(
275298
"WHEN MATCHED must come before WHEN NOT MATCHED or WHEN NOT MATCHED BY SOURCE."
276299
)
277300

278-
if mode == "overwrite_partitions":
279-
if not partition_cols:
280-
raise exceptions.InvalidArgumentCombination(
281-
"When mode is 'overwrite_partitions' partition_cols must be specified."
282-
)
283-
if merge_cols:
284-
raise exceptions.InvalidArgumentCombination(
285-
"When mode is 'overwrite_partitions' merge_cols must not be specified."
286-
)
287-
288301

289302
def _merge_iceberg(
290303
df: pd.DataFrame,

0 commit comments

Comments
 (0)