2017-08-19 143 views
0

有沒有辦法通過Google代碼將數據上傳到Google BigQuery中?就像它可以在UI上完成一樣。Google BigQuery - 從Google雲端存儲直接上傳數據

這裏是從文檔的樣品: 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(); 
    } 

回答

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(); 
    } 
相關問題