Esempio n. 1
0
        /// <summary>
        /// Query Job main processing function.
        /// </summary>
        public Apis.Bigquery.v2.Data.Job DoQuery()
        {
            if (ShouldProcess($"\n\nProject: {Project}\nQuery: {QueryString}\n\n"))
            {
                try
                {
                    var options = new CreateQueryJobOptions
                    {
                        UseLegacySql     = UseLegacySql,
                        Priority         = Priority,
                        DestinationTable = Destination,
                        DefaultDataset   = DefaultDataset
                    };

                    BigQueryJob bqr = Client.CreateQueryJob(QueryString, options);
                    return(bqr.Resource);
                }
                catch (GoogleApiException ex) when(ex.HttpStatusCode == HttpStatusCode.Forbidden)
                {
                    ThrowTerminatingError(new ErrorRecord(ex, "Query rejected: Access denied",
                                                          ErrorCategory.InvalidOperation, this));
                }
                catch (GoogleApiException ex) when(ex.HttpStatusCode == HttpStatusCode.NotFound)
                {
                    ThrowTerminatingError(new ErrorRecord(ex, "Query rejected: Resource not found",
                                                          ErrorCategory.InvalidOperation, this));
                }
            }
            return(null);
        }
        public void PropertiesSetOnRequest()
        {
            var options = new CreateQueryJobOptions
            {
                AllowLargeResults = true,
                CreateDisposition = CreateDisposition.CreateNever,
                DefaultDataset    = new DatasetReference {
                    ProjectId = "a", DatasetId = "b"
                },
                DestinationTable = new TableReference {
                    ProjectId = "a", DatasetId = "b", TableId = "c"
                },
                FlattenResults     = false,
                MaximumBillingTier = 10,
                Priority           = QueryPriority.Batch,
                UseQueryCache      = false,
                WriteDisposition   = WriteDisposition.WriteIfEmpty
            };

            JobConfigurationQuery query = new JobConfigurationQuery();

            options.ModifyRequest(query);
            Assert.Equal(true, query.AllowLargeResults);
            Assert.Equal("CREATE_NEVER", query.CreateDisposition);
            Assert.Equal("b", query.DefaultDataset.DatasetId);
            Assert.Equal("c", query.DestinationTable.TableId);
            Assert.Equal(false, query.FlattenResults);
            Assert.Equal(10, query.MaximumBillingTier);
            Assert.Equal("BATCH", query.Priority);
            Assert.Equal(false, query.UseQueryCache);
            Assert.Equal("WRITE_EMPTY", query.WriteDisposition);
        }