Skip to content

Commit 1a4b130

Browse files
(enhancement) Redshift: Adding 'primary_keys' to parameter validation (#1728)
* Adding 'primary_keys' to parameter validation * check type only if parameter is set * flake8
1 parent ecf9ab3 commit 1a4b130

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

awswrangler/redshift.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ def _validate_parameters(
219219
distkey: Optional[str],
220220
sortstyle: str,
221221
sortkey: Optional[List[str]],
222+
primary_keys: Optional[List[str]],
222223
) -> None:
223224
if diststyle not in _RS_DISTSTYLES:
224225
raise exceptions.InvalidRedshiftDiststyle(f"diststyle must be in {_RS_DISTSTYLES}")
@@ -240,6 +241,14 @@ def _validate_parameters(
240241
raise exceptions.InvalidRedshiftSortkey(
241242
f"sortkey must be a List of items in the columns list: {cols}. " f"Currently value: {key}"
242243
)
244+
if primary_keys:
245+
if not isinstance(primary_keys, list):
246+
raise exceptions.InvalidArgumentType(
247+
f"""
248+
primary keys should be of type list[str].
249+
Current value: {primary_keys} is of type {type(primary_keys)}
250+
"""
251+
)
243252

244253

245254
def _redshift_types_from_path(
@@ -379,6 +388,7 @@ def _create_table( # pylint: disable=too-many-locals,too-many-arguments,too-man
379388
distkey=distkey,
380389
sortstyle=sortstyle,
381390
sortkey=sortkey,
391+
primary_keys=primary_keys,
382392
)
383393
cols_str: str = "".join([f'"{k}" {v},\n' for k, v in redshift_types.items()])[:-2]
384394
primary_keys_str: str = f",\nPRIMARY KEY ({', '.join(primary_keys)})" if primary_keys else ""

0 commit comments

Comments
 (0)