Class: Gcloud::Bigquery::Project
- Inherits:
-
Object
- Object
- Gcloud::Bigquery::Project
- Defined in:
- lib/gcloud/bigquery/project.rb
Overview
# Project
Projects are top-level containers in Google Cloud Platform. They store information about billing and authorized users, and they contain BigQuery data. Each project has a friendly name and a unique ID.
Gcloud::Bigquery::Project is the main object for interacting with Google BigQuery. Dataset objects are created, accessed, and deleted by Gcloud::Bigquery::Project.
See Gcloud#bigquery
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
-
#create_dataset(dataset_id, name: nil, description: nil, expiration: nil, access: nil, location: nil) {|access| ... } ⇒ Gcloud::Bigquery::Dataset
Creates a new dataset.
-
#dataset(dataset_id) ⇒ Gcloud::Bigquery::Dataset?
Retrieves an existing dataset by ID.
-
#datasets(all: nil, token: nil, max: nil) ⇒ Array<Gcloud::Bigquery::Dataset>
Retrieves the list of datasets belonging to the project.
-
#initialize(project, credentials) ⇒ Project
constructor
Creates a new Connection instance.
-
#job(job_id) ⇒ Gcloud::Bigquery::Job?
Retrieves an existing job by ID.
-
#jobs(all: nil, token: nil, max: nil, filter: nil) ⇒ Array<Gcloud::Bigquery::Job>
Retrieves the list of jobs belonging to the project.
-
#project ⇒ Object
The BigQuery project connected to.
-
#query(query, max: nil, timeout: 10000, dryrun: nil, cache: true, dataset: nil, project: nil) ⇒ Gcloud::Bigquery::QueryData
Queries data using the [synchronous method](cloud.google.com/bigquery/querying-data).
-
#query_job(query, priority: "INTERACTIVE", cache: true, table: nil, create: nil, write: nil, large_results: nil, flatten: nil, dataset: nil) ⇒ Gcloud::Bigquery::QueryJob
Queries data using the [asynchronous method](cloud.google.com/bigquery/querying-data).
Constructor Details
#initialize(project, credentials) ⇒ Project
Creates a new Connection instance.
See Gcloud.bigquery
56 57 58 59 60 |
# File 'lib/gcloud/bigquery/project.rb', line 56 def initialize project, credentials project = project.to_s # Always cast to a string fail ArgumentError, "project is missing" if project.empty? @connection = Connection.new project, credentials end |
Instance Attribute Details
#connection ⇒ Object
50 51 52 |
# File 'lib/gcloud/bigquery/project.rb', line 50 def connection @connection end |
Class Method Details
.default_project ⇒ Object
79 80 81 82 83 84 |
# File 'lib/gcloud/bigquery/project.rb', line 79 def self.default_project ENV["BIGQUERY_PROJECT"] || ENV["GCLOUD_PROJECT"] || ENV["GOOGLE_CLOUD_PROJECT"] || Gcloud::GCE.project_id end |
Instance Method Details
#create_dataset(dataset_id, name: nil, description: nil, expiration: nil, access: nil, location: nil) {|access| ... } ⇒ Gcloud::Bigquery::Dataset
Creates a new dataset.
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 |
# File 'lib/gcloud/bigquery/project.rb', line 315 def create_dataset dataset_id, name: nil, description: nil, expiration: nil, access: nil, location: nil if block_given? access_builder = Dataset::Access.new connection.default_access_rules, "projectId" => project yield access_builder access = access_builder.access if access_builder.changed? end ensure_connection! = { name: name, description: description, expiration: expiration, access: access, location: location } resp = connection.insert_dataset dataset_id, return Dataset.from_gapi(resp.data, connection) if resp.success? fail ApiError.from_response(resp) end |
#dataset(dataset_id) ⇒ Gcloud::Bigquery::Dataset?
Retrieves an existing dataset by ID.
243 244 245 246 247 248 249 250 251 252 |
# File 'lib/gcloud/bigquery/project.rb', line 243 def dataset dataset_id ensure_connection! resp = connection.get_dataset dataset_id if resp.success? Dataset.from_gapi resp.data, connection else return nil if resp.status == 404 fail ApiError.from_response(resp) end end |
#datasets(all: nil, token: nil, max: nil) ⇒ Array<Gcloud::Bigquery::Dataset>
Retrieves the list of datasets belonging to the project.
381 382 383 384 385 386 387 388 389 390 |
# File 'lib/gcloud/bigquery/project.rb', line 381 def datasets all: nil, token: nil, max: nil ensure_connection! = { all: all, token: token, max: max } resp = connection.list_datasets if resp.success? Dataset::List.from_response resp, connection else fail ApiError.from_response(resp) end end |
#job(job_id) ⇒ Gcloud::Bigquery::Job?
Retrieves an existing job by ID.
408 409 410 411 412 413 414 415 416 417 |
# File 'lib/gcloud/bigquery/project.rb', line 408 def job job_id ensure_connection! resp = connection.get_job job_id if resp.success? Job.from_gapi resp.data, connection else return nil if resp.status == 404 fail ApiError.from_response(resp) end end |
#jobs(all: nil, token: nil, max: nil, filter: nil) ⇒ Array<Gcloud::Bigquery::Job>
Retrieves the list of jobs belonging to the project.
472 473 474 475 476 477 478 479 480 481 |
# File 'lib/gcloud/bigquery/project.rb', line 472 def jobs all: nil, token: nil, max: nil, filter: nil ensure_connection! = { all: all, token: token, max: max, filter: filter } resp = connection.list_jobs if resp.success? Job::List.from_response resp, connection else fail ApiError.from_response(resp) end end |
#project ⇒ Object
The BigQuery project connected to.
73 74 75 |
# File 'lib/gcloud/bigquery/project.rb', line 73 def project connection.project end |
#query(query, max: nil, timeout: 10000, dryrun: nil, cache: true, dataset: nil, project: nil) ⇒ Gcloud::Bigquery::QueryData
Queries data using the [synchronous method](cloud.google.com/bigquery/querying-data).
213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/gcloud/bigquery/project.rb', line 213 def query query, max: nil, timeout: 10000, dryrun: nil, cache: true, dataset: nil, project: nil ensure_connection! = { max: max, timeout: timeout, dryrun: dryrun, cache: cache, dataset: dataset, project: project } resp = connection.query query, if resp.success? QueryData.from_gapi resp.data, connection else fail ApiError.from_response(resp) end end |
#query_job(query, priority: "INTERACTIVE", cache: true, table: nil, create: nil, write: nil, large_results: nil, flatten: nil, dataset: nil) ⇒ Gcloud::Bigquery::QueryJob
Queries data using the [asynchronous method](cloud.google.com/bigquery/querying-data).
148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/gcloud/bigquery/project.rb', line 148 def query_job query, priority: "INTERACTIVE", cache: true, table: nil, create: nil, write: nil, large_results: nil, flatten: nil, dataset: nil ensure_connection! = { priority: priority, cache: cache, table: table, create: create, write: write, large_results: large_results, flatten: flatten, dataset: dataset } resp = connection.query_job query, if resp.success? Job.from_gapi resp.data, connection else fail ApiError.from_response(resp) end end |