|
5 | 5 | import json |
6 | 6 | import logging |
7 | 7 | import uuid |
8 | | -from typing import Any, Dict, Iterator, List, Optional, Tuple, Union, overload |
| 8 | +from typing import Any, Dict, Iterator, List, Literal, Optional, Tuple, Union, overload |
9 | 9 |
|
10 | 10 | import boto3 |
11 | 11 | import botocore |
|
24 | 24 | _RS_DISTSTYLES: List[str] = ["AUTO", "EVEN", "ALL", "KEY"] |
25 | 25 | _RS_SORTSTYLES: List[str] = ["COMPOUND", "INTERLEAVED"] |
26 | 26 |
|
| 27 | +_ToSqlModeLiteral = Literal["append", "overwrite", "upsert"] |
| 28 | +_ToSqlOverwriteModeLiteral = Literal["drop", "cascade", "truncate", "delete"] |
| 29 | +_ToSqlDistStyleLiteral = Literal["AUTO", "EVEN", "ALL", "KEY"] |
| 30 | +_ToSqlSortStyleLiteral = Literal["COMPOUND", "INTERLEAVED"] |
| 31 | + |
27 | 32 |
|
28 | 33 | def _validate_connection(con: "redshift_connector.Connection") -> None: |
29 | 34 | if not isinstance(con, redshift_connector.Connection): |
@@ -909,13 +914,13 @@ def to_sql( # pylint: disable=too-many-locals |
909 | 914 | con: "redshift_connector.Connection", |
910 | 915 | table: str, |
911 | 916 | schema: str, |
912 | | - mode: str = "append", |
913 | | - overwrite_method: str = "drop", |
| 917 | + mode: _ToSqlModeLiteral = "append", |
| 918 | + overwrite_method: _ToSqlOverwriteModeLiteral = "drop", |
914 | 919 | index: bool = False, |
915 | 920 | dtype: Optional[Dict[str, str]] = None, |
916 | | - diststyle: str = "AUTO", |
| 921 | + diststyle: _ToSqlDistStyleLiteral = "AUTO", |
917 | 922 | distkey: Optional[str] = None, |
918 | | - sortstyle: str = "COMPOUND", |
| 923 | + sortstyle: _ToSqlSortStyleLiteral = "COMPOUND", |
919 | 924 | sortkey: Optional[List[str]] = None, |
920 | 925 | primary_keys: Optional[List[str]] = None, |
921 | 926 | varchar_lengths_default: int = 256, |
@@ -1084,7 +1089,7 @@ def unload_to_files( |
1084 | 1089 | aws_secret_access_key: Optional[str] = None, |
1085 | 1090 | aws_session_token: Optional[str] = None, |
1086 | 1091 | region: Optional[str] = None, |
1087 | | - unload_format: Optional[str] = None, |
| 1092 | + unload_format: Optional[Literal["CSV", "PARQUET"]] = None, |
1088 | 1093 | max_file_size: Optional[float] = None, |
1089 | 1094 | kms_key_id: Optional[str] = None, |
1090 | 1095 | manifest: bool = False, |
@@ -1380,11 +1385,11 @@ def copy_from_files( # pylint: disable=too-many-locals,too-many-arguments |
1380 | 1385 | aws_secret_access_key: Optional[str] = None, |
1381 | 1386 | aws_session_token: Optional[str] = None, |
1382 | 1387 | parquet_infer_sampling: float = 1.0, |
1383 | | - mode: str = "append", |
1384 | | - overwrite_method: str = "drop", |
1385 | | - diststyle: str = "AUTO", |
| 1388 | + mode: _ToSqlModeLiteral = "append", |
| 1389 | + overwrite_method: _ToSqlOverwriteModeLiteral = "drop", |
| 1390 | + diststyle: _ToSqlDistStyleLiteral = "AUTO", |
1386 | 1391 | distkey: Optional[str] = None, |
1387 | | - sortstyle: str = "COMPOUND", |
| 1392 | + sortstyle: _ToSqlSortStyleLiteral = "COMPOUND", |
1388 | 1393 | sortkey: Optional[List[str]] = None, |
1389 | 1394 | primary_keys: Optional[List[str]] = None, |
1390 | 1395 | varchar_lengths_default: int = 256, |
@@ -1608,11 +1613,11 @@ def copy( # pylint: disable=too-many-arguments,too-many-locals |
1608 | 1613 | aws_session_token: Optional[str] = None, |
1609 | 1614 | index: bool = False, |
1610 | 1615 | dtype: Optional[Dict[str, str]] = None, |
1611 | | - mode: str = "append", |
1612 | | - overwrite_method: str = "drop", |
1613 | | - diststyle: str = "AUTO", |
| 1616 | + mode: _ToSqlModeLiteral = "append", |
| 1617 | + overwrite_method: _ToSqlOverwriteModeLiteral = "drop", |
| 1618 | + diststyle: _ToSqlDistStyleLiteral = "AUTO", |
1614 | 1619 | distkey: Optional[str] = None, |
1615 | | - sortstyle: str = "COMPOUND", |
| 1620 | + sortstyle: _ToSqlSortStyleLiteral = "COMPOUND", |
1616 | 1621 | sortkey: Optional[List[str]] = None, |
1617 | 1622 | primary_keys: Optional[List[str]] = None, |
1618 | 1623 | varchar_lengths_default: int = 256, |
|
0 commit comments