My apps script is modified from https://developers.google.com/apps-script/advanced/bigquery.
I keep getting errors like so:
File: 0 / Line:6 / Field:1, Bad character (ASCII 0) encountered: field starts with: < c7d��{>
File: 0 / Line:7 / Field:1, Bad character (ASCII 0) encountered: field starts with: < #7��v#>
File: 0 / Line:13 / Field:1, Bad character (ASCII 0) encountered: field starts with: < c7d�1>
File: 0 / Line:17 / Field:1, Bad character (ASCII 0) encountered: field starts with: <�+�d��>
File: 0 / Line:20 / Field:1, Bad character (ASCII 0) encountered: field starts with: <7�J�F�)�>
Here is my code:
function loadCsv() {
// Replace this value with the project ID listed in the Google
// Developers Console project.
var projectId = 'summer-rope-861';
// Create a dataset in the BigQuery UI (https://bigquery.cloud.google.com)
// and enter its ID below.
var datasetId = 'expedia_sem';
// Sample CSV file of Google Trends data conforming to the schema below.
// https://docs.google.com/file/d/0BwzA1Orbvy5WMXFLaTR1Z1p2UDg/edit
var csvFileId = '1JjShLEoLmPME6vdYbIAQy7iF5EgpHLArcJ9jxwkH-sY';
// Delete and reCreate the table.
var tableId = 'aud_info';
BigQuery.Tables.remove(projectId, datasetId, tableId);
var table = {
tableReference: {
projectId: projectId,
datasetId: datasetId,
tableId: tableId
},
schema: {
fields: [
{name: 'ListID', type: 'STRING'},
{name: 'ListName', type: 'STRING'},
{name: 'ListDescription', type: 'STRING'},
{name: 'AudienceCategory', type: 'STRING'}
]
}
};
table = BigQuery.Tables.insert(table, projectId, datasetId);
Logger.log('Table created: %s', table.id);
// Load CSV data from Drive and convert to the correct format for upload.
var file = DriveApp.getFileById(csvFileId);
var data = file.getBlob().setContentType('application/octet-stream');
// Create the data upload job.
var job = {
configuration: {
load: {
destinationTable: {
projectId: projectId,
datasetId: datasetId,
tableId: tableId
},
skipLeadingRows: 1,
allowJaggedRows: true
}
}
};
job = BigQuery.Jobs.insert(job, projectId, data);
Logger.log('Load job started. Check on the status of it here: ' +
'https://bigquery.cloud.google.com/jobs/%s', projectId);
}
What am I doing wrong? It looks like an encoding issue, but isn't Sheets already in a UTF-8 format?
My data looks like this:
When I run data.getDataAsString() to Logger, I get
%PDF-1.4 %���� 2 0 obj <>stream x���MO�@�缿bF$�a�?�FiC8X(b"����w$�PZ�if6��Ogf���0��Xo���I��?ע�P��aTYCѠs$-���O���$�O�d�&��S����B��-��Q2�?vZR�`nD��+�$�u��Y��(.7����6=��Ā�w8�ށ���K�dk-��JFJ��x���J���-)N%�L��-����[L� ��Nȣ��w0�9���a4���d��]��4Eu=G��@���V�w��FPr��K��aUݴ��GR�R�� �A��*F�p��9���ͦů�/���� endstream endobj 4 0 obj <>>>/Parent 3 0 R/MediaBox[0 0 612 792]>> endobj 5 0 obj <>stream x�� xE�?�VwO�=�3�̑L2�L.2�J��d�$ �}�`"A@9D�TT��� ���������1���U����]]V�^�u�U1���Vw�v�����{~O>��U]�U��[o�oUG��Ae����o}�9���/�{ɜW��]��q�e�...