Class: Google::Cloud::Bigquery::Table
- Inherits:
-
Object
- Object
- Google::Cloud::Bigquery::Table
- Defined in:
- lib/google/cloud/bigquery/table.rb,
lib/google/cloud/bigquery/table/list.rb,
lib/google/cloud/bigquery/table/async_inserter.rb
Overview
Table
A named resource representing a BigQuery table that holds zero or more records. Every table is defined by a schema that may contain nested and repeated fields.
The Table class can also represent a view, which is a virtual table defined by a SQL query. BigQuery's views are logical views, not materialized views, which means that the query that defines the view is re-executed every time the view is queried. Queries are billed according to the total amount of data in all table fields referenced directly or indirectly by the top-level query. (See #view?, #query, #query=, and Dataset#create_view.)
Direct Known Subclasses
Defined Under Namespace
Classes: AsyncInserter, List, Updater
Attributes collapse
-
#api_url ⇒ String?
A URL that can be used to access the table using the REST API.
-
#buffer_bytes ⇒ Integer?
A lower-bound estimate of the number of bytes currently in this table's streaming buffer, if one is present.
-
#buffer_oldest_at ⇒ Time?
The time of the oldest entry currently in this table's streaming buffer, if one is present.
-
#buffer_rows ⇒ Integer?
A lower-bound estimate of the number of rows currently in this table's streaming buffer, if one is present.
-
#created_at ⇒ Time?
The time when this table was created.
-
#dataset_id ⇒ String
The ID of the
Dataset
containing this table. -
#description ⇒ String?
A user-friendly description of the table.
-
#description=(new_description) ⇒ Object
Updates the user-friendly description of the table.
-
#etag ⇒ String?
The ETag hash of the table.
-
#expires_at ⇒ Time?
The time when this table expires.
-
#external ⇒ External::DataSource?
The External::DataSource (or subclass) object that represents the external data source that the table represents.
-
#external=(external) ⇒ Object
Set the External::DataSource (or subclass) object that represents the external data source that the table represents.
-
#external? ⇒ Boolean?
Checks if the table's type is "EXTERNAL", indicating that the table represents an External Data Source.
-
#fields ⇒ Array<Schema::Field>?
The fields of the table, obtained from its schema.
-
#headers ⇒ Array<Symbol>?
The names of the columns in the table, obtained from its schema.
-
#id ⇒ String?
The combined Project ID, Dataset ID, and Table ID for this table, in the format specified by the Legacy SQL Query Reference:
project_name:datasetId.tableId
. -
#labels ⇒ Hash<String, String>?
A hash of user-provided labels associated with this table.
-
#labels=(labels) ⇒ Object
Updates the hash of user-provided labels associated with this table.
-
#location ⇒ String?
The geographic location where the table should reside.
-
#modified_at ⇒ Time?
The date when this table was last modified.
-
#name ⇒ String?
The name of the table.
-
#name=(new_name) ⇒ Object
Updates the name of the table.
-
#project_id ⇒ String
The ID of the
Project
containing this table. -
#query ⇒ String
The query that executes each time the view is loaded.
-
#query_id(standard_sql: nil, legacy_sql: nil) ⇒ String
The value returned by #id, wrapped in square brackets if the Project ID contains dashes, as specified by the Query Reference.
-
#query_legacy_sql? ⇒ Boolean
Checks if the view's query is using legacy sql.
-
#query_standard_sql? ⇒ Boolean
Checks if the view's query is using standard sql.
-
#query_udfs ⇒ Array<String>
The user-defined function resources used in the view's query.
-
#schema(replace: false) {|schema| ... } ⇒ Google::Cloud::Bigquery::Schema?
Returns the table's schema.
-
#table? ⇒ Boolean?
Checks if the table's type is "TABLE".
-
#table_id ⇒ String
A unique ID for this table.
-
#time_partitioning? ⇒ Boolean?
Checks if the table is time-partitioned.
-
#time_partitioning_expiration ⇒ Integer?
The expiration for the table partitions, if any, in seconds.
-
#time_partitioning_expiration=(expiration) ⇒ Object
Sets the partition expiration for the table.
-
#time_partitioning_type ⇒ String?
The period for which the table is partitioned, if any.
-
#time_partitioning_type=(type) ⇒ Object
Sets the partitioning for the table.
-
#view? ⇒ Boolean?
Checks if the table's type is "VIEW", indicating that the table represents a BigQuery view.
Data collapse
-
#bytes_count ⇒ Integer?
The number of bytes in the table.
-
#copy(destination_table, create: nil, write: nil) ⇒ Boolean
Copies the data from the table to another table using a synchronous method that blocks for a response.
-
#copy_job(destination_table, create: nil, write: nil, dryrun: nil, job_id: nil, prefix: nil, labels: nil) ⇒ Google::Cloud::Bigquery::CopyJob
Copies the data from the table to another table using an asynchronous method.
-
#data(token: nil, max: nil, start: nil) ⇒ Google::Cloud::Bigquery::Data
Retrieves data from the table.
-
#extract(extract_url, format: nil, compression: nil, delimiter: nil, header: nil) ⇒ Boolean
Extracts the data from the table to a Google Cloud Storage file using a synchronous method that blocks for a response.
-
#extract_job(extract_url, format: nil, compression: nil, delimiter: nil, header: nil, dryrun: nil, job_id: nil, prefix: nil, labels: nil) ⇒ Google::Cloud::Bigquery::ExtractJob
Extracts the data from the table to a Google Cloud Storage file using an asynchronous method.
-
#insert(rows, skip_invalid: nil, ignore_unknown: nil) ⇒ Google::Cloud::Bigquery::InsertResponse
Inserts data into the table for near-immediate querying, without the need to complete a load operation before the data can appear in query results.
-
#insert_async(skip_invalid: nil, ignore_unknown: nil, max_bytes: 10000000, max_rows: 500, interval: 10, threads: 4) {|response| ... } ⇒ Table::AsyncInserter
Create an asynchronous inserter object used to insert rows in batches.
-
#load(file, format: nil, create: nil, write: nil, projection_fields: nil, jagged_rows: nil, quoted_newlines: nil, encoding: nil, delimiter: nil, ignore_unknown: nil, max_bad_records: nil, quote: nil, skip_leading: nil, autodetect: nil, null_marker: nil) ⇒ Google::Cloud::Bigquery::LoadJob
Loads data into the table.
-
#load_job(file, format: nil, create: nil, write: nil, projection_fields: nil, jagged_rows: nil, quoted_newlines: nil, encoding: nil, delimiter: nil, ignore_unknown: nil, max_bad_records: nil, quote: nil, skip_leading: nil, dryrun: nil, job_id: nil, prefix: nil, labels: nil, autodetect: nil, null_marker: nil) ⇒ Google::Cloud::Bigquery::LoadJob
Loads data into the table.
-
#rows_count ⇒ Integer?
The number of rows in the table.
Lifecycle collapse
-
#delete ⇒ Boolean
Permanently deletes the table.
-
#exists? ⇒ Boolean
Determines whether the table exists in the BigQuery service.
-
#query=(new_query) ⇒ Object
Updates the query that executes each time the view is loaded.
-
#reference? ⇒ Boolean
Whether the table was created without retrieving the resource representation from the BigQuery service.
-
#reload! ⇒ Google::Cloud::Bigquery::Table
(also: #refresh!)
Reloads the table with current data from the BigQuery service.
-
#resource? ⇒ Boolean
Whether the table was created with a resource representation from the BigQuery service.
-
#resource_full? ⇒ Boolean
Whether the table was created with a full resource representation from the BigQuery service.
-
#resource_partial? ⇒ Boolean
Whether the table was created with a partial resource representation from the BigQuery service by retrieval through Dataset#tables.
-
#set_query(query, standard_sql: nil, legacy_sql: nil, udfs: nil) ⇒ Object
Updates the query that executes each time the view is loaded.
Instance Method Details
#api_url ⇒ String?
A URL that can be used to access the table using the REST API.
379 380 381 382 383 |
# File 'lib/google/cloud/bigquery/table.rb', line 379 def api_url return nil if reference? ensure_full_data! @gapi.self_link end |
#buffer_bytes ⇒ Integer?
A lower-bound estimate of the number of bytes currently in this table's streaming buffer, if one is present. This field will be absent if the table is not being streamed to or if there is no data in the streaming buffer.
791 792 793 794 795 |
# File 'lib/google/cloud/bigquery/table.rb', line 791 def buffer_bytes return nil if reference? ensure_full_data! @gapi.streaming_buffer.estimated_bytes if @gapi.streaming_buffer end |
#buffer_oldest_at ⇒ Time?
The time of the oldest entry currently in this table's streaming buffer, if one is present. This field will be absent if the table is not being streamed to or if there is no data in the streaming buffer.
825 826 827 828 829 830 831 832 833 834 835 |
# File 'lib/google/cloud/bigquery/table.rb', line 825 def buffer_oldest_at return nil if reference? ensure_full_data! return nil unless @gapi.streaming_buffer oldest_entry_time = @gapi.streaming_buffer.oldest_entry_time begin ::Time.at(Integer(oldest_entry_time) / 1000.0) rescue nil end end |
#buffer_rows ⇒ Integer?
A lower-bound estimate of the number of rows currently in this table's streaming buffer, if one is present. This field will be absent if the table is not being streamed to or if there is no data in the streaming buffer.
809 810 811 812 813 |
# File 'lib/google/cloud/bigquery/table.rb', line 809 def buffer_rows return nil if reference? ensure_full_data! @gapi.streaming_buffer.estimated_rows if @gapi.streaming_buffer end |
#bytes_count ⇒ Integer?
The number of bytes in the table.
424 425 426 427 428 429 430 431 432 |
# File 'lib/google/cloud/bigquery/table.rb', line 424 def bytes_count return nil if reference? ensure_full_data! begin Integer @gapi.num_bytes rescue nil end end |
#copy(destination_table, create: nil, write: nil) ⇒ Boolean
Copies the data from the table to another table using a synchronous method that blocks for a response. Timeouts and transient errors are generally handled as needed to complete the job. See also #copy_job.
1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 |
# File 'lib/google/cloud/bigquery/table.rb', line 1159 def copy destination_table, create: nil, write: nil job = copy_job destination_table, create: create, write: write job.wait_until_done! if job.failed? begin # raise to activate ruby exception cause handling fail job.gapi_error rescue => e # wrap Google::Apis::Error with Google::Cloud::Error raise Google::Cloud::Error.from_error(e) end end true end |
#copy_job(destination_table, create: nil, write: nil, dryrun: nil, job_id: nil, prefix: nil, labels: nil) ⇒ Google::Cloud::Bigquery::CopyJob
Copies the data from the table to another table using an asynchronous method. In this method, a CopyJob is immediately returned. The caller may poll the service by repeatedly calling Job#reload! and Job#done? to detect when the job is done, or simply block until the job is done by calling #Job#wait_until_done!. See also #copy.
1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 |
# File 'lib/google/cloud/bigquery/table.rb', line 1095 def copy_job destination_table, create: nil, write: nil, dryrun: nil, job_id: nil, prefix: nil, labels: nil ensure_service! = { create: create, write: write, dryrun: dryrun, job_id: job_id, prefix: prefix, labels: labels } gapi = service.copy_table table_ref, get_table_ref(destination_table), Job.from_gapi gapi, service end |
#created_at ⇒ Time?
The time when this table was created.
460 461 462 463 464 465 466 467 468 |
# File 'lib/google/cloud/bigquery/table.rb', line 460 def created_at return nil if reference? ensure_full_data! begin ::Time.at(Integer(@gapi.creation_time) / 1000.0) rescue nil end end |
#data(token: nil, max: nil, start: nil) ⇒ Google::Cloud::Bigquery::Data
Retrieves data from the table.
If the table is not a full resource representation (see #resource_full?), the full representation will be retrieved before the data retrieval.
1010 1011 1012 1013 1014 1015 1016 1017 |
# File 'lib/google/cloud/bigquery/table.rb', line 1010 def data token: nil, max: nil, start: nil ensure_service! reload! unless resource_full? = { token: token, max: max, start: start } data_json = service.list_tabledata \ dataset_id, table_id, Data.from_gapi_json data_json, gapi, service end |
#dataset_id ⇒ String
The ID of the Dataset
containing this table.
128 129 130 131 |
# File 'lib/google/cloud/bigquery/table.rb', line 128 def dataset_id return reference.dataset_id if reference? @gapi.table_reference.dataset_id end |
#delete ⇒ Boolean
Permanently deletes the table.
1786 1787 1788 1789 1790 |
# File 'lib/google/cloud/bigquery/table.rb', line 1786 def delete ensure_service! service.delete_table dataset_id, table_id true end |
#description ⇒ String?
A user-friendly description of the table.
393 394 395 396 397 |
# File 'lib/google/cloud/bigquery/table.rb', line 393 def description return nil if reference? ensure_full_data! @gapi.description end |
#description=(new_description) ⇒ Object
Updates the user-friendly description of the table.
If the table is not a full resource representation (see #resource_full?), the full representation will be retrieved before the update to comply with ETag-based optimistic concurrency control.
410 411 412 413 414 |
# File 'lib/google/cloud/bigquery/table.rb', line 410 def description= new_description reload! unless resource_full? @gapi.update! description: new_description patch_gapi! :description end |
#etag ⇒ String?
The ETag hash of the table.
365 366 367 368 369 |
# File 'lib/google/cloud/bigquery/table.rb', line 365 def etag return nil if reference? ensure_full_data! @gapi.etag end |
#exists? ⇒ Boolean
Determines whether the table exists in the BigQuery service. The result is cached locally.
1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 |
# File 'lib/google/cloud/bigquery/table.rb', line 1833 def exists? # Always true if we have a gapi object return true unless reference? # If we have a value, return it return @exists unless @exists.nil? ensure_gapi! @exists = true rescue Google::Cloud::NotFoundError @exists = false end |
#expires_at ⇒ Time?
The time when this table expires. If not present, the table will persist indefinitely. Expired tables will be deleted and their storage reclaimed.
480 481 482 483 484 485 486 487 488 |
# File 'lib/google/cloud/bigquery/table.rb', line 480 def expires_at return nil if reference? ensure_full_data! begin ::Time.at(Integer(@gapi.expiration_time) / 1000.0) rescue nil end end |
#external ⇒ External::DataSource?
The External::DataSource (or subclass) object that represents the external data source that the table represents. Data can be queried the table, even though the data is not stored in BigQuery. Instead of loading or streaming the data, this object references the external data source.
Present only if the table represents an External Data Source. See #external? and External::DataSource.
745 746 747 748 749 750 |
# File 'lib/google/cloud/bigquery/table.rb', line 745 def external return nil if reference? ensure_full_data! return nil if @gapi.external_data_configuration.nil? External.from_gapi(@gapi.external_data_configuration).freeze end |
#external=(external) ⇒ Object
Set the External::DataSource (or subclass) object that represents the external data source that the table represents. Data can be queried the table, even though the data is not stored in BigQuery. Instead of loading or streaming the data, this object references the external data source.
Use only if the table represents an External Data Source. See #external? and External::DataSource.
If the table is not a full resource representation (see #resource_full?), the full representation will be retrieved before the update to comply with ETag-based optimistic concurrency control.
773 774 775 776 777 |
# File 'lib/google/cloud/bigquery/table.rb', line 773 def external= external reload! unless resource_full? @gapi.external_data_configuration = external.to_gapi patch_gapi! :external_data_configuration end |
#external? ⇒ Boolean?
Checks if the table's type is "EXTERNAL", indicating that the table represents an External Data Source. See #external? and External::DataSource.
548 549 550 551 |
# File 'lib/google/cloud/bigquery/table.rb', line 548 def external? return nil if reference? @gapi.type == "EXTERNAL" end |
#extract(extract_url, format: nil, compression: nil, delimiter: nil, header: nil) ⇒ Boolean
Extracts the data from the table to a Google Cloud Storage file using a synchronous method that blocks for a response. Timeouts and transient errors are generally handled as needed to complete the job. See also #extract_job.
1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 |
# File 'lib/google/cloud/bigquery/table.rb', line 1296 def extract extract_url, format: nil, compression: nil, delimiter: nil, header: nil job = extract_job extract_url, format: format, compression: compression, delimiter: delimiter, header: header job.wait_until_done! if job.failed? begin # raise to activate ruby exception cause handling fail job.gapi_error rescue => e # wrap Google::Apis::Error with Google::Cloud::Error raise Google::Cloud::Error.from_error(e) end end true end |
#extract_job(extract_url, format: nil, compression: nil, delimiter: nil, header: nil, dryrun: nil, job_id: nil, prefix: nil, labels: nil) ⇒ Google::Cloud::Bigquery::ExtractJob
Extracts the data from the table to a Google Cloud Storage file using an asynchronous method. In this method, an ExtractJob is immediately returned. The caller may poll the service by repeatedly calling Job#reload! and Job#done? to detect when the job is done, or simply block until the job is done by calling #Job#wait_until_done!. See also #extract.
1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 |
# File 'lib/google/cloud/bigquery/table.rb', line 1243 def extract_job extract_url, format: nil, compression: nil, delimiter: nil, header: nil, dryrun: nil, job_id: nil, prefix: nil, labels: nil ensure_service! = { format: format, compression: compression, delimiter: delimiter, header: header, dryrun: dryrun, job_id: job_id, prefix: prefix, labels: labels } gapi = service.extract_table table_ref, extract_url, Job.from_gapi gapi, service end |
#fields ⇒ Array<Schema::Field>?
The fields of the table, obtained from its schema.
700 701 702 703 |
# File 'lib/google/cloud/bigquery/table.rb', line 700 def fields return nil if reference? schema.fields end |
#headers ⇒ Array<Symbol>?
The names of the columns in the table, obtained from its schema.
723 724 725 726 |
# File 'lib/google/cloud/bigquery/table.rb', line 723 def headers return nil if reference? schema.headers end |
#id ⇒ String?
The combined Project ID, Dataset ID, and Table ID for this table, in
the format specified by the Legacy SQL Query
Reference:
project_name:datasetId.tableId
. To use this value in queries see
#query_id.
285 286 287 288 |
# File 'lib/google/cloud/bigquery/table.rb', line 285 def id return nil if reference? @gapi.id end |
#insert(rows, skip_invalid: nil, ignore_unknown: nil) ⇒ Google::Cloud::Bigquery::InsertResponse
Inserts data into the table for near-immediate querying, without the need to complete a load operation before the data can appear in query results.
1702 1703 1704 1705 1706 1707 1708 1709 1710 |
# File 'lib/google/cloud/bigquery/table.rb', line 1702 def insert rows, skip_invalid: nil, ignore_unknown: nil rows = [rows] if rows.is_a? Hash fail ArgumentError, "No rows provided" if rows.empty? ensure_service! = { skip_invalid: skip_invalid, ignore_unknown: ignore_unknown } gapi = service.insert_tabledata dataset_id, table_id, rows, InsertResponse.from_gapi rows, gapi end |
#insert_async(skip_invalid: nil, ignore_unknown: nil, max_bytes: 10000000, max_rows: 500, interval: 10, threads: 4) {|response| ... } ⇒ Table::AsyncInserter
Create an asynchronous inserter object used to insert rows in batches.
1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 |
# File 'lib/google/cloud/bigquery/table.rb', line 1759 def insert_async skip_invalid: nil, ignore_unknown: nil, max_bytes: 10000000, max_rows: 500, interval: 10, threads: 4, &block ensure_service! AsyncInserter.new self, skip_invalid: skip_invalid, ignore_unknown: ignore_unknown, max_bytes: max_bytes, max_rows: max_rows, interval: interval, threads: threads, &block end |
#labels ⇒ Hash<String, String>?
A hash of user-provided labels associated with this table. Labels are used to organize and group tables. See Using Labels.
The returned hash is frozen and changes are not allowed. Use #labels= to replace the entire hash.
589 590 591 592 593 594 |
# File 'lib/google/cloud/bigquery/table.rb', line 589 def labels return nil if reference? m = @gapi.labels m = m.to_h if m.respond_to? :to_h m.dup.freeze end |
#labels=(labels) ⇒ Object
Updates the hash of user-provided labels associated with this table. Labels are used to organize and group tables. See Using Labels.
If the table is not a full resource representation (see #resource_full?), the full representation will be retrieved before the update to comply with ETag-based optimistic concurrency control.
626 627 628 629 630 |
# File 'lib/google/cloud/bigquery/table.rb', line 626 def labels= labels reload! unless resource_full? @gapi.labels = labels patch_gapi! :labels end |
#load(file, format: nil, create: nil, write: nil, projection_fields: nil, jagged_rows: nil, quoted_newlines: nil, encoding: nil, delimiter: nil, ignore_unknown: nil, max_bad_records: nil, quote: nil, skip_leading: nil, autodetect: nil, null_marker: nil) ⇒ Google::Cloud::Bigquery::LoadJob
Loads data into the table. You can pass a google-cloud storage file path or a google-cloud storage file instance. Or, you can upload a file directly. See Loading Data with a POST Request.
1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 |
# File 'lib/google/cloud/bigquery/table.rb', line 1625 def load file, format: nil, create: nil, write: nil, projection_fields: nil, jagged_rows: nil, quoted_newlines: nil, encoding: nil, delimiter: nil, ignore_unknown: nil, max_bad_records: nil, quote: nil, skip_leading: nil, autodetect: nil, null_marker: nil job = load_job file, format: format, create: create, write: write, projection_fields: projection_fields, jagged_rows: jagged_rows, quoted_newlines: quoted_newlines, encoding: encoding, delimiter: delimiter, ignore_unknown: ignore_unknown, max_bad_records: max_bad_records, quote: quote, skip_leading: skip_leading, autodetect: autodetect, null_marker: null_marker job.wait_until_done! if job.failed? begin # raise to activate ruby exception cause handling fail job.gapi_error rescue => e # wrap Google::Apis::Error with Google::Cloud::Error raise Google::Cloud::Error.from_error(e) end end true end |
#load_job(file, format: nil, create: nil, write: nil, projection_fields: nil, jagged_rows: nil, quoted_newlines: nil, encoding: nil, delimiter: nil, ignore_unknown: nil, max_bad_records: nil, quote: nil, skip_leading: nil, dryrun: nil, job_id: nil, prefix: nil, labels: nil, autodetect: nil, null_marker: nil) ⇒ Google::Cloud::Bigquery::LoadJob
Loads data into the table. You can pass a google-cloud storage file path or a google-cloud storage file instance. Or, you can upload a file directly. See Loading Data with a POST Request.
1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 |
# File 'lib/google/cloud/bigquery/table.rb', line 1471 def load_job file, format: nil, create: nil, write: nil, projection_fields: nil, jagged_rows: nil, quoted_newlines: nil, encoding: nil, delimiter: nil, ignore_unknown: nil, max_bad_records: nil, quote: nil, skip_leading: nil, dryrun: nil, job_id: nil, prefix: nil, labels: nil, autodetect: nil, null_marker: nil ensure_service! = { format: format, create: create, write: write, projection_fields: projection_fields, jagged_rows: jagged_rows, quoted_newlines: quoted_newlines, encoding: encoding, delimiter: delimiter, ignore_unknown: ignore_unknown, max_bad_records: max_bad_records, quote: quote, skip_leading: skip_leading, dryrun: dryrun, job_id: job_id, prefix: prefix, labels: labels, autodetect: autodetect, null_marker: null_marker } return load_storage(file, ) if storage_url? file return load_local(file, ) if local_file? file fail Google::Cloud::Error, "Don't know how to load #{file}" end |
#location ⇒ String?
The geographic location where the table should reside. Possible
values include EU
and US
. The default value is US
.
561 562 563 564 565 |
# File 'lib/google/cloud/bigquery/table.rb', line 561 def location return nil if reference? ensure_full_data! @gapi.location end |
#modified_at ⇒ Time?
The date when this table was last modified.
498 499 500 501 502 503 504 505 506 |
# File 'lib/google/cloud/bigquery/table.rb', line 498 def modified_at return nil if reference? ensure_full_data! begin ::Time.at(Integer(@gapi.last_modified_time) / 1000.0) rescue nil end end |
#name ⇒ String?
The name of the table.
335 336 337 338 |
# File 'lib/google/cloud/bigquery/table.rb', line 335 def name return nil if reference? @gapi.friendly_name end |
#name=(new_name) ⇒ Object
Updates the name of the table.
If the table is not a full resource representation (see #resource_full?), the full representation will be retrieved before the update to comply with ETag-based optimistic concurrency control.
351 352 353 354 355 |
# File 'lib/google/cloud/bigquery/table.rb', line 351 def name= new_name reload! unless resource_full? @gapi.update! friendly_name: new_name patch_gapi! :friendly_name end |
#project_id ⇒ String
The ID of the Project
containing this table.
140 141 142 143 |
# File 'lib/google/cloud/bigquery/table.rb', line 140 def project_id return reference.project_id if reference? @gapi.table_reference.project_id end |
#query ⇒ String
The query that executes each time the view is loaded.
844 845 846 |
# File 'lib/google/cloud/bigquery/table.rb', line 844 def query @gapi.view.query if @gapi.view end |
#query=(new_query) ⇒ Object
Updates the query that executes each time the view is loaded.
This sets the query using standard SQL. To specify legacy SQL or to use user-defined function resources use (#set_query) instead.
871 872 873 |
# File 'lib/google/cloud/bigquery/table.rb', line 871 def query= new_query set_query new_query end |
#query_id(standard_sql: nil, legacy_sql: nil) ⇒ String
The value returned by #id, wrapped in square brackets if the Project ID contains dashes, as specified by the Query Reference. Useful in queries.
319 320 321 322 323 324 325 |
# File 'lib/google/cloud/bigquery/table.rb', line 319 def query_id standard_sql: nil, legacy_sql: nil if Convert.resolve_legacy_sql standard_sql, legacy_sql "[#{project_id}:#{dataset_id}.#{table_id}]" else "`#{project_id}.#{dataset_id}.#{table_id}`" end end |
#query_legacy_sql? ⇒ Boolean
Checks if the view's query is using legacy sql.
929 930 931 932 933 |
# File 'lib/google/cloud/bigquery/table.rb', line 929 def query_legacy_sql? val = @gapi.view.use_legacy_sql return true if val.nil? val end |
#query_standard_sql? ⇒ Boolean
Checks if the view's query is using standard sql.
942 943 944 |
# File 'lib/google/cloud/bigquery/table.rb', line 942 def query_standard_sql? !query_legacy_sql? end |
#query_udfs ⇒ Array<String>
The user-defined function resources used in the view's query. May be
either a code resource to load from a Google Cloud Storage URI
(gs://bucket/path
), or an inline resource that contains code for a
user-defined function (UDF). Providing an inline code resource is
equivalent to providing a URI for a file containing the same code. See
User-Defined
Functions.
960 961 962 963 964 |
# File 'lib/google/cloud/bigquery/table.rb', line 960 def query_udfs udfs_gapi = @gapi.view.user_defined_function_resources return [] if udfs_gapi.nil? Array(udfs_gapi).map { |udf| udf.inline_code || udf.resource_uri } end |
#reference? ⇒ Boolean
Whether the table was created without retrieving the resource representation from the BigQuery service.
1863 1864 1865 |
# File 'lib/google/cloud/bigquery/table.rb', line 1863 def reference? @gapi.nil? end |
#reload! ⇒ Google::Cloud::Bigquery::Table Also known as: refresh!
Reloads the table with current data from the BigQuery service.
1810 1811 1812 1813 1814 |
# File 'lib/google/cloud/bigquery/table.rb', line 1810 def reload! ensure_service! gapi = service.get_table dataset_id, table_id @gapi = gapi end |
#resource? ⇒ Boolean
Whether the table was created with a resource representation from the BigQuery service.
1886 1887 1888 |
# File 'lib/google/cloud/bigquery/table.rb', line 1886 def resource? !@gapi.nil? end |
#resource_full? ⇒ Boolean
Whether the table was created with a full resource representation from the BigQuery service.
1935 1936 1937 |
# File 'lib/google/cloud/bigquery/table.rb', line 1935 def resource_full? @gapi.is_a? Google::Apis::BigqueryV2::Table end |
#resource_partial? ⇒ Boolean
Whether the table was created with a partial resource representation from the BigQuery service by retrieval through Dataset#tables. See Tables: list response for the contents of the partial representation. Accessing any attribute outside of the partial representation will result in loading the full representation.
1914 1915 1916 |
# File 'lib/google/cloud/bigquery/table.rb', line 1914 def resource_partial? @gapi.is_a? Google::Apis::BigqueryV2::TableList::Table end |
#rows_count ⇒ Integer?
The number of rows in the table.
442 443 444 445 446 447 448 449 450 |
# File 'lib/google/cloud/bigquery/table.rb', line 442 def rows_count return nil if reference? ensure_full_data! begin Integer @gapi.num_rows rescue nil end end |
#schema(replace: false) {|schema| ... } ⇒ Google::Cloud::Bigquery::Schema?
Returns the table's schema. If the table is not a view (See #view?), this method can also be used to set, replace, or add to the schema by passing a block. See Schema for available methods.
If the table is not a full resource representation (see #resource_full?), the full representation will be retrieved.
667 668 669 670 671 672 673 674 675 676 677 678 679 680 |
# File 'lib/google/cloud/bigquery/table.rb', line 667 def schema replace: false return nil if reference? && !block_given? reload! unless resource_full? schema_builder = Schema.from_gapi @gapi.schema if block_given? schema_builder = Schema.from_gapi if replace yield schema_builder if schema_builder.changed? @gapi.schema = schema_builder.to_gapi patch_gapi! :schema end end schema_builder.freeze end |
#set_query(query, standard_sql: nil, legacy_sql: nil, udfs: nil) ⇒ Object
Updates the query that executes each time the view is loaded. Allows setting of standard vs. legacy SQL and user-defined function resources.
913 914 915 916 917 918 919 920 |
# File 'lib/google/cloud/bigquery/table.rb', line 913 def set_query query, standard_sql: nil, legacy_sql: nil, udfs: nil @gapi.view = Google::Apis::BigqueryV2::ViewDefinition.new \ query: query, use_legacy_sql: Convert.resolve_legacy_sql(standard_sql, legacy_sql), user_defined_function_resources: udfs_gapi(udfs) patch_gapi! :view end |
#table? ⇒ Boolean?
Checks if the table's type is "TABLE".
517 518 519 520 |
# File 'lib/google/cloud/bigquery/table.rb', line 517 def table? return nil if reference? @gapi.type == "TABLE" end |
#table_id ⇒ String
A unique ID for this table.
115 116 117 118 |
# File 'lib/google/cloud/bigquery/table.rb', line 115 def table_id return reference.table_id if reference? @gapi.table_reference.table_id end |
#time_partitioning? ⇒ Boolean?
Checks if the table is time-partitioned. See Partitioned Tables.
165 166 167 168 |
# File 'lib/google/cloud/bigquery/table.rb', line 165 def time_partitioning? return nil if reference? !@gapi.time_partitioning.nil? end |
#time_partitioning_expiration ⇒ Integer?
The expiration for the table partitions, if any, in seconds. See Partitioned Tables.
231 232 233 234 235 236 237 |
# File 'lib/google/cloud/bigquery/table.rb', line 231 def time_partitioning_expiration return nil if reference? ensure_full_data! @gapi.time_partitioning.expiration_ms / 1_000 if time_partitioning? && !@gapi.time_partitioning.expiration_ms.nil? end |
#time_partitioning_expiration=(expiration) ⇒ Object
Sets the partition expiration for the table. See Partitioned Tables. The table must also be partitioned.
If the table is not a full resource representation (see #resource_full?), the full representation will be retrieved before the update to comply with ETag-based optimistic concurrency control.
265 266 267 268 269 270 271 |
# File 'lib/google/cloud/bigquery/table.rb', line 265 def time_partitioning_expiration= expiration reload! unless resource_full? @gapi.time_partitioning ||= Google::Apis::BigqueryV2::TimePartitioning.new @gapi.time_partitioning.expiration_ms = expiration * 1000 patch_gapi! :time_partitioning end |
#time_partitioning_type ⇒ String?
The period for which the table is partitioned, if any. See Partitioned Tables.
180 181 182 183 184 |
# File 'lib/google/cloud/bigquery/table.rb', line 180 def time_partitioning_type return nil if reference? ensure_full_data! @gapi.time_partitioning.type if time_partitioning? end |
#time_partitioning_type=(type) ⇒ Object
Sets the partitioning for the table. See Partitioned Tables.
You can only set partitioning when creating a table as in the example below. BigQuery does not allow you to change partitioning on an existing table.
If the table is not a full resource representation (see #resource_full?), the full representation will be retrieved before the update to comply with ETag-based optimistic concurrency control.
212 213 214 215 216 217 218 |
# File 'lib/google/cloud/bigquery/table.rb', line 212 def time_partitioning_type= type reload! unless resource_full? @gapi.time_partitioning ||= Google::Apis::BigqueryV2::TimePartitioning.new @gapi.time_partitioning.type = type patch_gapi! :time_partitioning end |
#view? ⇒ Boolean?
Checks if the table's type is "VIEW", indicating that the table represents a BigQuery view. See Dataset#create_view.
532 533 534 535 |
# File 'lib/google/cloud/bigquery/table.rb', line 532 def view? return nil if reference? @gapi.type == "VIEW" end |