Gcloud::Bigquery::View

View

A view is a virtual table defined by a SQL query. You can query views in the browser tool, or by using a query job.

BigQuery's views are logical views, not materialized views, which means that the query that defines the view is re-executed every time the view is queried. Queries are billed according to the total amount of data in all table fields referenced directly or indirectly by the top-level query.

require "gcloud"

gcloud = Gcloud.new
bigquery = gcloud.bigquery
dataset = bigquery.dataset "my_dataset"
view = dataset.create_view "my_view",
         "SELECT name, age FROM [proj:dataset.users]"

Methods

Public Instance Methods

refresh!()

Alias for: reload!

Attributes Methods

Public Instance Methods

created_at()

The time when this table was created.

dataset_id()

The ID of the Dataset containing this table.

description()

The description of the table.

etag()

A string hash of the dataset.

expires_at()

The time when this table expires. If not present, the table will persist indefinitely. Expired tables will be deleted and their storage reclaimed.

fields()

The fields of the table.

headers()

The names of the columns in the table.

location()

The geographic location where the table should reside. Possible values include EU and US. The default value is US.

modified_at()

The date when this table was last modified.

name()

The name of the table.

project_id()

The ID of the Project containing this table.

query()

The query that executes each time the view is loaded.

schema()

The schema of the table.

table?()

Checks if the table's type is “TABLE”.

table_id()

A unique ID for this table. The ID must contain only letters (a-z, A-Z), numbers (0-9), or underscores (_). The maximum length is 1,024 characters.

url()

A URL that can be used to access the dataset using the REST API.

view?()

Checks if the table's type is “VIEW”.

Data Methods

Public Instance Methods

data(options = {})

Runs a query to retrieve all data from the view.

Parameters

options

An optional Hash for controlling additional behavior. (Hash)

options[:max]

The maximum number of rows of data to return per page of results. Setting this flag to a small value such as 1000 and then paging through results might improve reliability when the query result set is large. In addition to this limit, responses are also limited to 10 MB. By default, there is no maximum row count, and only the byte limit applies. (Integer)

options[:timeout]

How long to wait for the query to complete, in milliseconds, before the request times out and returns. Note that this is only a timeout for the request, not the query. If the query takes longer to run than the timeout value, the call returns without any results and with Gcloud::Bigquery::QueryData#complete? set to false. The default value is 10000 milliseconds (10 seconds). (Integer)

options[:dryrun]

If set to true, BigQuery doesn't run the job. Instead, if the query is valid, BigQuery returns statistics about the job such as how many bytes would be processed. If the query is invalid, an error returns. The default value is false. (Boolean)

options[:cache]

Whether to look for the result in the query cache. The query cache is a best-effort cache that will be flushed whenever tables in the query are modified. The default value is true. For more information, see query caching. (Boolean)

Returns

Gcloud::Bigquery::QueryData

Example

require "gcloud"

gcloud = Gcloud.new
bigquery = gcloud.bigquery
dataset = bigquery.dataset "my_dataset"
view = dataset.table "my_view"

data = view.data
data.each do |row|
  puts row["first_name"]
end
more_data = data.next if data.next?

Lifecycle Methods

Public Instance Methods

delete()

Permanently deletes the table.

Returns

true if the table was deleted.

Example

require "gcloud"

gcloud = Gcloud.new
bigquery = gcloud.bigquery
dataset = bigquery.dataset "my_dataset"
table = dataset.table "my_table"

table.delete

description=(new_description)

Updates the description of the table.

name=(new_name)

Updates the name of the table.

query=(new_query)

Updates the query that executes each time the view is loaded. See the BigQuery Query Reference .

Parameters

new_query

The query that defines the view. (String)

Example

require "gcloud"

gcloud = Gcloud.new
bigquery = gcloud.bigquery
dataset = bigquery.dataset "my_dataset"
view = dataset.table "my_view"

view.query = "SELECT first_name FROM [my_project:my_dataset.my_table]"

reload!()

Reloads the table with current data from the BigQuery service.

Also aliased as: refresh!