【问题标题】:Google BigQuery - Directly upload data from Google Cloud StorageGoogle BigQuery - 直接从 Google Cloud Storage 上传数据
【发布时间】:2018-01-28 01:17:15
【问题描述】:

有什么方法可以将数据从 Google Cloud 存储上传到 Google BigQuery,而无需通过 .NET 代码下载?就像它可以在 UI 上完成一样。

以下是文档中的示例: https://cloud.google.com/bigquery/docs/loading-data-cloud-storage#bigquery-import-gcs-file-csharp

    StorageClient gcsClient = StorageClient.Create();

    using (var stream = new MemoryStream())
    {
        // Set Cloud Storage Bucket name. This uses a bucket named the same as the project.
        string bucket = projectId;
        // If folder is passed in, add it to Cloud Storage File Path using "/" character
        string filePath = string.IsNullOrEmpty(folder) ? fileName : folder + "/" + fileName;
        // Download Google Cloud Storage object into stream
        gcsClient.DownloadObject(projectId, filePath, stream);

        // This example uploads data to an existing table. If the upload will create a new table
        // or if the schema in the JSON isn't identical to the schema in the table,
        // create a schema to pass into the call instead of passing in a null value.
        BigQueryJob job = client.UploadJson(datasetId, tableId, null, stream);
        // Use the job to find out when the data has finished being inserted into the table,
        // report errors etc.

        // Wait for the job to complete.
        job.PollUntilCompleted();
    }

【问题讨论】:

    标签: c# .net google-bigquery google-cloud-storage


    【解决方案1】:

    来这里

    public void ImportDataFromCloudStorage(BigQueryClient client, string uri, TableReference reference, WriteDisposition disposition = WriteDisposition.WriteIfEmpty)
        {
          BigQueryJob job = client.CreateLoadJob(uri, reference, null, new CreateLoadJobOptions()
          {
            FieldDelimiter = ";",
            SkipLeadingRows = 1,
            AllowQuotedNewlines = true,
            WriteDisposition = disposition
          });
    
          job.PollUntilCompleted();
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-13
      • 2014-09-18
      • 1970-01-01
      • 2018-06-20
      • 1970-01-01
      • 1970-01-01
      • 2018-11-27
      • 2018-11-18
      相关资源
      最近更新 更多