本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
列出排程查詢
您可以使用下列程式碼片段來列出已排程的查詢。
- Java
-
public void listScheduledQueries() { System.out.println("Listing Scheduled Query"); try { String nextToken = null; List<String> scheduledQueries = new ArrayList<>(); do { ListScheduledQueriesResult listScheduledQueriesResult = queryClient.listScheduledQueries(new ListScheduledQueriesRequest() .withNextToken(nextToken).withMaxResults(10)); List<ScheduledQuery> scheduledQueryList = listScheduledQueriesResult.getScheduledQueries(); printScheduledQuery(scheduledQueryList); nextToken = listScheduledQueriesResult.getNextToken(); } while (nextToken != null); } catch (Exception e) { System.out.println("List Scheduled Query failed: " + e); throw e; } } public void printScheduledQuery(List<ScheduledQuery> scheduledQueryList) { for (ScheduledQuery scheduledQuery: scheduledQueryList) { System.out.println(scheduledQuery.getArn()); } }
- Java v2
-
public void listScheduledQueries() { System.out.println("Listing Scheduled Query"); try { String nextToken = null; do { ListScheduledQueriesResponse listScheduledQueriesResult = queryClient.listScheduledQueries(ListScheduledQueriesRequest.builder() .nextToken(nextToken).maxResults(10) .build()); List<ScheduledQuery> scheduledQueryList = listScheduledQueriesResult.scheduledQueries(); printScheduledQuery(scheduledQueryList); nextToken = listScheduledQueriesResult.nextToken(); } while (nextToken != null); } catch (Exception e) { System.out.println("List Scheduled Query failed: " + e); throw e; } } public void printScheduledQuery(List<ScheduledQuery> scheduledQueryList) { for (ScheduledQuery scheduledQuery: scheduledQueryList) { System.out.println(scheduledQuery.arn()); } }
- Go
-
func (timestreamBuilder TimestreamBuilder) ListScheduledQueries() ([]*timestreamquery.ScheduledQuery, error) { var nextToken *string = nil var scheduledQueries []*timestreamquery.ScheduledQuery for ok := true; ok; ok = nextToken != nil { listScheduledQueriesInput := ×treamquery.ListScheduledQueriesInput{ MaxResults: aws.Int64(15), } if nextToken != nil { listScheduledQueriesInput.NextToken = aws.String(*nextToken) } listScheduledQueriesOutput, err := timestreamBuilder.QuerySvc.ListScheduledQueries(listScheduledQueriesInput) if err != nil { fmt.Printf("Error: %s", err.Error()) return nil, err } scheduledQueries = append(scheduledQueries, listScheduledQueriesOutput.ScheduledQueries...) nextToken = listScheduledQueriesOutput.NextToken } return scheduledQueries, nil }
- Python
-
def list_scheduled_queries(self): print("\nListing Scheduled Queries") try: response = self.query_client.list_scheduled_queries(MaxResults=10) self.print_scheduled_queries(response['ScheduledQueries']) next_token = response.get('NextToken', None) while next_token: response = self.query_client.list_scheduled_queries(NextToken=next_token, MaxResults=10) self.print_scheduled_queries(response['ScheduledQueries']) next_token = response.get('NextToken', None) except Exception as err: print("List scheduled queries failed:", err) raise err @staticmethod def print_scheduled_queries(scheduled_queries): for scheduled_query in scheduled_queries: print(scheduled_query['Arn'])
- Node.js
-
下列程式碼片段使用 AWS SDK適用於 JavaScript V2 樣式的 。它以 Node.js 範例應用程式為基礎,適用於 上的 LiveAnalytics 應用程式 GitHub
。 async function listScheduledQueries() { console.log("Listing Scheduled Query"); try { var nextToken = null; do { var params = { MaxResults: 10, NextToken: nextToken } var data = await queryClient.listScheduledQueries(params).promise(); var scheduledQueryList = data.ScheduledQueries; printScheduledQuery(scheduledQueryList); nextToken = data.NextToken; } while (nextToken != null); } catch (err) { console.log("List Scheduled Query failed: ", err); throw err; } } async function printScheduledQuery(scheduledQueryList) { scheduledQueryList.forEach(element => console.log(element.Arn)); }
- .NET
-
private async Task ListScheduledQueries() { try { Console.WriteLine("Listing Scheduled Query"); string nextToken; do { ListScheduledQueriesResponse response = await _amazonTimestreamQuery.ListScheduledQueriesAsync(new ListScheduledQueriesRequest()); foreach (var scheduledQuery in response.ScheduledQueries) { Console.WriteLine($"{scheduledQuery.Arn}"); } nextToken = response.NextToken; } while (nextToken != null); } catch (Exception e) { Console.WriteLine($"List Scheduled Query failed: {e}"); throw; } }
建立排程查詢
描述排程查詢