Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.
Batalkan kueri
Anda dapat menggunakan cuplikan kode berikut untuk membatalkan kueri.
catatan
Cuplikan kode ini didasarkan pada contoh aplikasi lengkap. GitHub
- Java
-
public void cancelQuery() { System.out.println("Starting query: " + SELECT_ALL_QUERY); QueryRequest queryRequest = new QueryRequest(); queryRequest.setQueryString(SELECT_ALL_QUERY); QueryResult queryResult = queryClient.query(queryRequest); System.out.println("Cancelling the query: " + SELECT_ALL_QUERY); final CancelQueryRequest cancelQueryRequest = new CancelQueryRequest(); cancelQueryRequest.setQueryId(queryResult.getQueryId()); try { queryClient.cancelQuery(cancelQueryRequest); System.out.println("Query has been successfully cancelled"); } catch (Exception e) { System.out.println("Could not cancel the query: " + SELECT_ALL_QUERY + " = " + e); } }
- Java v2
-
public void cancelQuery() { System.out.println("Starting query: " + SELECT_ALL_QUERY); QueryRequest queryRequest = QueryRequest.builder().queryString(SELECT_ALL_QUERY).build(); QueryResponse queryResponse = timestreamQueryClient.query(queryRequest); System.out.println("Cancelling the query: " + SELECT_ALL_QUERY); final CancelQueryRequest cancelQueryRequest = CancelQueryRequest.builder() .queryId(queryResponse.queryId()).build(); try { timestreamQueryClient.cancelQuery(cancelQueryRequest); System.out.println("Query has been successfully cancelled"); } catch (Exception e) { System.out.println("Could not cancel the query: " + SELECT_ALL_QUERY + " = " + e); } }
- Go
-
cancelQueryInput := ×treamquery.CancelQueryInput{ QueryId: aws.String(*queryOutput.QueryId), } fmt.Println("Submitting cancellation for the query") fmt.Println(cancelQueryInput) // submit the query cancelQueryOutput, err := querySvc.CancelQuery(cancelQueryInput) if err != nil { fmt.Println("Error:") fmt.Println(err) } else { fmt.Println("Query has been cancelled successfully") fmt.Println(cancelQueryOutput) }
- Python
-
def cancel_query(self): print("Starting query: " + self.SELECT_ALL) result = self.client.query(QueryString=self.SELECT_ALL) print("Cancelling query: " + self.SELECT_ALL) try: self.client.cancel_query(QueryId=result['QueryId']) print("Query has been successfully cancelled") except Exception as err: print("Cancelling query failed:", err)
- Node.js
-
Cuplikan berikut menggunakan gaya AWS SDK for JavaScript V2. Hal ini didasarkan pada contoh aplikasi di Node.js sampel Amazon Timestream untuk LiveAnalytics aplikasi
pada. GitHub async function tryCancelQuery() { const params = { QueryString: SELECT_ALL_QUERY }; console.log(`Running query: ${SELECT_ALL_QUERY}`); await queryClient.query(params).promise() .then( async (response) => { await cancelQuery(response.QueryId); }, (err) => { console.error("Error while executing select all query:", err); }); } async function cancelQuery(queryId) { const cancelParams = { QueryId: queryId }; console.log(`Sending cancellation for query: ${SELECT_ALL_QUERY}`); await queryClient.cancelQuery(cancelParams).promise() .then( (response) => { console.log("Query has been cancelled successfully"); }, (err) => { console.error("Error while cancelling select all:", err); }); }
- .NET
-
public async Task CancelQuery() { Console.WriteLine("Starting query: " + SELECT_ALL_QUERY); QueryRequest queryRequest = new QueryRequest(); queryRequest.QueryString = SELECT_ALL_QUERY; QueryResponse queryResponse = await queryClient.QueryAsync(queryRequest); Console.WriteLine("Cancelling query: " + SELECT_ALL_QUERY); CancelQueryRequest cancelQueryRequest = new CancelQueryRequest(); cancelQueryRequest.QueryId = queryResponse.QueryId; try { await queryClient.CancelQueryAsync(cancelQueryRequest); Console.WriteLine("Query has been successfully cancelled."); } catch(Exception e) { Console.WriteLine("Could not cancel the query: " + SELECT_ALL_QUERY + " = " + e); } }
Jalankan UNLOAD kueri
Buat tugas pemuatan batch