取消查询 - Amazon Timestream

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

取消查询

您可以使用以下代码片段来取消查询。

注意

这些代码片段基于上的完整示例应用程序。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 := &timestreamquery.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

以下代码段使用 for JavaScript V2 样式。 AWS SDK它基于 Node.js 示例 Amazon Timestream 中的示例 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); } }