View a markdown version of this page

Usare DescribeStatement con un AWS SDK - Amazon Redshift

Amazon Redshift non supporterà più l'uso delle UDF Python dopo il 30 giugno 2026. Inizieremo ad applicarlo gradualmente. Per ulteriori informazioni sui dettagli della fine del ciclo di vita e sulle opzioni di migrazione di Python, consulta la post sul blog che è stato pubblicato il 30 giugno 2025.

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

Usare DescribeStatement con un AWS SDK

I seguenti esempi di codice mostrano come usare DescribeStatement.

Gli esempi di operazioni sono estratti di codice da programmi più grandi e devono essere eseguiti nel contesto. È possibile visualizzare questa operazione nel contesto nel seguente esempio di codice:

.NET
SDK per .NET (v4)
Nota

C'è di più su GitHub. Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

/// <summary> /// Describe a statement execution. /// </summary> /// <param name="statementId">The statement ID.</param> /// <returns>The statement description.</returns> public async Task<DescribeStatementResponse> DescribeStatementAsync(string statementId) { try { var request = new DescribeStatementRequest { Id = statementId }; var response = await _redshiftDataClient.DescribeStatementAsync(request); return response; } catch (Amazon.RedshiftDataAPIService.Model.ResourceNotFoundException ex) { Console.WriteLine($"Statement not found: {ex.Message}"); throw; } catch (Exception ex) { Console.WriteLine($"Couldn't describe statement. Here's why: {ex.Message}"); throw; } }
  • Per i dettagli sull'API, consulta DescribeStatement nel AWS SDK per .NET Riferimento API.

Java
SDK per Java 2.x
Nota

C'è di più su GitHub. Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

/** * Checks the status of an SQL statement asynchronously and handles the completion of the statement. * * @param sqlId the ID of the SQL statement to check * @return a {@link CompletableFuture} that completes when the SQL statement's status is either "FINISHED" or "FAILED" */ public CompletableFuture<Void> checkStatementAsync(String sqlId) { DescribeStatementRequest statementRequest = DescribeStatementRequest.builder() .id(sqlId) .build(); return getAsyncDataClient().describeStatement(statementRequest) .thenCompose(response -> { String status = response.statusAsString(); logger.info("... Status: {} ", status); if ("FAILED".equals(status)) { throw new RuntimeException("The Query Failed. Ending program"); } else if ("FINISHED".equals(status)) { return CompletableFuture.completedFuture(null); } else { // Sleep for 1 second and recheck status return CompletableFuture.runAsync(() -> { try { TimeUnit.SECONDS.sleep(1); } catch (InterruptedException e) { throw new RuntimeException("Error during sleep: " + e.getMessage(), e); } }).thenCompose(ignore -> checkStatementAsync(sqlId)); // Recursively call until status is FINISHED or FAILED } }).whenComplete((result, exception) -> { if (exception != null) { // Handle exceptions logger.info("Error: {} ", exception.getMessage()); } else { logger.info("The statement is finished!"); } }); }
  • Per i dettagli sull'API, consulta DescribeStatement nel AWS SDK for Java 2.x Riferimento API.

Python
SDK per Python (Boto3)
Nota

C'è di più su GitHub. Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

class RedshiftDataWrapper: """Encapsulates Amazon Redshift data.""" def __init__(self, client): """ :param client: A Boto3 RedshiftDataWrapper client. """ self.client = client def describe_statement(self, statement_id): """ Describes a SQL statement. :param statement_id: The SQL statement identifier. :return: The SQL statement result. """ try: response = self.client.describe_statement(Id=statement_id) return response except ClientError as err: logging.error( "Couldn't describe statement. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise

Il codice seguente crea un'istanza di RedshiftDataWrapper oggetto.

client = boto3.client("redshift-data") redshift_data_wrapper = RedshiftDataWrapper(client)
  • Per i dettagli sull'API, vedi DescribeStatement nel AWS Riferimento alle API SDK per Python (Boto3).

SAP ABAP
SDK per SAP ABAP
Nota

C'è di più su GitHub. Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

TRY. " Example values: iv_statement_id = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' oo_result = lo_rsd->describestatement( iv_id = iv_statement_id ). lv_status = oo_result->get_status( ). MESSAGE |Statement status: { lv_status }| TYPE 'I'. CATCH /aws1/cx_rsdresourcenotfoundex. MESSAGE 'Statement not found.' TYPE 'I'. CATCH /aws1/cx_rsdinternalserverex. MESSAGE 'Internal server error.' TYPE 'I'. ENDTRY.
  • Per i dettagli sull'API, consulta DescribeStatement nel AWS Riferimento all'API SDK per SAP ABAP.

Per un elenco completo di AWS Guide per sviluppatori SDK ed esempi di codice, consulta Utilizzo di questo servizio con un AWS SDK. Questo argomento include anche informazioni su come iniziare e dettagli sulle versioni precedenti dell’SDK.