예제 #1
0
        // [END poll_job]

        /// <summary>
        /// Lists all Datasets in a project specified by the projectId.
        /// </summary>
        /// <param name="projectId">The projectId from which lists the existing
        /// Datasets.</param>
        // [START list_datasets]
        public IEnumerable <DatasetList.DatasetsData> ListDatasets(
            string projectId)
        {
            BigqueryService bigquery       = CreateAuthorizedClient();
            var             datasetRequest =
                new DatasetsResource.ListRequest(bigquery, projectId);

            // Sometimes Datasets will be null instead of an empty list.
            // It's easy to forget that and dereference null.  So, catch
            // that case and return an empty list.
            return(datasetRequest.Execute().Datasets ??
                   new DatasetList.DatasetsData[] { });
        }
예제 #2
0
        // Just loops though getting all the rows.
        private static DatasetList ProcessResults(DatasetsResource.ListRequest request)
        {
            try
            {
                DatasetList result = request.Execute();


                List <DatasetList.DatasetsData> allRows = new List <DatasetList.DatasetsData>();

                //// Loop through until we arrive at an empty page
                while (result.Datasets != null)
                {
                    //Add the rows to the final list
                    allRows.AddRange(result.Datasets);

                    // We will know we are on the last page when the next page token is
                    // null.
                    // If this is the case, break.
                    if (result.NextPageToken == null)
                    {
                        break;
                    }
                    // Prepare the next page of results
                    request.PageToken = result.NextPageToken;

                    // Execute and process the next page request
                    result = request.Execute();
                }
                DatasetList allData = result;
                allData.Datasets = (List <DatasetList.DatasetsData>)allRows;
                return(allData);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(null);
            }
        }
예제 #3
0
 private IEnumerable <DatasetList.DatasetsData> DoListRequest(string project)
 {
     DatasetsResource.ListRequest lRequest = Service.Datasets.List(project);
     lRequest.All    = IncludeHidden;
     lRequest.Filter = (Filter == null) ? null : string.Join(" ", Filter.Select(item => $"labels.{item}"));
     do
     {
         DatasetList response = lRequest.Execute();
         if (response == null)
         {
             ThrowTerminatingError(new ErrorRecord(
                                       new Exception("List request to server responded with null."),
                                       "List request returned null", ErrorCategory.InvalidArgument, project));
         }
         if (response.Datasets != null)
         {
             foreach (DatasetList.DatasetsData d in response.Datasets)
             {
                 yield return(d);
             }
         }
         lRequest.PageToken = response.NextPageToken;
     }while (!Stopping && lRequest.PageToken != null);
 }
예제 #4
0
 // [END poll_job]
 /// <summary>
 /// Lists all Datasets in a project specified by the projectId.
 /// </summary>
 /// <param name="bigquery">The BigQuery object.</param>
 /// <param name="projectId">The projectId from which lists the existing Datasets.
 /// </param>
 // [START list_datasets]
 public static IEnumerable<DatasetList.DatasetsData> ListDatasets(BigqueryService bigquery,
     string projectId)
 {
     var datasetRequest = new DatasetsResource.ListRequest(bigquery, projectId);
     // Sometimes Datasets will be null instead of an empty list.
     // It's easy to forget that and dereference null.  So, catch
     // that case and return an empty list.
     return datasetRequest.Execute().Datasets ?? new DatasetList.DatasetsData[] { };
 }