Class: Google::Cloud::Bigquery::Project
- Inherits:
-
Object
- Object
- Google::Cloud::Bigquery::Project
- Defined in:
- lib/google/cloud/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.
Google::Cloud::Bigquery::Project is the main object for interacting with Google BigQuery. Dataset objects are created, accessed, and deleted by Google::Cloud::Bigquery::Project.
Instance Method Summary collapse
-
#create_dataset(dataset_id, name: nil, description: nil, expiration: nil, location: nil) {|access| ... } ⇒ Google::Cloud::Bigquery::Dataset
Creates a new dataset.
-
#dataset(dataset_id) ⇒ Google::Cloud::Bigquery::Dataset?
Retrieves an existing dataset by ID.
-
#datasets(all: nil, token: nil, max: nil) ⇒ Array<Google::Cloud::Bigquery::Dataset>
Retrieves the list of datasets belonging to the project.
-
#initialize(service) ⇒ Project
constructor
Creates a new Service instance.
-
#job(job_id) ⇒ Google::Cloud::Bigquery::Job?
Retrieves an existing job by ID.
-
#jobs(all: nil, token: nil, max: nil, filter: nil) ⇒ Array<Google::Cloud::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) ⇒ Google::Cloud::Bigquery::QueryData
Queries data using the synchronous method.
-
#query_job(query, priority: "INTERACTIVE", cache: true, table: nil, create: nil, write: nil, large_results: nil, flatten: nil, dataset: nil) ⇒ Google::Cloud::Bigquery::QueryJob
Queries data using the asynchronous method.
Constructor Details
#initialize(service) ⇒ Project
Creates a new Service instance.
57 58 59 |
# File 'lib/google/cloud/bigquery/project.rb', line 57 def initialize service @service = service end |
Instance Method Details
#create_dataset(dataset_id, name: nil, description: nil, expiration: nil, location: nil) {|access| ... } ⇒ Google::Cloud::Bigquery::Dataset
Creates a new dataset.
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
# File 'lib/google/cloud/bigquery/project.rb', line 313 def create_dataset dataset_id, name: nil, description: nil, expiration: nil, location: nil ensure_service! new_ds = Google::Apis::BigqueryV2::Dataset.new( dataset_reference: Google::Apis::BigqueryV2::DatasetReference.new( project_id: project, dataset_id: dataset_id)) # Can set location only on creation, no Dataset#location method new_ds.update! location: location unless location.nil? updater = Dataset::Updater.new(new_ds).tap do |b| b.name = name unless name.nil? b.description = description unless description.nil? b.default_expiration = expiration unless expiration.nil? end if block_given? yield updater updater.check_for_mutated_access! end gapi = service.insert_dataset new_ds Dataset.from_gapi gapi, service end |
#dataset(dataset_id) ⇒ Google::Cloud::Bigquery::Dataset?
Retrieves an existing dataset by ID.
248 249 250 251 252 253 254 |
# File 'lib/google/cloud/bigquery/project.rb', line 248 def dataset dataset_id ensure_service! gapi = service.get_dataset dataset_id Dataset.from_gapi gapi, service rescue Google::Cloud::NotFoundError nil end |
#datasets(all: nil, token: nil, max: nil) ⇒ Array<Google::Cloud::Bigquery::Dataset>
Retrieves the list of datasets belonging to the project.
381 382 383 384 385 386 |
# File 'lib/google/cloud/bigquery/project.rb', line 381 def datasets all: nil, token: nil, max: nil ensure_service! = { all: all, token: token, max: max } gapi = service.list_datasets Dataset::List.from_gapi gapi, service, all, max end |
#job(job_id) ⇒ Google::Cloud::Bigquery::Job?
Retrieves an existing job by ID.
404 405 406 407 408 409 410 |
# File 'lib/google/cloud/bigquery/project.rb', line 404 def job job_id ensure_service! gapi = service.get_job job_id Job.from_gapi gapi, service rescue Google::Cloud::NotFoundError nil end |
#jobs(all: nil, token: nil, max: nil, filter: nil) ⇒ Array<Google::Cloud::Bigquery::Job>
Retrieves the list of jobs belonging to the project.
464 465 466 467 468 469 |
# File 'lib/google/cloud/bigquery/project.rb', line 464 def jobs all: nil, token: nil, max: nil, filter: nil ensure_service! = { all: all, token: token, max: max, filter: filter } gapi = service.list_jobs Job::List.from_gapi gapi, service, all, max, filter end |
#project ⇒ Object
The BigQuery project connected to.
73 74 75 |
# File 'lib/google/cloud/bigquery/project.rb', line 73 def project service.project end |
#query(query, max: nil, timeout: 10000, dryrun: nil, cache: true, dataset: nil, project: nil) ⇒ Google::Cloud::Bigquery::QueryData
Queries data using the synchronous method.
222 223 224 225 226 227 228 229 |
# File 'lib/google/cloud/bigquery/project.rb', line 222 def query query, max: nil, timeout: 10000, dryrun: nil, cache: true, dataset: nil, project: nil ensure_service! = { max: max, timeout: timeout, dryrun: dryrun, cache: cache, dataset: dataset, project: project } gapi = service.query query, QueryData.from_gapi gapi, service end |
#query_job(query, priority: "INTERACTIVE", cache: true, table: nil, create: nil, write: nil, large_results: nil, flatten: nil, dataset: nil) ⇒ Google::Cloud::Bigquery::QueryJob
Queries data using the asynchronous method.
149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/google/cloud/bigquery/project.rb', line 149 def query_job query, priority: "INTERACTIVE", cache: true, table: nil, create: nil, write: nil, large_results: nil, flatten: nil, dataset: nil ensure_service! = { priority: priority, cache: cache, table: table, create: create, write: write, large_results: large_results, flatten: flatten, dataset: dataset } gapi = service.query_job query, Job.from_gapi gapi, service end |