コード例 #1
0
        public void CannotExtractAsDatastoreBackup()
        {
            var options = new CreateExtractJobOptions {
                DestinationFormat = FileFormat.DatastoreBackup
            };
            JobConfigurationExtract extract = new JobConfigurationExtract();

            Assert.Throws <ArgumentException>(() => options.ModifyRequest(extract));
        }
コード例 #2
0
        public void ExtractJob_Labels()
        {
            var bqClient          = BigQueryClient.Create(_fixture.ProjectId);
            var originReference   = bqClient.GetTableReference(_fixture.DatasetId, _fixture.HighScoreTableId);
            var destinationBucket = _fixture.StorageBucketName;
            var destinationObject = _fixture.GenerateStorageObjectName();
            var destinationUri    = $"gs://{destinationBucket}/{destinationObject}";
            var options           = new CreateExtractJobOptions {
                Labels = JobLabels
            };

            var extractJob = bqClient.CreateExtractJob(originReference, destinationUri, options);

            VerifyJobLabels(extractJob?.Resource?.Configuration?.Labels);

            extractJob = extractJob.PollUntilCompleted().ThrowOnAnyError();
            VerifyJobLabels(extractJob?.Resource?.Configuration?.Labels);
        }
コード例 #3
0
        public void ModifyRequest()
        {
            var options = new CreateExtractJobOptions
            {
                Compression       = CompressionType.Gzip,
                PrintHeader       = false,
                DestinationFormat = FileFormat.NewlineDelimitedJson,
                // May not make any sense for JSON, but we don't validate...
                FieldDelimiter = "gronkle"
            };
            JobConfigurationExtract extract = new JobConfigurationExtract();

            options.ModifyRequest(extract);
            Assert.Equal("GZIP", extract.Compression);
            Assert.Equal(false, extract.PrintHeader);
            Assert.Equal("NEWLINE_DELIMITED_JSON", extract.DestinationFormat);
            Assert.Equal("gronkle", extract.FieldDelimiter);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: mattosaurus/DataTransfer
        public static async Task ExportBigQueryTableToStorageAsync(BigQueryClient bigQueryClient, string destinationUri, BigQueryResults results)
        {
            CreateExtractJobOptions jobOptions = new CreateExtractJobOptions()
            {
                DestinationFormat = FileFormat.Csv,
                Compression       = CompressionType.Gzip
            };

            BigQueryJob job = bigQueryClient.CreateExtractJob(
                projectId: results.TableReference.ProjectId,
                datasetId: results.TableReference.DatasetId,
                tableId: results.TableReference.TableId,
                destinationUri: destinationUri,
                options: jobOptions
                );

            await job.PollUntilCompletedAsync();
        }
コード例 #5
0
    public void ExtractTableJson(
        string projectId  = "your-project-id",
        string bucketName = "your-bucket-name")
    {
        BigQueryClient client         = BigQueryClient.Create(projectId);
        string         destinationUri = $"gs://{bucketName}/shakespeare.json";
        var            jobOptions     = new CreateExtractJobOptions()
        {
            DestinationFormat = FileFormat.NewlineDelimitedJson
        };
        BigQueryJob job = client.CreateExtractJob(
            projectId: "bigquery-public-data",
            datasetId: "samples",
            tableId: "shakespeare",
            destinationUri: destinationUri,
            options: jobOptions
            );

        job = job.PollUntilCompleted().ThrowOnAnyError();  // Waits for the job to complete.
        Console.Write($"Exported table to {destinationUri}.");
    }