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.
-
#clustering? ⇒ Boolean?
Checks if the table is clustered.
-
#clustering_fields ⇒ Array<String>?
One or more fields on which data should be clustered.
-
#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.
-
#encryption ⇒ EncryptionConfiguration?
The EncryptionConfiguration object that represents the custom encryption method used to protect the table.
-
#encryption=(value) ⇒ Object
Set the EncryptionConfiguration object that represents the custom encryption method used to protect 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:dataset_id.table_id
). -
#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.
-
#param_types ⇒ Hash
The types of the fields in the table, obtained from its schema.
-
#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 backticks (Standard SQL) or s quare brackets (Legacy SQL) to accommodate project IDs containing dashes.
-
#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.
-
#range_partitioning? ⇒ Boolean?
Checks if the table is range partitioned.
-
#range_partitioning_end ⇒ Integer?
The end of range partitioning, exclusive.
-
#range_partitioning_field ⇒ Integer?
The field on which the table is range partitioned, if any.
-
#range_partitioning_interval ⇒ Integer?
The width of each interval.
-
#range_partitioning_start ⇒ Integer?
The start of range partitioning, inclusive.
-
#require_partition_filter ⇒ Boolean?
Whether queries over this table require a partition filter that can be used for partition elimination to be specified.
-
#require_partition_filter=(new_require) ⇒ Object
Sets whether queries over this table require a partition filter.
-
#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 time partitions, if any, in seconds.
-
#time_partitioning_expiration=(expiration) ⇒ Object
Sets the time partition expiration for the table.
-
#time_partitioning_field ⇒ String?
The field on which the table is time partitioned, if any.
-
#time_partitioning_field=(field) ⇒ Object
Sets the field on which to time partition the table.
-
#time_partitioning_type ⇒ String?
The period for which the table is time partitioned, if any.
-
#time_partitioning_type=(type) ⇒ Object
Sets the time partitioning type 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) {|job| ... } ⇒ 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, job_id: nil, prefix: nil, labels: nil, dryrun: nil) {|job| ... } ⇒ 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) {|job| ... } ⇒ 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, job_id: nil, prefix: nil, labels: nil, dryrun: nil) {|job| ... } ⇒ Google::Cloud::Bigquery::ExtractJob
Extracts the data from the table to a Google Cloud Storage file using an asynchronous method.
-
#insert(rows, insert_ids: nil, 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: 10_000_000, max_rows: 500, interval: 10, threads: 4) {|response| ... } ⇒ Table::AsyncInserter
Create an asynchronous inserter object used to insert rows in batches.
-
#load(files, 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) {|updater| ... } ⇒ Boolean
Loads data into the table.
-
#load_job(files, 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, job_id: nil, prefix: nil, labels: nil, autodetect: nil, null_marker: nil, dryrun: nil) {|load_job| ... } ⇒ 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?(force: false) ⇒ 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.
610 611 612 613 614 |
# File 'lib/google/cloud/bigquery/table.rb', line 610 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.
1097 1098 1099 1100 1101 |
# File 'lib/google/cloud/bigquery/table.rb', line 1097 def buffer_bytes return nil if reference? ensure_full_data! @gapi.streaming_buffer&.estimated_bytes 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.
1131 1132 1133 1134 1135 1136 1137 |
# File 'lib/google/cloud/bigquery/table.rb', line 1131 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 Convert.millis_to_time oldest_entry_time 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.
1115 1116 1117 1118 1119 |
# File 'lib/google/cloud/bigquery/table.rb', line 1115 def buffer_rows return nil if reference? ensure_full_data! @gapi.streaming_buffer&.estimated_rows end |
#bytes_count ⇒ Integer?
The number of bytes in the table.
655 656 657 658 659 660 661 662 663 |
# File 'lib/google/cloud/bigquery/table.rb', line 655 def bytes_count return nil if reference? ensure_full_data! begin Integer @gapi.num_bytes rescue StandardError nil end end |
#clustering? ⇒ Boolean?
Checks if the table is clustered.
472 473 474 475 |
# File 'lib/google/cloud/bigquery/table.rb', line 472 def clustering? return nil if reference? !@gapi.clustering.nil? end |
#clustering_fields ⇒ Array<String>?
One or more fields on which data should be clustered. Must be specified with time partitioning, data in the table will be first partitioned and subsequently clustered. The order of the returned fields determines the sort order of the data.
See Google::Cloud::Bigquery::Table::Updater#clustering_fields=.
498 499 500 501 502 |
# File 'lib/google/cloud/bigquery/table.rb', line 498 def clustering_fields return nil if reference? ensure_full_data! @gapi.clustering.fields if clustering? end |
#copy(destination_table, create: nil, write: nil) {|job| ... } ⇒ 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.
The geographic location for the job ("US", "EU", etc.) can be set via CopyJob::Updater#location= in a block passed to this method. If the table is a full resource representation (see #resource_full?), the location of the job will be automatically set to the location of the table.
1515 1516 1517 1518 1519 1520 |
# File 'lib/google/cloud/bigquery/table.rb', line 1515 def copy destination_table, create: nil, write: nil, &block job = copy_job destination_table, create: create, write: write, &block job.wait_until_done! ensure_job_succeeded! job true end |
#copy_job(destination_table, create: nil, write: nil, job_id: nil, prefix: nil, labels: nil, dryrun: nil) {|job| ... } ⇒ 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.
The geographic location for the job ("US", "EU", etc.) can be set via CopyJob::Updater#location= in a block passed to this method. If the table is a full resource representation (see #resource_full?), the location of the job will be automatically set to the location of the table.
1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 |
# File 'lib/google/cloud/bigquery/table.rb', line 1433 def copy_job destination_table, create: nil, write: nil, job_id: nil, prefix: nil, labels: nil, dryrun: nil ensure_service! = { create: create, write: write, dryrun: dryrun, labels: labels, job_id: job_id, prefix: prefix } updater = CopyJob::Updater.( service, table_ref, Service.get_table_ref(destination_table, default_ref: table_ref), ) updater.location = location if location # may be table reference yield updater if block_given? job_gapi = updater.to_gapi gapi = service.copy_table job_gapi Job.from_gapi gapi, service end |
#created_at ⇒ Time?
The time when this table was created.
691 692 693 694 695 |
# File 'lib/google/cloud/bigquery/table.rb', line 691 def created_at return nil if reference? ensure_full_data! Convert.millis_to_time @gapi.creation_time 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.
1323 1324 1325 1326 1327 1328 |
# File 'lib/google/cloud/bigquery/table.rb', line 1323 def data token: nil, max: nil, start: nil ensure_service! reload! unless resource_full? data_json = service.list_tabledata dataset_id, table_id, token: token, max: max, start: start Data.from_gapi_json data_json, gapi, nil, service end |
#dataset_id ⇒ String
The ID of the Dataset
containing this table.
130 131 132 133 |
# File 'lib/google/cloud/bigquery/table.rb', line 130 def dataset_id return reference.dataset_id if reference? @gapi.table_reference.dataset_id end |
#delete ⇒ Boolean
Permanently deletes the table.
2241 2242 2243 2244 2245 2246 2247 |
# File 'lib/google/cloud/bigquery/table.rb', line 2241 def delete ensure_service! service.delete_table dataset_id, table_id # Set flag for #exists? @exists = false true end |
#description ⇒ String?
A user-friendly description of the table.
624 625 626 627 628 |
# File 'lib/google/cloud/bigquery/table.rb', line 624 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.
641 642 643 644 645 |
# File 'lib/google/cloud/bigquery/table.rb', line 641 def description= new_description reload! unless resource_full? @gapi.update! description: new_description patch_gapi! :description end |
#encryption ⇒ EncryptionConfiguration?
The EncryptionConfiguration object that represents the custom encryption method used to protect the table. If not set, Dataset#default_encryption is used.
Present only if the table is using custom encryption.
1003 1004 1005 1006 1007 1008 |
# File 'lib/google/cloud/bigquery/table.rb', line 1003 def encryption return nil if reference? ensure_full_data! return nil if @gapi.encryption_configuration.nil? EncryptionConfiguration.from_gapi(@gapi.encryption_configuration).freeze end |
#encryption=(value) ⇒ Object
Set the EncryptionConfiguration object that represents the custom encryption method used to protect the table. If not set, Dataset#default_encryption is used.
Present only if the table is using custom encryption.
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.
1028 1029 1030 1031 1032 |
# File 'lib/google/cloud/bigquery/table.rb', line 1028 def encryption= value reload! unless resource_full? @gapi.encryption_configuration = value.to_gapi patch_gapi! :encryption_configuration end |
#etag ⇒ String?
The ETag hash of the table.
596 597 598 599 600 |
# File 'lib/google/cloud/bigquery/table.rb', line 596 def etag return nil if reference? ensure_full_data! @gapi.etag end |
#exists?(force: false) ⇒ Boolean
Determines whether the table exists in the BigQuery service. The
result is cached locally. To refresh state, set force
to true
.
2297 2298 2299 2300 2301 2302 2303 2304 |
# File 'lib/google/cloud/bigquery/table.rb', line 2297 def exists? force: false return gapi_exists? if force # If we have a value, return it return @exists unless @exists.nil? # Always true if we have a gapi object return true if resource? gapi_exists? 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.
707 708 709 710 711 |
# File 'lib/google/cloud/bigquery/table.rb', line 707 def expires_at return nil if reference? ensure_full_data! Convert.millis_to_time @gapi.expiration_time 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.
1051 1052 1053 1054 1055 1056 |
# File 'lib/google/cloud/bigquery/table.rb', line 1051 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.
1079 1080 1081 1082 1083 |
# File 'lib/google/cloud/bigquery/table.rb', line 1079 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.
767 768 769 770 |
# File 'lib/google/cloud/bigquery/table.rb', line 767 def external? return nil if reference? @gapi.type == "EXTERNAL" end |
#extract(extract_url, format: nil, compression: nil, delimiter: nil, header: nil) {|job| ... } ⇒ 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.
The geographic location for the job ("US", "EU", etc.) can be set via ExtractJob::Updater#location= in a block passed to this method. If the table is a full resource representation (see #resource_full?), the location of the job will be automatically set to the location of the table.
1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 |
# File 'lib/google/cloud/bigquery/table.rb', line 1688 def extract extract_url, format: nil, compression: nil, delimiter: nil, header: nil, &block job = extract_job extract_url, format: format, compression: compression, delimiter: delimiter, header: header, &block job.wait_until_done! ensure_job_succeeded! job true end |
#extract_job(extract_url, format: nil, compression: nil, delimiter: nil, header: nil, job_id: nil, prefix: nil, labels: nil, dryrun: nil) {|job| ... } ⇒ 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.
The geographic location for the job ("US", "EU", etc.) can be set via ExtractJob::Updater#location= in a block passed to this method. If the table is a full resource representation (see #resource_full?), the location of the job will automatically be set to the location of the table.
1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 |
# File 'lib/google/cloud/bigquery/table.rb', line 1612 def extract_job extract_url, format: nil, compression: nil, delimiter: nil, header: nil, job_id: nil, prefix: nil, labels: nil, dryrun: nil ensure_service! = { format: format, compression: compression, delimiter: delimiter, header: header, dryrun: dryrun, job_id: job_id, prefix: prefix, labels: labels } updater = ExtractJob::Updater. service, table_ref, extract_url, updater.location = location if location # may be table reference yield updater if block_given? job_gapi = updater.to_gapi gapi = service.extract_table job_gapi Job.from_gapi gapi, service end |
#fields ⇒ Array<Schema::Field>?
The fields of the table, obtained from its schema.
941 942 943 944 |
# File 'lib/google/cloud/bigquery/table.rb', line 941 def fields return nil if reference? schema.fields end |
#headers ⇒ Array<Symbol>?
The names of the columns in the table, obtained from its schema.
964 965 966 967 |
# File 'lib/google/cloud/bigquery/table.rb', line 964 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:dataset_id.table_id
). This is useful for referencing
tables in other projects and datasets. To use this value in queries
see #query_id.
517 518 519 520 |
# File 'lib/google/cloud/bigquery/table.rb', line 517 def id return nil if reference? @gapi.id end |
#insert(rows, insert_ids: nil, 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.
Because BigQuery's streaming API is designed for high insertion rates, modifications to the underlying table metadata are eventually consistent when interacting with the streaming system. In most cases metadata changes are propagated within minutes, but during this period API responses may reflect the inconsistent state of the table.
The value :skip
can be provided to skip the generation of IDs for all rows, or to skip the generation of an
ID for a specific row in the array.
2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 |
# File 'lib/google/cloud/bigquery/table.rb', line 2154 def insert rows, insert_ids: nil, skip_invalid: nil, ignore_unknown: nil rows = [rows] if rows.is_a? Hash raise ArgumentError, "No rows provided" if rows.empty? insert_ids = Array.new(rows.count) { :skip } if insert_ids == :skip insert_ids = Array insert_ids if insert_ids.count.positive? && insert_ids.count != rows.count raise ArgumentError, "insert_ids must be the same size as rows" end ensure_service! = { skip_invalid: skip_invalid, ignore_unknown: ignore_unknown, insert_ids: insert_ids } 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: 10_000_000, max_rows: 500, interval: 10, threads: 4) {|response| ... } ⇒ Table::AsyncInserter
Create an asynchronous inserter object used to insert rows in batches.
2217 2218 2219 2220 2221 2222 2223 |
# File 'lib/google/cloud/bigquery/table.rb', line 2217 def insert_async skip_invalid: nil, ignore_unknown: nil, max_bytes: 10_000_000, 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.
808 809 810 811 812 813 |
# File 'lib/google/cloud/bigquery/table.rb', line 808 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.
852 853 854 855 856 |
# File 'lib/google/cloud/bigquery/table.rb', line 852 def labels= labels reload! unless resource_full? @gapi.labels = labels patch_gapi! :labels end |
#load(files, 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) {|updater| ... } ⇒ Boolean
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.
The geographic location for the job ("US", "EU", etc.) can be set via LoadJob::Updater#location= in a block passed to this method. If the table is a full resource representation (see #resource_full?), the location of the job will be automatically set to the location of the table.
2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 |
# File 'lib/google/cloud/bigquery/table.rb', line 2077 def load files, 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, &block job = load_job files, 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, &block job.wait_until_done! ensure_job_succeeded! job true end |
#load_job(files, 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, job_id: nil, prefix: nil, labels: nil, autodetect: nil, null_marker: nil, dryrun: nil) {|load_job| ... } ⇒ 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.
The geographic location for the job ("US", "EU", etc.) can be set via LoadJob::Updater#location= in a block passed to this method. If the table is a full resource representation (see #resource_full?), the location of the job will be automatically set to the location of the table.
1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 |
# File 'lib/google/cloud/bigquery/table.rb', line 1892 def load_job files, 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, job_id: nil, prefix: nil, labels: nil, autodetect: nil, null_marker: nil, dryrun: nil ensure_service! updater = load_job_updater 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, schema: schema, labels: labels, autodetect: autodetect, null_marker: null_marker yield updater if block_given? job_gapi = updater.to_gapi return load_local files, job_gapi if local_file? files load_storage files, job_gapi end |
#location ⇒ String?
The geographic location where the table should reside. Possible
values include EU
and US
. The default value is US
.
780 781 782 783 784 |
# File 'lib/google/cloud/bigquery/table.rb', line 780 def location return nil if reference? ensure_full_data! @gapi.location end |
#modified_at ⇒ Time?
The date when this table was last modified.
721 722 723 724 725 |
# File 'lib/google/cloud/bigquery/table.rb', line 721 def modified_at return nil if reference? ensure_full_data! Convert.millis_to_time @gapi.last_modified_time end |
#name ⇒ String?
The name of the table.
566 567 568 569 |
# File 'lib/google/cloud/bigquery/table.rb', line 566 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.
582 583 584 585 586 |
# File 'lib/google/cloud/bigquery/table.rb', line 582 def name= new_name reload! unless resource_full? @gapi.update! friendly_name: new_name patch_gapi! :friendly_name end |
#param_types ⇒ Hash
The types of the fields in the table, obtained from its schema. Types use the same format as the optional query parameter types.
984 985 986 987 |
# File 'lib/google/cloud/bigquery/table.rb', line 984 def param_types return nil if reference? schema.param_types end |
#project_id ⇒ String
The ID of the Project
containing this table.
142 143 144 145 |
# File 'lib/google/cloud/bigquery/table.rb', line 142 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.
1146 1147 1148 |
# File 'lib/google/cloud/bigquery/table.rb', line 1146 def query @gapi.view&.query 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.
1173 1174 1175 |
# File 'lib/google/cloud/bigquery/table.rb', line 1173 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 backticks (Standard SQL) or s quare brackets (Legacy SQL) to accommodate project IDs containing dashes. Useful in queries.
550 551 552 553 554 555 556 |
# File 'lib/google/cloud/bigquery/table.rb', line 550 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.
1240 1241 1242 1243 1244 |
# File 'lib/google/cloud/bigquery/table.rb', line 1240 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.
1253 1254 1255 |
# File 'lib/google/cloud/bigquery/table.rb', line 1253 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.
1271 1272 1273 1274 1275 |
# File 'lib/google/cloud/bigquery/table.rb', line 1271 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 |
#range_partitioning? ⇒ Boolean?
Checks if the table is range partitioned. See Creating and using integer range partitioned tables.
167 168 169 170 |
# File 'lib/google/cloud/bigquery/table.rb', line 167 def range_partitioning? return nil if reference? !@gapi.range_partitioning.nil? end |
#range_partitioning_end ⇒ Integer?
The end of range partitioning, exclusive. See Creating and using integer range partitioned tables.
228 229 230 231 232 |
# File 'lib/google/cloud/bigquery/table.rb', line 228 def range_partitioning_end return nil if reference? ensure_full_data! @gapi.range_partitioning.range.end if range_partitioning? end |
#range_partitioning_field ⇒ Integer?
The field on which the table is range partitioned, if any. The field must be a top-level NULLABLE/REQUIRED
field. The only supported type is INTEGER/INT64
. See Creating and using integer range partitioned
tables.
182 183 184 185 186 |
# File 'lib/google/cloud/bigquery/table.rb', line 182 def range_partitioning_field return nil if reference? ensure_full_data! @gapi.range_partitioning.field if range_partitioning? end |
#range_partitioning_interval ⇒ Integer?
The width of each interval. See Creating and using integer range partitioned tables.
212 213 214 215 216 217 |
# File 'lib/google/cloud/bigquery/table.rb', line 212 def range_partitioning_interval return nil if reference? ensure_full_data! return nil unless range_partitioning? @gapi.range_partitioning.range.interval end |
#range_partitioning_start ⇒ Integer?
The start of range partitioning, inclusive. See Creating and using integer range partitioned tables.
197 198 199 200 201 |
# File 'lib/google/cloud/bigquery/table.rb', line 197 def range_partitioning_start return nil if reference? ensure_full_data! @gapi.range_partitioning.range.start if range_partitioning? end |
#reference? ⇒ Boolean
Whether the table was created without retrieving the resource representation from the BigQuery service.
2325 2326 2327 |
# File 'lib/google/cloud/bigquery/table.rb', line 2325 def reference? @gapi.nil? end |
#reload! ⇒ Google::Cloud::Bigquery::Table Also known as: refresh!
Reloads the table with current data from the BigQuery service.
2267 2268 2269 2270 2271 2272 2273 |
# File 'lib/google/cloud/bigquery/table.rb', line 2267 def reload! ensure_service! @gapi = service.get_table dataset_id, table_id @reference = nil @exists = nil self end |
#require_partition_filter ⇒ Boolean?
Whether queries over this table require a partition filter that can be used for partition elimination to be specified. See Partitioned Tables.
425 426 427 428 429 |
# File 'lib/google/cloud/bigquery/table.rb', line 425 def require_partition_filter return nil if reference? ensure_full_data! @gapi.require_partition_filter end |
#require_partition_filter=(new_require) ⇒ Object
Sets whether queries over this table require a partition filter. See Partitioned Tables.
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.
454 455 456 457 458 |
# File 'lib/google/cloud/bigquery/table.rb', line 454 def require_partition_filter= new_require reload! unless resource_full? @gapi.require_partition_filter = new_require patch_gapi! :require_partition_filter end |
#resource? ⇒ Boolean
Whether the table was created with a resource representation from the BigQuery service.
2348 2349 2350 |
# File 'lib/google/cloud/bigquery/table.rb', line 2348 def resource? !@gapi.nil? end |
#resource_full? ⇒ Boolean
Whether the table was created with a full resource representation from the BigQuery service.
2397 2398 2399 |
# File 'lib/google/cloud/bigquery/table.rb', line 2397 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.
2376 2377 2378 |
# File 'lib/google/cloud/bigquery/table.rb', line 2376 def resource_partial? @gapi.is_a? Google::Apis::BigqueryV2::TableList::Table end |
#rows_count ⇒ Integer?
The number of rows in the table.
673 674 675 676 677 678 679 680 681 |
# File 'lib/google/cloud/bigquery/table.rb', line 673 def rows_count return nil if reference? ensure_full_data! begin Integer @gapi.num_rows rescue StandardError 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.
908 909 910 911 912 913 914 915 916 917 918 919 920 921 |
# File 'lib/google/cloud/bigquery/table.rb', line 908 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.
1223 1224 1225 1226 1227 1228 1229 1230 1231 |
# File 'lib/google/cloud/bigquery/table.rb', line 1223 def set_query query, standard_sql: nil, legacy_sql: nil, udfs: nil use_legacy_sql = Convert.resolve_legacy_sql standard_sql, legacy_sql @gapi.view = Google::Apis::BigqueryV2::ViewDefinition.new( query: query, use_legacy_sql: use_legacy_sql, user_defined_function_resources: udfs_gapi(udfs) ) patch_gapi! :view end |
#table? ⇒ Boolean?
Checks if the table's type is "TABLE".
736 737 738 739 |
# File 'lib/google/cloud/bigquery/table.rb', line 736 def table? return nil if reference? @gapi.type == "TABLE" end |
#table_id ⇒ String
A unique ID for this table.
117 118 119 120 |
# File 'lib/google/cloud/bigquery/table.rb', line 117 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.
244 245 246 247 |
# File 'lib/google/cloud/bigquery/table.rb', line 244 def time_partitioning? return nil if reference? !@gapi.time_partitioning.nil? end |
#time_partitioning_expiration ⇒ Integer?
The expiration for the time partitions, if any, in seconds. See Partitioned Tables.
369 370 371 372 373 374 375 |
# File 'lib/google/cloud/bigquery/table.rb', line 369 def time_partitioning_expiration return nil if reference? ensure_full_data! return nil unless time_partitioning? return nil if @gapi.time_partitioning.expiration_ms.nil? @gapi.time_partitioning.expiration_ms / 1_000 end |
#time_partitioning_expiration=(expiration) ⇒ Object
Sets the time partition expiration for the table. See Partitioned Tables. The table must also be time 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.
407 408 409 410 411 412 |
# File 'lib/google/cloud/bigquery/table.rb', line 407 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_field ⇒ String?
The field on which the table is time partitioned, if any. If not
set, the destination table is time partitioned by pseudo column
_PARTITIONTIME
; if set, the table is time partitioned by this field. See
Partitioned Tables.
314 315 316 317 318 |
# File 'lib/google/cloud/bigquery/table.rb', line 314 def time_partitioning_field return nil if reference? ensure_full_data! @gapi.time_partitioning.field if time_partitioning? end |
#time_partitioning_field=(field) ⇒ Object
Sets the field on which to time partition the table. If not
set, the destination table is time partitioned by pseudo column
_PARTITIONTIME
; if set, the table is time partitioned by this field. See
Partitioned Tables.
The table must also be time partitioned.
You can only set the time partitioning field while creating a table as in the example below. BigQuery does not allow you to change time partitioning on an existing table.
352 353 354 355 356 357 |
# File 'lib/google/cloud/bigquery/table.rb', line 352 def time_partitioning_field= field reload! unless resource_full? @gapi.time_partitioning ||= Google::Apis::BigqueryV2::TimePartitioning.new @gapi.time_partitioning.field = field patch_gapi! :time_partitioning end |
#time_partitioning_type ⇒ String?
The period for which the table is time partitioned, if any. See Partitioned Tables.
260 261 262 263 264 |
# File 'lib/google/cloud/bigquery/table.rb', line 260 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 time partitioning type for the table. See Partitioned
Tables.
The supported types are DAY
, HOUR
, MONTH
, and YEAR
, which will
generate one partition per day, hour, month, and year, respectively.
You can only set time partitioning when creating a table as in the example below. BigQuery does not allow you to change time partitioning on an existing table.
295 296 297 298 299 300 |
# File 'lib/google/cloud/bigquery/table.rb', line 295 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.
751 752 753 754 |
# File 'lib/google/cloud/bigquery/table.rb', line 751 def view? return nil if reference? @gapi.type == "VIEW" end |