public void ModifyRequest() { var options = new ListJobsOptions { PageSize = 25, StateFilter = JobState.Pending, AllUsers = true, Projection = ProjectionEnum.Full, PageToken = "nextpage", MinCreationTime = new DateTimeOffset(1970, 1, 1, 0, 0, 1, TimeSpan.Zero), // Negative offset means this UTC is ahead of local time - so this is 1970-01-01T00:01:01Z. MaxCreationTime = new DateTimeOffset(1970, 1, 1, 0, 0, 1, TimeSpan.FromMinutes(-1)), ParentJobId = "dummy_parent_id" }; ListRequest request = new ListRequest(new BigqueryService(), "project"); options.ModifyRequest(request); Assert.Equal(25, request.MaxResults); Assert.Equal(StateFilterEnum.Pending, request.StateFilter); Assert.Equal(true, request.AllUsers); Assert.Equal(ProjectionEnum.Full, request.Projection); Assert.Equal("nextpage", request.PageToken); Assert.Equal(1000UL, request.MinCreationTime); Assert.Equal(61000UL, request.MaxCreationTime); Assert.Equal("dummy_parent_id", request.ParentJobId); }
public void ListJobs_FilterByLabels() { string bucketName = _fixture.StorageBucketName; string objectName = _fixture.GenerateStorageObjectName(); string projectId = _fixture.ProjectId; string datasetId = _fixture.GameDatasetId; string tableId = _fixture.HistoryTableId; // Snippet: Labels IDictionary <string, string> labels = new Dictionary <string, string>() { { "label-key", "label-value" } }; BigQueryClient client = BigQueryClient.Create(projectId); BigQueryTable table = client.GetTable(projectId, datasetId, tableId); string destinationUri = $"gs://{bucketName}/{objectName}"; // Just a couple examples of jobs marked with labels: // (These jobs will most certainly be created somewhere else.) // Running a query on a given table. BigQueryJob oneLabeledJob = client.CreateQueryJob( $"SELECT * FROM {table}", null, new QueryOptions { Labels = labels }); // Extracting data from a table to GCS. BigQueryJob anotherLabeledJob = client.CreateExtractJob( projectId, datasetId, tableId, destinationUri, new CreateExtractJobOptions { Labels = labels }); // Find jobs marked with a certain label. KeyValuePair <string, string> labelToBeFound = labels.First(); // Specify full projection to make sure that // label information, if it exists, is returned for listed jobs. ListJobsOptions options = new ListJobsOptions { Projection = ProjectionEnum.Full }; List <BigQueryJob> jobs = client .ListJobs(options) .Where(job => job.Resource.Configuration.Labels?.Contains(labelToBeFound) ?? false) .Take(2) .ToList(); foreach (BigQueryJob job in jobs) { Console.WriteLine(job.Reference.JobId); } // End snippet // This test added two jobs with such labels, other tests might have // added more. Assert.True(jobs.Count >= 2); }
public void MaxCreationTimeBeforeUnixEpoch() { var options = new ListJobsOptions { MaxCreationTime = new DateTimeOffset(1969, 12, 31, 23, 59, 59, TimeSpan.Zero), }; ListRequest request = new ListRequest(new BigqueryService(), "project"); Assert.Throws <ArgumentOutOfRangeException>(() => options.ModifyRequest(request)); }
public void MinCreationTimeLaterThanMaxCreationTime() { var options = new ListJobsOptions { MinCreationTime = new DateTimeOffset(2001, 1, 1, 0, 0, 0, TimeSpan.Zero), MaxCreationTime = new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero) }; ListRequest request = new ListRequest(new BigqueryService(), "project"); Assert.Throws <ArgumentException>(() => options.ModifyRequest(request)); }
public void ListJobsAsyncEquivalents() { var reference = new ProjectReference { ProjectId = ProjectId }; var options = new ListJobsOptions(); VerifyEquivalent(new UnimplementedPagedAsyncEnumerable <JobList, BigQueryJob>(), client => client.ListJobsAsync(MatchesWhenSerialized(reference), options), client => client.ListJobsAsync(options), client => client.ListJobsAsync(ProjectId, options)); }
public void ModifyRequest() { var options = new ListJobsOptions { PageSize = 25, StateFilter = JobState.Pending }; ListRequest request = new ListRequest(new BigqueryService(), "project"); options.ModifyRequest(request); Assert.Equal(25, request.MaxResults); Assert.Equal(StateFilterEnum.Pending, request.StateFilter); }
public void ModifyRequest_NoOp() { var options = new ListJobsOptions(); ListRequest request = new ListRequest(new BigqueryService(), "project"); options.ModifyRequest(request); Assert.Null(request.MaxResults); Assert.Null(request.StateFilter); Assert.Null(request.AllUsers); Assert.Null(request.Projection); Assert.Null(request.PageToken); Assert.Null(request.MinCreationTime); Assert.Null(request.MaxCreationTime); }
public void ListJobs_FullProjection() { var client = BigQueryClient.Create(_fixture.ProjectId); var table = client.GetTable(_fixture.ProjectId, _fixture.DatasetId, _fixture.HighScoreTableId); var jobToFind = client.CreateQueryJob($"SELECT * FROM {table}", parameters: null); // Find the job after listing with full projection. var options = new ListJobsOptions { Projection = ProjectionEnum.Full }; var jobFound = client.ListJobs(options).Single(job => job.Reference.JobId == jobToFind.Reference.JobId); Assert.NotNull(jobFound.Resource.Configuration); }
public void ListJobs() { var client = BigQueryClient.Create(_fixture.ProjectId); var table = client.GetTable(_fixture.ProjectId, _fixture.DatasetId, _fixture.HighScoreTableId); var jobToFind = client.CreateQueryJob($"SELECT * FROM {table}", parameters: null); // Find all jobs started in the last minute. var options = new ListJobsOptions { MinCreationTime = DateTimeOffset.UtcNow.AddMinutes(-1) }; var foundJob = client .ListJobs(options) .FirstOrDefault(job => job.Reference.JobId == jobToFind.Reference.JobId); Assert.NotNull(foundJob); }
public void ListJobs_ChildJobs() { var client = BigQueryClient.Create(_fixture.ProjectId); var table1 = client.GetTable(_fixture.ProjectId, _fixture.DatasetId, _fixture.HighScoreTableId); var table2 = client.GetTable(_fixture.ProjectId, _fixture.DatasetId, _fixture.PeopleTableId); string script = $"SELECT * FROM {table1};SELECT * FROM {table2}"; var parentJob = client.CreateQueryJob(script, null).PollUntilCompleted().ThrowOnAnyError(); // Find the child jobs of our job. var options = new ListJobsOptions { ParentJobId = parentJob.Reference.JobId }; var childrenJobs = client.ListJobs(options).ToList(); Assert.Equal(2, childrenJobs.Count); }
public void ListJobs_JobLabels() { var client = BigQueryClient.Create(_fixture.ProjectId); var table = client.GetTable(_fixture.ProjectId, _fixture.DatasetId, _fixture.HighScoreTableId); var jobToFind = client.CreateQueryJob($"SELECT * FROM {table}", null, new QueryOptions() { Labels = JobLabels }); // Find the job after listing with full projection. var options = new ListJobsOptions { Projection = ProjectionEnum.Full }; var jobFound = client.ListJobs(options).Single(job => job.Reference.JobId == jobToFind.Reference.JobId); VerifyJobLabels(jobFound.Resource.Configuration.Labels); }
public void ModifyRequest() { var options = new ListJobsOptions { PageSize = 25, StateFilter = JobState.Pending, AllUsers = true, Projection = ProjectionEnum.Full, PageToken = "nextpage" }; ListRequest request = new ListRequest(new BigqueryService(), "project"); options.ModifyRequest(request); Assert.Equal(25, request.MaxResults); Assert.Equal(StateFilterEnum.Pending, request.StateFilter); Assert.Equal(true, request.AllUsers); Assert.Equal(ProjectionEnum.Full, request.Projection); Assert.Equal("nextpage", request.PageToken); }