Google apps script BigQuery CSV上载中的双引号数据错误
将数据从GoogleSheets上传到BigQuery时,comments字段包含如下数据Google apps script BigQuery CSV上载中的双引号数据错误,google-apps-script,google-bigquery,Google Apps Script,Google Bigquery,将数据从GoogleSheets上传到BigQuery时,comments字段包含如下数据 请为我提供解决方案,我希望按原样上传评论,而不将其替换为空格。除了从工作表中创建CSV然后将该CSV导入BigQuery之外的其他选项: 要求数据位于工作表的第一个选项卡中。然后可以将该外部表复制到真正的bigquery表 使用BigQuery.Tabledata.insertAll将数据作为JSON插入表中,而不必格式化CSV 您之所以会遇到此问题,是因为您没有在原始注释字段中转义引号。您必须这样做。请
请为我提供解决方案,我希望按原样上传评论,而不将其替换为空格。除了从工作表中创建CSV然后将该CSV导入BigQuery之外的其他选项: 要求数据位于工作表的第一个选项卡中。然后可以将该外部表复制到真正的bigquery表 使用BigQuery.Tabledata.insertAll将数据作为JSON插入表中,而不必格式化CSV
您之所以会遇到此问题,是因为您没有在原始注释字段中转义引号。您必须这样做。请查看相关的BigQuery问题,并指出1您得到的确切错误,2您解决此问题的尝试会带来什么以及尝试这些问题的结果。
function pushToBQ(projectId, datasetId, tableId) {
var fileId = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
var jobSpec = { configuration: {
load: {
destinationTable: {
projectId: projectId,
datasetId: datasetId,
tableId: tableId
},
allowJaggedRows: true,
writeDisposition: 'WRITE_TRUNCATE',
allowQuotedNewlines: true,
schema: {
fields: [
{name: 'User_id', type: 'STRING'},
{name: 'email', type: 'STRING'},
{name: 'Comments', type: 'STRING'},
]
}
}
}
};
var spreadsheet = SpreadsheetApp.openById(fileId);
var MAX_ROWS = 50000;
var sheet = spreadsheet.getSheetByName("xyz");
var data = sheet.getDataRange().getValues();
var csvdata = "";
for (var row = 1; row < data.length && row < MAX_ROWS + 1; row++) {
for (var col = 0; col < data[row].length; col++) {
var cell = data[row][col].toString();
if (cell.indexOf(",") != -1) {
csvdata += "\"" + cell + "\"";
} else {
csvdata += cell;
}
if (col < data[row].length - 1) {
csvdata += ",";
}
}
csvdata += "\r\n";
}
var data = Utilities.newBlob(csvdata, "application/octet-stream");
BigQuery.Jobs.insert(jobSpec, projectId, data);
}
function daily_upload(){
pushToBQ("dev", "sampledataset",'sampletable');
}