本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
取消查詢
您可以使用下列程式碼片段來取消查詢。
- 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
-
下列程式碼片段使用 AWS SDK JavaScript V2 樣式的 。它以 Node.js 範例應用程式為基礎,適用於 上的 LiveAnalytics 應用程式 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); } }
執行UNLOAD查詢
建立批次載入任務