BigQuery API - Class Google::Cloud::Bigquery::External::AvroSource (v1.48.1)

Reference documentation and code samples for the BigQuery API class Google::Cloud::Bigquery::External::AvroSource.

AvroSource

AvroSource is a subclass of DataSource and represents a Avro 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.

Example

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new

avro_url = "gs://bucket/path/to/*.avro"
avro_table = bigquery.external avro_url do |avro|
  avro.use_avro_logical_types = 1
end

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

# Iterate over the first page of results
data.each do |row|
  puts row[:name]
end
# Retrieve the next page of results
data = data.next if data.next?

Methods

#use_avro_logical_types

def use_avro_logical_types() -> Boolean

Indicates whether to interpret logical types as the corresponding BigQuery data type (for example, TIMESTAMP), instead of using the raw type (for example, INTEGER).

Returns
  • (Boolean)
Example
require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new

avro_url = "gs://bucket/path/to/*.avro"
avro_table = bigquery.external avro_url do |avro|
  avro.use_avro_logical_types = true
end

avro_table.use_avro_logical_types #=> true

#use_avro_logical_types=

def use_avro_logical_types=(new_use_avro_logical_types)

Sets whether to interpret logical types as the corresponding BigQuery data type (for example, TIMESTAMP), instead of using the raw type (for example, INTEGER).

Parameter
  • new_use_avro_logical_types (Boolean) — The new use_avro_logical_types value.
Example
require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new

avro_url = "gs://bucket/path/to/*.avro"
avro_table = bigquery.external avro_url do |avro|
  avro.use_avro_logical_types = true
end

avro_table.use_avro_logical_types #=> true