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:
datasetName: the name of BigQuery data set.
tableName: the table in the data set.
schema: table schema (to map CSV file onto the records).
sourceUri: URL of the file on the bucket.
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
Create a new function called ImportCSVFileFromBucketIntoBigQuery.java.
Upload a CSV file to the GCS bucket having customer details.
Create a BigQuery table for a customer with similar columns as the CSV.
Set parameters as the datasetName, tableName, sourceUri, and schema.
Call BigQueryApi.importCSVbyURIIntoTable function with the above parameters.
Return the successful/failed response as a Result.
Last updated