【发布时间】:2016-12-08 11:41:21
【问题描述】:
使用 appscript 将大型 (16GB) Biq 查询表导出到 GCS 时,我无法进行压缩。我将压缩类型设置为 GZIP 并将目标格式设置为 NEWLINE_DELIMITED_JSON 但它不压缩文件,而是只输出 116 个文件?
我尝试过extract.compression = 和extract.setcompression =,但没有任何区别。我该如何解决这个问题?
function extractBigQueryToCloudStorage(compressionType,csFileUri, datasetId, tableId,projectId) {
//
var compressionType='GZIP';
var csFileUri='gs://xxxxxxxxxx/bq_extracts/xxxxxxxxxx.*.JSON';
var datasetId='xxxxxxxxxx';
var tableId='xxxxxxxxxx';
var projectId='xxxxxxxxxx';
var bqTable = checkBigQueryTable(projectId, datasetId, tableId);
var fnStart = new Date();
try {
var tableReference = BigQuery.newTableReference();
tableReference.setProjectId(projectId);
tableReference.setDatasetId(datasetId);
tableReference.setTableId(tableId);
var extract = BigQuery.newJobConfigurationExtract()
extract.setDestinationFormat('NEWLINE_DELIMITED_JSON');
extract.compression=(compressionType);
extract.setDestinationUris([csFileUri]);
extract.setSourceTable(tableReference);
var configuration = BigQuery.newJobConfiguration();
configuration.setExtract(extract);
var newJob = BigQuery.newJob();
newJob.setConfiguration(configuration);
var job = BigQuery.Jobs.insert(newJob, projectId);
var jobId = job.getJobReference().getJobId();
var status = job.getStatus();
while (status.getState() != 'DONE'){
Logger.log(status.getState());
if(status.getState() == 'PENDING'){
Utilities.sleep(100);
}
if (status.getErrorResult() == true){
Logger.log('BigQuery file upload error: %s', status.getErrors());
}
status = BigQuery.Jobs.get(projectId, jobId).getStatus();
}
} catch(err) {
Logger.log('BigQuery file upload error: %s', err);
return err;
}
var fnEnd = new Date();
Logger.log(status.getState());
Logger.log('Function loadCloudStorageFileToBigQuery elapsed time: %sms', fnEnd - fnStart);
Logger.log(status.errorResult); // check for notification of extract too big (e.g. > 1 Gb)
return status.getState();
// Function to determine if a BigQuery table exists. Returns boolean
function checkBigQueryTable(projectId, datasetId, tableId) {
try {
var job = BigQuery.Tables.get(projectId, datasetId, tableId);
return true;
} catch(err) {
Logger.log('Table %s does not exist' , tableId);
return false;
}
}
}
【问题讨论】:
标签: google-apps-script google-bigquery