Import a CSV file from bucket into BigQuery

This section describes how to import a csv file from a Google cloud storage bucket into BigQuery

Code: /lessons/Import_a_CSV_file_from_Bucket_into_BigQuery

In this example, the function code accepts the following parameters:

  1. datasetName: the name of BigQuery data set.

  2. tableName: the table in the data set.

  3. schema: table schema (to map CSV file onto the records).

  4. sourceUri: URL of the file on the bucket.

  5. numberOfRowsToSkip: number of rows to skip, default being 1

It imports the contents of the CSV into the BigQuery table and returns a success/failed response.

Prerequisite

In this lesson it is assumed that the CSV file exists in the bucket

Steps

  1. Create a new function called ImportCSVFileFromBucketIntoBigQuery.java.

  2. Upload a CSV file to the GCS bucket having customer details.

  3. Create a BigQuery table for a customer with similar columns as the CSV.

  4. Set parameters as the datasetName, tableName, sourceUri, and schema.

  5. Call BigQueryApi.importCSVbyURIIntoTable function with the above parameters.

  6. Return the successful/failed response as a Result.

Last updated