0
votes

I need to upload data to BigQuery from Drive. I found these two explanations (Upload CSV, BQ Jobs),

However, I don't want to define the schema everytime anew. In manual upload you can check the 'autodetect' but in the script I can't find how to do it.

Thanks

2

2 Answers

5
votes

With the jobs.load API, you are looking for the configuration.load.autodetect option. There should be a similarly named setting for Apps Script.

3
votes

Thanks Elliot.

Here is the updated request:

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,
            autodetect: true
                 }
              }
           };

job = BigQuery.Jobs.insert(job, projectId, data);