Kelvin Lam
Kelvin Lam

Reputation: 11

How to skip leading row when loading data into BigQuery with Ruby?

I have been following Google's documentation to load data to BigQuery with Ruby using the following code

# project_id      = "Your Google Cloud project ID"
# dataset_id      = "ID of the dataset containing table"
# table_id        = "ID of the table to import file data into"
# local_file_path = "Path to local file to import into BigQuery table"

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new project: project_id
dataset  = bigquery.dataset dataset_id
table    = dataset.table table_id

puts "Importing data from file: #{local_file_path}"
load_job = table.load_job local_file_path

puts "Waiting for load job to complete: #{load_job.job_id}"
load_job.wait_until_done!

puts "Data imported"

from: https://cloud.google.com/bigquery/docs/loading-data-local

Everything works fine but my CSV file needs to skip the first two rows.

I have read through further documentation to see the instance method of skip_leading_rows but not sure how to use it. https://googleapis.github.io/google-cloud-ruby/docs/google-cloud-bigquery/latest/Google/Cloud/Bigquery/LoadJob.html

Appreciate some advice on this. Thanks!

Upvotes: 0

Views: 1977

Answers (1)

spickermann
spickermann

Reputation: 106932

According to the documentation I would expect this to work:

puts "Importing data from file: #{local_file_path}"
load_job = table.load_job(local_file_path, skip_leading: 1)

Upvotes: 2

Related Questions