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
Attributes Methods
Public Instance Methods
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.
location()
¶
↑
The geographic location where the table should reside. Possible values include EU and US. The default value is US.
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 isfalse
. (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¶ ↑
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
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]"