Class: Google::Cloud::Bigquery::External::SheetsSource

Inherits:
DataSource
  • Object
show all
Defined in:
lib/google/cloud/bigquery/external.rb

Overview

SheetsSource

SheetsSource is a subclass of DataSource and represents a Google Sheets external data source that can be queried from directly, even though the data is not stored in BigQuery. Instead of loading or streaming the data, this object references the external data source.

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new

sheets_url = "https://docs.google.com/spreadsheets/d/1234567980"
sheets_table = bigquery.external sheets_url do |sheets|
  sheets.skip_leading_rows = 1
end

data = bigquery.query "SELECT * FROM my_ext_table",
                      external: { my_ext_table: sheets_table }

data.each do |row|
  puts row[:name]
end

Instance Method Summary collapse

Methods inherited from DataSource

#autodetect, #autodetect=, #avro?, #backup?, #bigtable?, #compression, #compression=, #csv?, #format, #ignore_unknown, #ignore_unknown=, #json?, #max_bad_records, #max_bad_records=, #sheets?, #urls

Instance Method Details

#skip_leading_rowsInteger

The number of rows at the top of a sheet that BigQuery will skip when reading the data. The default value is 0.

This property is useful if you have header rows that should be skipped. When autodetect is on, behavior is the following:

  • nil - Autodetect tries to detect headers in the first row. If they are not detected, the row is read as data. Otherwise data is read starting from the second row.
  • 0 - Instructs autodetect that there are no headers and data should be read starting from the first row.
  • N > 0 - Autodetect skips N-1 rows and tries to detect headers in row N. If headers are not detected, row N is just skipped. Otherwise row N is used to extract column names for the detected schema.

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new

sheets_url = "https://docs.google.com/spreadsheets/d/1234567980"
sheets_table = bigquery.external sheets_url do |sheets|
  sheets.skip_leading_rows = 1
end

sheets_table.skip_leading_rows #=> 1

Returns:

  • (Integer)


1200
1201
1202
# File 'lib/google/cloud/bigquery/external.rb', line 1200

def skip_leading_rows
  @gapi.google_sheets_options.skip_leading_rows
end

#skip_leading_rows=(row_count) ⇒ Object

Set the number of rows at the top of a sheet that BigQuery will skip when reading the data.

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new

sheets_url = "https://docs.google.com/spreadsheets/d/1234567980"
sheets_table = bigquery.external sheets_url do |sheets|
  sheets.skip_leading_rows = 1
end

sheets_table.skip_leading_rows #=> 1

Parameters:

  • row_count (Integer)

    New skip_leading_rows value



1222
1223
1224
1225
# File 'lib/google/cloud/bigquery/external.rb', line 1222

def skip_leading_rows= row_count
  frozen_check!
  @gapi.google_sheets_options.skip_leading_rows = row_count
end