bi_etl.bulk_loaders.redshift_s3_json_loader module
- class bi_etl.bulk_loaders.redshift_s3_json_loader.RedShiftS3JSONBulk(config: S3_Bulk_Loader_Config)[source]
Bases:
RedShiftS3BaseBulk loader for Redshift using gzipped JSON files staged to S3 and
COPY ... JSON 'auto'.Note:
s3_file_max_rowsis used as the number of rows per JSON file Each file is queued for upload as soon as it is complete.- DEFAULT_ROWS_PER_FILE = 25000
- __init__(config: S3_Bulk_Loader_Config)[source]
- Parameters:
config¶ –
S3_Bulk_Loader_Configwith the S3 and Redshift settings.
- add_redact_value(redact_value: str)
Register a value (such as a password) that
log_with_redactions()must hide.- Parameters:
redact_value¶ – Text to replace with asterisks in logged messages. None is ignored.
- clean_s3_folder(s3_full_folder: str)
Delete every object in the bucket whose key starts with s3_full_folder.
- Parameters:
s3_full_folder¶ – Key prefix of the folder to empty.
- get_copy_sql(s3_source_path: str, table_to_load: str, file_compression: str = '', analyze_compression: str | None = None, options: str = '')[source]
Build the JSON
COPYstatement.- Parameters:
s3_source_path¶ – Path of the S3 folder (within the bucket) containing the files to load.
table_to_load¶ – Qualified name of the table to load.
file_compression¶ – Compression option text to add to the statement (e.g.
GZIP).analyze_compression¶ –
COMPUPDATEsetting. Defaults to the configuredanalyze_compression.options¶ – Additional
COPYoptions to append.
- Returns:
The SQL text.
- Return type:
- load_from_files(local_files: List[str | Path], table_object: Table, table_to_load: str = None, perform_rename: bool = False, file_compression: str = '', options: str = '', analyze_compression: str = None) int
Wait for the uploads of local_files to S3 (uploading any that were not queued) and
COPYthem into the table.See
_upload_files_to_s3().- Parameters:
local_files¶ – Local files to load.
table_object¶ – Table being loaded.
table_to_load¶ – Name of the table (or temp table) to load into. Defaults to
table_object.qualified_table_name.perform_rename¶ – If
True, renametable_to_loadover the original table after the load.file_compression¶ – Compression option text to add to the statement (e.g.
GZIP).options¶ – Additional
COPYoptions to append.analyze_compression¶ –
COMPUPDATEsetting. Defaults to the configuredanalyze_compression.
- Returns:
Number of rows loaded.
- Return type:
- load_from_iterable(iterable: Iterable[Row], table_object: Table, table_to_load: str | None = None, perform_rename: bool = False, progress_frequency: int = 10, analyze_compression: str | None = None, parent_task: ETLTask | None = None) int[source]
Write rows from iterable to local gzipped JSON files of at most
rows_per_filerows each, and load them withload_from_files().Each file is queued for upload (see
_queue_file_for_upload()) as soon as it is closed, soload_from_files()only has to wait for the uploads still in progress.- Parameters:
table_object¶ – Table being loaded.
table_to_load¶ – Name of the table (or temp table) to load into. Defaults to
table_object.qualified_table_name.perform_rename¶ – If
True, renametable_to_loadover the original table after the load.progress_frequency¶ – Seconds between progress log messages. Pass
Noneto disable.analyze_compression¶ –
COMPUPDATEsetting. Defaults to the configuredanalyze_compression.parent_task¶ – Optional parent task (not used).
- Returns:
Number of rows written.
- Return type:
- load_from_s3_path(s3_source_path: str, table_object: Table, table_to_load: str = None, s3_source_path_is_absolute: bool = True, file_list: List[str] | None = None, file_compression: str = '', options: str = '', analyze_compression: str = None, perform_rename: bool = False) int
Load files that are already in S3 into the table with
COPY.- Parameters:
s3_source_path¶ – S3 folder (or file prefix) to load from.
table_object¶ – Table being loaded.
table_to_load¶ – Name of the table (or temp table) to load into. Defaults to
table_object.qualified_table_name.s3_source_path_is_absolute¶ – If
False,s3_source_pathis relative to the configured S3 folder.file_list¶ – Names of the files being loaded. Not used by the
COPYitself.file_compression¶ – Compression option text to add to the statement (e.g.
GZIP).options¶ – Additional
COPYoptions to append.analyze_compression¶ –
COMPUPDATEsetting. Defaults to the configuredanalyze_compression.perform_rename¶ – If
True, renametable_to_loadover the original table after the load.
- Returns:
Number of rows loaded.
- Return type:
- load_table_from_cache(table_object: Table, table_to_load: str | None = None, perform_rename: bool = False, progress_frequency: int = 10, analyze_compression: str | None = None) int
Load the rows in the cache of table_object with
load_from_iterable().- Parameters:
table_object¶ – Table whose cache is loaded.
table_to_load¶ – Name of the table (or temp table) used when renaming.
perform_rename¶ – If
True, renametable_to_loadover the original table (keeping the original as_old).progress_frequency¶ – Seconds between progress log messages.
analyze_compression¶ –
COMPUPDATEsetting. Defaults to the configuredanalyze_compression.
- Returns:
Number of rows loaded.
- Return type:
- log_with_redactions(*, log_level: int, message: str)
Log message after replacing every registered redaction value with asterisks.
- Parameters:
log_level¶ – Logging level, such as
logging.INFO.message¶ – Text to log.
- property needs_all_columns
Always
False.JSON 'auto'maps keys to columns by name, so a subset of columns can be loaded.
- rename_table(temp_table_name: str | None, table_object: Table)
Swap a freshly loaded temp table in place of table_object.
The existing table is renamed with an
_oldsuffix (dropping any earlier_oldtable first), and temp_table_name is renamed to the name of table_object.
- s3_folder_contents(s3_full_folder: str)
List the objects in the bucket whose keys start with s3_full_folder.
- property s3_password
The S3 password from the config. It is registered for redaction in log messages.