class Google::Cloud::Bigquery::ExtractJob::Updater
Yielded to a block to accumulate changes for an API request.
Public Class Methods
@private Create an Updater
from a Job
and options hash.
@return [Google::Cloud::Bigquery::ExtractJob::Updater] A job
configuration object for setting query options.
# File lib/google/cloud/bigquery/extract_job.rb, line 289 def self.from_job_and_options request, options updater = ExtractJob::Updater.new request updater.compression = options[:compression] updater.delimiter = options[:delimiter] updater.format = options[:format] updater.header = options[:header] updater.labels = options[:labels] if options[:labels] unless options[:use_avro_logical_types].nil? updater.use_avro_logical_types = options[:use_avro_logical_types] end updater end
@private Create an Updater
from an options hash.
@return [Google::Cloud::Bigquery::ExtractJob::Updater] A job
configuration object for setting query options.
# File lib/google/cloud/bigquery/extract_job.rb, line 258 def self.from_options service, source, storage_files, options job_ref = service.job_ref_from options[:job_id], options[:prefix] storage_urls = Array(storage_files).map do |url| url.respond_to?(:to_gs_url) ? url.to_gs_url : url end options[:format] ||= Convert.derive_source_format storage_urls.first extract_config = Google::Apis::BigqueryV2::JobConfigurationExtract.new( destination_uris: Array(storage_urls) ) case source when Google::Apis::BigqueryV2::TableReference extract_config.source_table = source when Google::Apis::BigqueryV2::ModelReference extract_config.source_model = source end job = Google::Apis::BigqueryV2::Job.new( job_reference: job_ref, configuration: Google::Apis::BigqueryV2::JobConfiguration.new( extract: extract_config, dry_run: options[:dryrun] ) ) from_job_and_options job, options end
@private Create an Updater
object.
# File lib/google/cloud/bigquery/extract_job.rb, line 248 def initialize gapi super() @gapi = gapi end
Public Instance Methods
# File lib/google/cloud/bigquery/extract_job.rb, line 435 def cancel raise "not implemented in #{self.class}" end
Sets the compression type. Not applicable when extracting models.
@param [String] value The compression type to use for exported
files. Possible values include `GZIP` and `NONE`. The default value is `NONE`.
@!group Attributes
# File lib/google/cloud/bigquery/extract_job.rb, line 342 def compression= value @gapi.configuration.extract.compression = value end
Sets the field delimiter. Not applicable when extracting models.
@param [String] value Delimiter to use between fields in the
exported data. Default is <code>,</code>.
@!group Attributes
# File lib/google/cloud/bigquery/extract_job.rb, line 353 def delimiter= value @gapi.configuration.extract.field_delimiter = value end
Sets the destination file format. The default value for tables is `csv`. Tables with nested or repeated fields cannot be exported as CSV. The default value for models is `ml_tf_saved_model`.
Supported values for tables:
-
`csv` - CSV
-
`json` - [Newline-delimited JSON](jsonlines.org/)
-
`avro` - [Avro](avro.apache.org/)
Supported values for models:
-
`ml_tf_saved_model` - TensorFlow SavedModel
-
`ml_xgboost_booster` - XGBoost Booster
@param [String] new_format The new source format.
@!group Attributes
# File lib/google/cloud/bigquery/extract_job.rb, line 377 def format= new_format @gapi.configuration.extract.update! destination_format: Convert.source_format(new_format) end
Print a header row in the exported file. Not applicable when extracting models.
@param [Boolean] value Whether to print out a header row in the
results. Default is `true`.
@!group Attributes
# File lib/google/cloud/bigquery/extract_job.rb, line 389 def header= value @gapi.configuration.extract.print_header = value end
Sets the labels to use for the job.
@param [Hash] value A hash of user-provided labels associated with
the job. You can use these to organize and group your jobs. The labels applied to a resource must meet the following requirements: * Each resource can have multiple labels, up to a maximum of 64. * Each label must be a key-value pair. * Keys have a minimum length of 1 character and a maximum length of 63 characters, and cannot be empty. Values can be empty, and have a maximum length of 63 characters. * Keys and values can contain only lowercase letters, numeric characters, underscores, and dashes. All characters must use UTF-8 encoding, and international characters are allowed. * The key portion of a label must be unique. However, you can use the same key with multiple resources. * Keys must start with a lowercase letter or international character.
@!group Attributes
# File lib/google/cloud/bigquery/extract_job.rb, line 415 def labels= value @gapi.configuration.update! labels: value end
Sets the geographic location where the job should run. Required except for US and EU.
@param [String] value A geographic location, such as “US”, “EU” or
"asia-northeast1". Required except for US and EU.
@example
require "google/cloud/bigquery" bigquery = Google::Cloud::Bigquery.new dataset = bigquery.dataset "my_dataset" table = dataset.table "my_table" destination = "gs://my-bucket/file-name.csv" extract_job = table.extract_job destination do |j| j.location = "EU" end extract_job.wait_until_done! extract_job.done? #=> true
@!group Attributes
# File lib/google/cloud/bigquery/extract_job.rb, line 325 def location= value @gapi.job_reference.location = value return unless value.nil? # Treat assigning value of nil the same as unsetting the value. unset = @gapi.job_reference.instance_variables.include? :@location @gapi.job_reference.remove_instance_variable :@location if unset end
# File lib/google/cloud/bigquery/extract_job.rb, line 443 def reload! raise "not implemented in #{self.class}" end
# File lib/google/cloud/bigquery/extract_job.rb, line 439 def rerun! raise "not implemented in #{self.class}" end
@private Returns the Google
API client library version of this job.
@return [<Google::Apis::BigqueryV2::Job>] (See
{Google::Apis::BigqueryV2::Job})
# File lib/google/cloud/bigquery/extract_job.rb, line 457 def to_gapi @gapi end
Indicate whether to enable extracting applicable column types (such as `TIMESTAMP`) to their corresponding AVRO logical types (`timestamp-micros`), instead of only using their raw types (`avro-long`).
Only used when `#format` is set to `“AVRO”` (`#avro?`).
@param [Boolean] value Whether applicable column types will use
their corresponding AVRO logical types.
@!group Attributes
# File lib/google/cloud/bigquery/extract_job.rb, line 431 def use_avro_logical_types= value @gapi.configuration.extract.use_avro_logical_types = value end
# File lib/google/cloud/bigquery/extract_job.rb, line 448 def wait_until_done! raise "not implemented in #{self.class}" end