Learn R Programming

bigrquery (version 0.1.0)

query_exec: Run a asynchronous query and retrieve results.

Description

This is a high-level function that inserts a query job (with insert_query_job), repeatedly checks the status (with get_job) until it is complete, then retrieves the results (with list_tabledata)

Usage

query_exec(query, project, destination_table = NULL, default_dataset = NULL,
  page_size = 10000, max_pages = 10, warn = TRUE)

Arguments

query
SQL query string
project
project name
destination_table
(optional) destination table for large queries, either as a string in the format used by BigQuery, or as a list with project_id, dataset_id, and table_id entries
default_dataset
(optional) default dataset for any table references in query, either as a string in the format used by BigQuery or as a list with project_id and dataset_id entries
page_size
Number of items per page.
max_pages
maximum number of pages to retrieve. Use Inf to retrieve the complete dataset.
warn
If TRUE, warn when there are rows remaining to be pulled down from database.

See Also

Google documentation describing asynchronous queries: https://developers.google.com/bigquery/docs/queries#asyncqueries

Google documentation for handling large results: https://developers.google.com/bigquery/querying-data#largequeryresults

Examples

Run this code
project <- "fantastic-voyage-389" # put your project ID here
sql <- "SELECT year, month, day, weight_pounds FROM [publicdata:samples.natality] LIMIT 5"
query_exec(sql, project = project)
# Put the results in a table you own (which uses project by default)
query_exec(sql, project = project, destination_table = "my_dataset.results")
# Use a default dataset for the query
sql <- "SELECT year, month, day, weight_pounds FROM natality LIMIT 5"
query_exec(sql, project = project, default_dataset = "publicdata:samples")

Run the code above in your browser using DataLab