Amazon Redshift dejará de admitir la creación de nuevas UDF de Python a partir del 1 de noviembre de 2025. Si desea utilizar las UDF de Python, créelas antes de esa fecha. Las UDF de Python existentes seguirán funcionando con normalidad. Para obtener más información, consulte la publicación del blog.
Uso de DescribeStatement con un SDK de AWS
Los siguientes ejemplos de código muestran cómo utilizar DescribeStatement.
Los ejemplos de acciones son extractos de código de programas más grandes y deben ejecutarse en contexto. Puede ver esta acción en contexto en el siguiente ejemplo de código:
- Java
-
- SDK para Java 2.x
-
/**
* 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!");
}
});
}
- Python
-
- SDK para Python (Boto3)
-
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
El código siguiente crea una instancia del objeto RedshiftDataWrapper.
client = boto3.client("redshift-data")
redshift_data_wrapper = RedshiftDataWrapper(client)
Para obtener una lista completa de las guías para desarrolladores de AWS SDK y ejemplos de código, consulte Cómo utilizar este servicio con un AWS SDK. En este tema también se incluye información sobre cómo comenzar a utilizar el SDK y detalles sobre sus versiones anteriores.