Loading data from a file in Google Cloud Storage to a BigQuery table

The following code imports data from a file stored in Google Cloud Storage to the specified table in the specified dataset. To do the import, the service account must have the following permissions enabled under the IAM & Admin section:

  • BigQuery Data Owner
  • BigQuery Job User
  • Storage Object Viewer

The data can be loaded into the table using one of the following modes; specify it in the CreateLoadJobOptions.WriteDisposition property using the enum WriteDisposition:

  • WriteAppend: Appends the records from the file or query to the table
  • WriteTruncate: Overwrites the records in the table with the records from the file or query
  • WriteIfEmpty: Writes records to the table only if it is empty or not yet created
The date format must be in YYYY-MM-DD format in the file for BigQuery to successfully import the data from the file into the table.

Call the import data function in the main method and pass the required parameters to import data to the correct dataset and table in the project:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.41.235