client¶
Improve the original redshift data api boto3 API.
Ref:
- simple_aws_redshift.redshift_data_api.client.get_statement_result(redshift_data_api_client: RedshiftDataAPIServiceClient, id: str, max_items: int = 1000) GetStatementResultResponseIterProxy[source]¶
Retrieves the result of a SQL statement execution using the Redshift Data API.
This function automatically paginates through all result pages and returns an iterator proxy that yields GetStatementResultResponse objects for each page.
- Parameters:
redshift_data_api_client – boto3.client(“redshift-data”) object
id – The identifier of the SQL statement to retrieve results for
max_items – Maximum number of items to return across all pages
- Returns:
Reference:
get_statement_result: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/redshift-data/client/get_statement_result.html
GetStatementResult: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/redshift-data/paginator/GetStatementResult.html
Note
get_statement_result can only return results that are in JSON format! for CSV, please use get_statement_result_v2.
- class simple_aws_redshift.redshift_data_api.client.RunSqlResult(execute_statement_response: ExecuteStatementOutputTypeDef = REQ, describe_statement_response: DescribeStatementResponse = REQ)[source]¶
Result of running a SQL statement using the Redshift Data API.
- Parameters:
execute_statement_response – Response from the execute_statement API call.
describe_statement_response – Response from the describe_statement API call.
- simple_aws_redshift.redshift_data_api.client.run_sql(redshift_data_api_client: RedshiftDataAPIServiceClient, sql: str, client_token: str = OPT, cluster_identifier: str = OPT, database: str = OPT, db_user: str = OPT, parameters: dict[str, Any] = OPT, result_format: ResultFormatStringType = OPT, secret_arn: str = OPT, session_id: str = OPT, session_keep_alive_seconds: int = OPT, statement_name: str = OPT, with_event: bool = OPT, workgroup_name: str = OPT, delay: int = 1, timeout: int = 10, verbose: bool = False, raises_on_error: bool = True)[source]¶
Run redshift SQL statement using Data API and get the results. It will run
execute_statementAPI to run the SQL asynchronously, then do a long polling to check the status of the SQL execution using``describe_statement`` API. Once the SQL execution is finished, it will runget_statement_resultAPI to get the result.In other words, this function is a human-friendly wrapper of the Data API.
- Parameters:
redshift_data_api_client – boto3.client(“redshift-data”) object
sql – SQL statement you want to execute.
client_token – Unique identifier for the request to ensure idempotency.
cluster_identifier – cluster identifier. this is for Redshift provisioned cluster only.
database – database name.
db_user – database user name.
parameters – Parameters for the SQL statement.
result_format – Format of the result set (JSON or CSV).
secret_arn – ARN of the secret containing database credentials.
session_id – Database session identifier.
session_keep_alive_seconds – Number of seconds to keep the session alive.
statement_name – statement name. a human-friendly name you want to give to this SQL statement.
with_event – Whether to send an event to Amazon EventBridge.
workgroup_name – workgroup name. this is for Redshift serverless only.
delay – how many seconds to wait between each long polling.
timeout – how many seconds to wait before timeout.
verbose – whether to print verbose output during polling.
raises_on_error – whether to raise an exception when the SQL execution fails.
Reference:
execute_statement: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/redshift-data/client/execute_statement.html
describe_statement: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/redshift-data/client/describe_statement.html
get_statement_result: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/redshift-data/client/get_statement_result.html
- Returns:
RunSqlResultobject.
- class simple_aws_redshift.redshift_data_api.client.SqlCommandKeyEnum[source]¶
Keys for internal data storage in SqlCommand.
- class simple_aws_redshift.redshift_data_api.client.SqlCommand(redshift_data_api_client: RedshiftDataAPIServiceClient = REQ, sql: str = REQ, client_token: str = OPT, cluster_identifier: str = OPT, database: str = OPT, db_user: str = OPT, parameters: dict[str, ~typing.Any] = OPT, result_format: ResultFormatStringType = 'JSON', secret_arn: str = OPT, session_id: str = OPT, session_keep_alive_seconds: int = OPT, statement_name: str = OPT, with_event: bool = OPT, workgroup_name: str = OPT, delay: int = 1, timeout: int = 10, verbose: bool = False, raises_on_error: bool = True, max_rows: int = 1000, _data: dict[str, ~typing.Any] = <factory>)[source]¶
Command pattern class that encapsulates everything needed to execute a Redshift SQL statement using the Data API and retrieve its results.
Usage:
Use run() for automatic execution of the complete workflow
- Or call methods in sequence for more control:
execute_statement() → wait_until_finished() → get_statement_result() → get_consolidated_result()
Note: The iterproxy returned by get_statement_result() can only be consumed once. If you need to iterate multiple times, call get_consolidated_result() instead.
- Parameters:
redshift_data_api_client – boto3.client(“redshift-data”) object
sql – SQL statement you want to execute.
client_token – Unique identifier for the request to ensure idempotency.
cluster_identifier – cluster identifier. this is for Redshift provisioned cluster only.
database – database name.
db_user – database user name.
parameters – Parameters for the SQL statement.
result_format – Format of the result set (JSON or CSV).
secret_arn – ARN of the secret containing database credentials.
session_id – Database session identifier.
session_keep_alive_seconds – Number of seconds to keep the session alive.
statement_name – statement name. a human-friendly name you want to give to this SQL statement.
with_event – Whether to send an event to Amazon EventBridge.
workgroup_name – workgroup name. this is for Redshift serverless only.
delay – how many seconds to wait between each long polling.
timeout – how many seconds to wait before timeout.
verbose – whether to print verbose output during polling.
raises_on_error – whether to raise an exception when the SQL execution fails.
_data – internal data storage.
Reference:
execute_statement: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/redshift-data/client/execute_statement.html
describe_statement: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/redshift-data/client/describe_statement.html
get_statement_result: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/redshift-data/client/get_statement_result.html
- property execute_statement_response: ExecuteStatementOutputTypeDef¶
Interface to get the response from the execute_statement API call.
- property describe_statement_response: DescribeStatementResponse¶
Interface to get the statement execution status and metadata.
- property get_statement_result_iterproxy: GetStatementResultResponseIterProxy¶
Interface to get the statement execution results as an iterator proxy (consumable only once).
- property result: ConsolidatedStatementResult¶
Interface to get consolidated results after running the full workflow.
- property statement_id: str¶
Get the statement ID of the SQL statement. This ID can be used to retrieve the results of the SQL execution using the get_statement_result API.
- execute_statement() ExecuteStatementOutputTypeDef[source]¶
Run
execute_statementAPI to run the SQL asynchronously.- Returns:
Response from the execute_statement API call.
- wait_until_finished() DescribeStatementResponse[source]¶
Poll the statement status until it reaches a final state (FINISHED, FAILED, or ABORTED).
- get_statement_result() GetStatementResultResponseIterProxy[source]¶
Retrieve the statement execution results as an iterator proxy (consumable only once).
- get_consolidated_result_v1() ConsolidatedStatementResult[source]¶
Consolidate JSON format results into a single result object.
- get_consolidated_result_v2() ConsolidatedStatementResult[source]¶
Consolidate CSV format results into a single result object.
- get_consolidated_result() ConsolidatedStatementResult[source]¶
Get consolidated results in the appropriate format based on result_format setting.