public void ExecuteQuery() { var projectId = _fixture.ProjectId; var datasetId = _fixture.GameDatasetId; var historyTableId = _fixture.HistoryTableId; // Snippet: ExecuteQuery BigqueryClient client = BigqueryClient.Create(projectId); BigqueryTable table = client.GetTable(datasetId, historyTableId); BigqueryResult result = client.ExecuteQuery( $@"SELECT player, MAX(score) AS score FROM {table} GROUP BY player ORDER BY score DESC"); foreach (var row in result.Rows) { Console.WriteLine($"{row["player"]}: {row["score"]}"); } // End snippet var players = result.Rows.Select(r => (string)r["player"]).ToList(); Assert.Contains("Ben", players); Assert.Contains("Nadia", players); Assert.Contains("Tim", players); }
/// <summary> /// Waits for a query to return a non-empty result set. Some inserts may take a few seconds before the results are visible /// via queries - and much longer to show up in ListRows. (It looks like these are inserts with repeated fields and/or record fields.) /// </summary> private IEnumerable <BigqueryRow> WaitForRows(BigqueryClient client, BigqueryCommand command) { for (int i = 0; i < 5; i++) { var rows = client.ExecuteQuery(command) .PollUntilCompleted() .GetRows() .ToList(); if (rows.Count > 0) { return(rows); } Thread.Sleep(1000); } throw new TimeoutException("Expected rows were not available after 5 seconds"); }