Class: Google::Cloud::Bigquery::Dataset
- Inherits:
-
Object
- Object
- Google::Cloud::Bigquery::Dataset
- Defined in:
- lib/google/cloud/bigquery/dataset.rb,
lib/google/cloud/bigquery/dataset/list.rb,
lib/google/cloud/bigquery/dataset/access.rb
Overview
Dataset
Represents a Dataset. A dataset is a grouping mechanism that holds zero or more tables. Datasets are the lowest level unit of access control; you cannot control access at the table level. A dataset is contained within a specific project.
Direct Known Subclasses
Defined Under Namespace
Classes: Access, List, Updater
Attributes collapse
-
#access {|access| ... } ⇒ Google::Cloud::Bigquery::Dataset::Access
Retrieves the access rules for a Dataset.
-
#api_url ⇒ Object
A URL that can be used to access the dataset using the REST API.
-
#created_at ⇒ Object
The time when this dataset was created.
-
#dataset_id ⇒ Object
A unique ID for this dataset, without the project name.
-
#default_expiration ⇒ Object
The default lifetime of all tables in the dataset, in milliseconds.
-
#default_expiration=(new_default_expiration) ⇒ Object
Updates the default lifetime of all tables in the dataset, in milliseconds.
-
#description ⇒ Object
A user-friendly description of the dataset.
-
#description=(new_description) ⇒ Object
Updates the user-friendly description of the dataset.
-
#etag ⇒ Object
A string hash of the dataset.
-
#location ⇒ Object
The geographic location where the dataset should reside.
-
#modified_at ⇒ Object
The date when this dataset or any of its tables was last modified.
-
#name ⇒ Object
A descriptive name for the dataset.
-
#name=(new_name) ⇒ Object
Updates the descriptive name for the dataset.
-
#project_id ⇒ Object
The ID of the project containing this dataset.
Lifecycle collapse
-
#delete(force: nil) ⇒ Boolean
Permanently deletes the dataset.
Table collapse
-
#create_table(table_id, name: nil, description: nil) {|table| ... } ⇒ Google::Cloud::Bigquery::Table
Creates a new table.
-
#create_view(table_id, query, name: nil, description: nil, standard_sql: nil, legacy_sql: nil) ⇒ Google::Cloud::Bigquery::View
Creates a new view table from the given query.
-
#table(table_id) ⇒ Google::Cloud::Bigquery::Table, ...
Retrieves an existing table by ID.
-
#tables(token: nil, max: nil) ⇒ Array<Google::Cloud::Bigquery::Table>, Array<Google::Cloud::Bigquery::View>
Retrieves the list of tables belonging to the dataset.
Data collapse
-
#query(query, params: nil, max: nil, timeout: 10000, dryrun: nil, cache: true, 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, standard_sql: nil, legacy_sql: nil, large_results: nil, flatten: nil) ⇒ Google::Cloud::Bigquery::QueryJob
Queries data using the asynchronous method.
Instance Method Details
#access {|access| ... } ⇒ Google::Cloud::Bigquery::Dataset::Access
Retrieves the access rules for a Dataset. The rules can be updated when passing a block, see Access for all the methods available.
255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/google/cloud/bigquery/dataset.rb', line 255 def access ensure_full_data! access_builder = Access.from_gapi @gapi if block_given? yield access_builder if access_builder.changed? @gapi.update! access: access_builder.to_gapi patch_gapi! :access end end access_builder.freeze end |
#api_url ⇒ Object
A URL that can be used to access the dataset using the REST API.
124 125 126 127 |
# File 'lib/google/cloud/bigquery/dataset.rb', line 124 def api_url ensure_full_data! @gapi.self_link end |
#create_table(table_id, name: nil, description: nil) {|table| ... } ⇒ Google::Cloud::Bigquery::Table
Creates a new table. If you are adapting existing code that was written for the Rest API , you can pass the table's schema as a hash (see example.)
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 |
# File 'lib/google/cloud/bigquery/dataset.rb', line 359 def create_table table_id, name: nil, description: nil ensure_service! new_tb = Google::Apis::BigqueryV2::Table.new( table_reference: Google::Apis::BigqueryV2::TableReference.new( project_id: project_id, dataset_id: dataset_id, table_id: table_id)) updater = Table::Updater.new(new_tb).tap do |tb| tb.name = name unless name.nil? tb.description = description unless description.nil? end yield updater if block_given? gapi = service.insert_table dataset_id, updater.to_gapi Table.from_gapi gapi, service end |
#create_view(table_id, query, name: nil, description: nil, standard_sql: nil, legacy_sql: nil) ⇒ Google::Cloud::Bigquery::View
Creates a new view table from the given query.
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 |
# File 'lib/google/cloud/bigquery/dataset.rb', line 416 def create_view table_id, query, name: nil, description: nil, standard_sql: nil, legacy_sql: nil new_view_opts = { table_reference: Google::Apis::BigqueryV2::TableReference.new( project_id: project_id, dataset_id: dataset_id, table_id: table_id ), friendly_name: name, description: description, view: Google::Apis::BigqueryV2::ViewDefinition.new( query: query, use_legacy_sql: Convert.resolve_legacy_sql(standard_sql, legacy_sql) ) }.delete_if { |_, v| v.nil? } new_view = Google::Apis::BigqueryV2::Table.new new_view_opts gapi = service.insert_table dataset_id, new_view Table.from_gapi gapi, service end |
#created_at ⇒ Object
The time when this dataset was created.
179 180 181 182 183 184 185 186 |
# File 'lib/google/cloud/bigquery/dataset.rb', line 179 def created_at ensure_full_data! begin ::Time.at(Integer(@gapi.creation_time) / 1000.0) rescue nil end end |
#dataset_id ⇒ Object
A unique ID for this dataset, without the project name. The ID must contain only letters (a-z, A-Z), numbers (0-9), or underscores (_). The maximum length is 1,024 characters.
67 68 69 |
# File 'lib/google/cloud/bigquery/dataset.rb', line 67 def dataset_id @gapi.dataset_reference.dataset_id end |
#default_expiration ⇒ Object
The default lifetime of all tables in the dataset, in milliseconds.
154 155 156 157 158 159 160 161 |
# File 'lib/google/cloud/bigquery/dataset.rb', line 154 def default_expiration ensure_full_data! begin Integer @gapi.default_table_expiration_ms rescue nil end end |
#default_expiration=(new_default_expiration) ⇒ Object
Updates the default lifetime of all tables in the dataset, in milliseconds.
169 170 171 172 |
# File 'lib/google/cloud/bigquery/dataset.rb', line 169 def default_expiration= new_default_expiration @gapi.update! default_table_expiration_ms: new_default_expiration patch_gapi! :default_table_expiration_ms end |
#delete(force: nil) ⇒ Boolean
Permanently deletes the dataset. The dataset must be empty before it
can be deleted unless the force
option is set to true
.
288 289 290 291 292 |
# File 'lib/google/cloud/bigquery/dataset.rb', line 288 def delete force: nil ensure_service! service.delete_dataset dataset_id, force true end |
#description ⇒ Object
A user-friendly description of the dataset.
134 135 136 137 |
# File 'lib/google/cloud/bigquery/dataset.rb', line 134 def description ensure_full_data! @gapi.description end |
#description=(new_description) ⇒ Object
Updates the user-friendly description of the dataset.
144 145 146 147 |
# File 'lib/google/cloud/bigquery/dataset.rb', line 144 def description= new_description @gapi.update! description: new_description patch_gapi! :description end |
#etag ⇒ Object
A string hash of the dataset.
114 115 116 117 |
# File 'lib/google/cloud/bigquery/dataset.rb', line 114 def etag ensure_full_data! @gapi.etag end |
#location ⇒ Object
The geographic location where the dataset should reside. Possible values include EU and US. The default value is US.
208 209 210 211 |
# File 'lib/google/cloud/bigquery/dataset.rb', line 208 def location ensure_full_data! @gapi.location end |
#modified_at ⇒ Object
The date when this dataset or any of its tables was last modified.
193 194 195 196 197 198 199 200 |
# File 'lib/google/cloud/bigquery/dataset.rb', line 193 def modified_at ensure_full_data! begin ::Time.at(Integer(@gapi.last_modified_time) / 1000.0) rescue nil end end |
#name ⇒ Object
A descriptive name for the dataset.
95 96 97 |
# File 'lib/google/cloud/bigquery/dataset.rb', line 95 def name @gapi.friendly_name end |
#name=(new_name) ⇒ Object
Updates the descriptive name for the dataset.
104 105 106 107 |
# File 'lib/google/cloud/bigquery/dataset.rb', line 104 def name= new_name @gapi.update! friendly_name: new_name patch_gapi! :friendly_name end |
#project_id ⇒ Object
The ID of the project containing this dataset.
76 77 78 |
# File 'lib/google/cloud/bigquery/dataset.rb', line 76 def project_id @gapi.dataset_reference.project_id end |
#query(query, params: nil, max: nil, timeout: 10000, dryrun: nil, cache: true, standard_sql: nil, legacy_sql: nil) ⇒ Google::Cloud::Bigquery::QueryData
Queries data using the synchronous method.
Sets the current dataset as the default dataset in the query. Useful for using unqualified table names.
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.
799 800 801 802 803 804 805 806 807 808 809 |
# File 'lib/google/cloud/bigquery/dataset.rb', line 799 def query query, params: nil, max: nil, timeout: 10000, dryrun: nil, cache: true, standard_sql: nil, legacy_sql: nil = { max: max, timeout: timeout, dryrun: dryrun, cache: cache, legacy_sql: legacy_sql, standard_sql: standard_sql, params: params } [:dataset] ||= dataset_id [:project] ||= project_id ensure_service! 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, standard_sql: nil, legacy_sql: nil, large_results: nil, flatten: nil) ⇒ Google::Cloud::Bigquery::QueryJob
Queries data using the asynchronous method.
Sets the current dataset as the default dataset in the query. Useful for using unqualified table names.
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.
655 656 657 658 659 660 661 662 663 664 665 666 667 |
# File 'lib/google/cloud/bigquery/dataset.rb', line 655 def query_job query, params: nil, priority: "INTERACTIVE", cache: true, table: nil, create: nil, write: nil, standard_sql: nil, legacy_sql: nil, large_results: nil, flatten: nil = { priority: priority, cache: cache, table: table, create: create, write: write, large_results: large_results, flatten: flatten, legacy_sql: legacy_sql, standard_sql: standard_sql, params: params } [:dataset] ||= self ensure_service! gapi = service.query_job query, Job.from_gapi gapi, service end |
#table(table_id) ⇒ Google::Cloud::Bigquery::Table, ...
Retrieves an existing table by ID.
455 456 457 458 459 460 461 |
# File 'lib/google/cloud/bigquery/dataset.rb', line 455 def table table_id ensure_service! gapi = service.get_table dataset_id, table_id Table.from_gapi gapi, service rescue Google::Cloud::NotFoundError nil end |
#tables(token: nil, max: nil) ⇒ Array<Google::Cloud::Bigquery::Table>, Array<Google::Cloud::Bigquery::View>
Retrieves the list of tables belonging to the dataset.
496 497 498 499 500 501 |
# File 'lib/google/cloud/bigquery/dataset.rb', line 496 def tables token: nil, max: nil ensure_service! = { token: token, max: max } gapi = service.list_tables dataset_id, Table::List.from_gapi gapi, service, dataset_id, max end |