Class: Google::Cloud::Bigquery::Project
- Inherits:
-
Object
- Object
- Google::Cloud::Bigquery::Project
- Defined in:
- lib/google/cloud/bigquery/project.rb,
lib/google/cloud/bigquery/project/list.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.
Defined Under Namespace
Classes: List
Instance Attribute Summary collapse
-
#name ⇒ String?
readonly
The descriptive name of the project.
-
#numeric_id ⇒ Integer?
readonly
The numeric ID of the 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.
-
#projects(token: nil, max: nil) ⇒ Array<Google::Cloud::Bigquery::Project>
Retrieves the list of all projects for which the currently authorized account has been granted any project role.
-
#query(query, params: nil, max: nil, timeout: 10000, dryrun: nil, cache: true, dataset: nil, project: nil, standard_sql: nil, legacy_sql: nil) ⇒ Google::Cloud::Bigquery::QueryData
Queries data using the synchronous method.
-
#query_job(query, params: nil, priority: "INTERACTIVE", cache: true, table: nil, create: nil, write: nil, dataset: nil, standard_sql: nil, legacy_sql: nil, large_results: nil, flatten: nil) ⇒ Google::Cloud::Bigquery::QueryJob
Queries data using the asynchronous method.
-
#time(hour, minute, second) ⇒ Bigquery::Time
Creates a Bigquery::Time object to represent a time, independent of a specific date.
Constructor Details
#initialize(service) ⇒ Project
Creates a new Service instance.
65 66 67 |
# File 'lib/google/cloud/bigquery/project.rb', line 65 def initialize service @service = service end |
Instance Attribute Details
#name ⇒ String? (readonly)
The descriptive name of the project. Can only be present if the project was retrieved with #projects.
54 55 56 |
# File 'lib/google/cloud/bigquery/project.rb', line 54 def name @name end |
#numeric_id ⇒ Integer? (readonly)
The numeric ID of the project. Can only be present if the project was retrieved with #projects.
54 55 56 |
# File 'lib/google/cloud/bigquery/project.rb', line 54 def numeric_id @numeric_id 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.
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 |
# File 'lib/google/cloud/bigquery/project.rb', line 494 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.
440 441 442 443 444 445 446 |
# File 'lib/google/cloud/bigquery/project.rb', line 440 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.
559 560 561 562 563 564 |
# File 'lib/google/cloud/bigquery/project.rb', line 559 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.
581 582 583 584 585 586 587 |
# File 'lib/google/cloud/bigquery/project.rb', line 581 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.
638 639 640 641 642 643 |
# File 'lib/google/cloud/bigquery/project.rb', line 638 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.
82 83 84 |
# File 'lib/google/cloud/bigquery/project.rb', line 82 def project service.project end |
#projects(token: nil, max: nil) ⇒ Array<Google::Cloud::Bigquery::Project>
Retrieves the list of all projects for which the currently authorized account has been granted any project role. The returned project instances share the same credentials as the project used to retrieve them, but lazily create a new API connection for interactions with the BigQuery service.
686 687 688 689 690 691 |
# File 'lib/google/cloud/bigquery/project.rb', line 686 def projects token: nil, max: nil ensure_service! = { token: token, max: max } gapi = service.list_projects Project::List.from_gapi gapi, service, max end |
#query(query, params: nil, max: nil, timeout: 10000, dryrun: nil, cache: true, dataset: nil, project: nil, standard_sql: nil, legacy_sql: nil) ⇒ Google::Cloud::Bigquery::QueryData
Queries data using the synchronous method.
When using standard SQL and passing arguments using params
, Ruby
types are mapped to BigQuery types as follows:
BigQuery | Ruby | Notes |
---|---|---|
BOOL |
true /false |
|
INT64 |
Integer |
|
FLOAT64 |
Float |
|
STRING |
STRING |
|
DATETIME |
DateTime |
DATETIME does not support time zone. |
DATE |
Date |
|
TIMESTAMP |
Time |
|
TIME |
Google::Cloud::BigQuery::Time |
|
BYTES |
File , IO , StringIO , or similar |
|
ARRAY |
Array |
Nested arrays, nil values are not supported. |
STRUCT |
Hash |
Hash keys may be strings or symbols. |
See Data Types for an overview of each BigQuery data type, including allowed values.
412 413 414 415 416 417 418 419 420 421 422 |
# File 'lib/google/cloud/bigquery/project.rb', line 412 def query query, params: nil, max: nil, timeout: 10000, dryrun: nil, cache: true, dataset: nil, project: nil, standard_sql: nil, legacy_sql: nil ensure_service! = { max: max, timeout: timeout, dryrun: dryrun, cache: cache, dataset: dataset, project: project, legacy_sql: legacy_sql, standard_sql: standard_sql, params: params } gapi = service.query query, QueryData.from_gapi gapi, service end |
#query_job(query, params: nil, priority: "INTERACTIVE", cache: true, table: nil, create: nil, write: nil, dataset: nil, standard_sql: nil, legacy_sql: nil, large_results: nil, flatten: nil) ⇒ Google::Cloud::Bigquery::QueryJob
Queries data using the asynchronous method.
When using standard SQL and passing arguments using params
, Ruby
types are mapped to BigQuery types as follows:
BigQuery | Ruby | Notes |
---|---|---|
BOOL |
true /false |
|
INT64 |
Integer |
|
FLOAT64 |
Float |
|
STRING |
STRING |
|
DATETIME |
DateTime |
DATETIME does not support time zone. |
DATE |
Date |
|
TIMESTAMP |
Time |
|
TIME |
Google::Cloud::BigQuery::Time |
|
BYTES |
File , IO , StringIO , or similar |
|
ARRAY |
Array |
Nested arrays, nil values are not supported. |
STRUCT |
Hash |
Hash keys may be strings or symbols. |
See Data Types for an overview of each BigQuery data type, including allowed values.
251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/google/cloud/bigquery/project.rb', line 251 def query_job query, params: nil, priority: "INTERACTIVE", cache: true, table: nil, create: nil, write: nil, dataset: nil, standard_sql: nil, legacy_sql: nil, large_results: nil, flatten: nil ensure_service! = { priority: priority, cache: cache, table: table, create: create, write: write, large_results: large_results, flatten: flatten, dataset: dataset, legacy_sql: legacy_sql, standard_sql: standard_sql, params: params } gapi = service.query_job query, Job.from_gapi gapi, service end |
#time(hour, minute, second) ⇒ Bigquery::Time
Creates a Bigquery::Time object to represent a time, independent of a specific date.
734 735 736 |
# File 'lib/google/cloud/bigquery/project.rb', line 734 def time hour, minute, second Bigquery::Time.new "#{hour}:#{minute}:#{second}" end |