Ilja
Ilja

Reputation: 1053

BigQuery - upload csv with schema autodetect via apps script

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

Upvotes: 0

Views: 749

Answers (2)

Ilja
Ilja

Reputation: 1053

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);

Upvotes: 3

Elliott Brossard
Elliott Brossard

Reputation: 33765

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

Upvotes: 5

Related Questions