Les traductions sont fournies par des outils de traduction automatique. En cas de conflit entre le contenu d'une traduction et celui de la version originale en anglais, la version anglaise prévaudra.
DeleteNamedQueryExample
montre comment supprimer une requête nommée en utilisant l'ID de la requête nommée.
package aws.example.athena;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.athena.AthenaClient;
import software.amazon.awssdk.services.athena.model.DeleteNamedQueryRequest;
import software.amazon.awssdk.services.athena.model.AthenaException;
import software.amazon.awssdk.services.athena.model.CreateNamedQueryRequest;
import software.amazon.awssdk.services.athena.model.CreateNamedQueryResponse;
/**
* Before running this Java V2 code example, set up your development
* environment, including your credentials.
*
* For more information, see the following documentation topic:
*
* https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html
*/
public class DeleteNamedQueryExample {
public static void main(String[] args) {
final String USAGE = """
Usage:
<name>
Where:
name - the name of the Amazon Athena query.\s
""";
if (args.length != 1) {
System.out.println(USAGE);
System.exit(1);
}
String name = args[0];
AthenaClient athenaClient = AthenaClient.builder()
.region(Region.US_WEST_2)
.build();
String sampleNamedQueryId = getNamedQueryId(athenaClient, name);
deleteQueryName(athenaClient, sampleNamedQueryId);
athenaClient.close();
}
public static void deleteQueryName(AthenaClient athenaClient, String sampleNamedQueryId) {
try {
DeleteNamedQueryRequest deleteNamedQueryRequest = DeleteNamedQueryRequest.builder()
.namedQueryId(sampleNamedQueryId)
.build();
athenaClient.deleteNamedQuery(deleteNamedQueryRequest);
} catch (AthenaException e) {
e.printStackTrace();
System.exit(1);
}
}
public static String getNamedQueryId(AthenaClient athenaClient, String name) {
try {
CreateNamedQueryRequest createNamedQueryRequest = CreateNamedQueryRequest.builder()
.database(ExampleConstants.ATHENA_DEFAULT_DATABASE)
.queryString(ExampleConstants.ATHENA_SAMPLE_QUERY)
.name(name)
.description("Sample description")
.build();
CreateNamedQueryResponse createNamedQueryResponse = athenaClient.createNamedQuery(createNamedQueryRequest);
return createNamedQueryResponse.namedQueryId();
} catch (AthenaException e) {
e.printStackTrace();
System.exit(1);
}
return null;
}
}