Skip to content

Commit 0bac3b1

Browse files
authored
feat(BigQuery): Exposing reservation field in JobConfiguration (#31777)
* chore(BigQuery): Adding missing parameters to load_job initializers and updaters - * feat(BigQuery): Exposing reservation field in JobConfiguration
1 parent 22f0e4c commit 0bac3b1

14 files changed

Lines changed: 477 additions & 76 deletions

File tree

google-cloud-bigquery/lib/google/cloud/bigquery/copy_job.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ def self.from_options service, source, target, options
194194
job_reference: job_ref,
195195
configuration: Google::Apis::BigqueryV2::JobConfiguration.new(
196196
copy: copy_cfg,
197-
dry_run: options[:dryrun]
197+
dry_run: options[:dryrun],
198+
reservation: options[:reservation]
198199
)
199200
)
200201

@@ -325,6 +326,18 @@ def labels= value
325326
@gapi.configuration.update! labels: value
326327
end
327328

329+
##
330+
# Sets the reservation that job would use. User can specify a reservation
331+
# to execute the job. If reservation is not set, reservation is determined
332+
# based on the rules defined by the reservation assignments. The expected
333+
# format is `projects/`project`/locations/`location`/reservations/`reservation``.
334+
# @param [String] value The reservation name.
335+
#
336+
# @!group Attributes
337+
def reservation= value
338+
@gapi.configuration.update! reservation: value
339+
end
340+
328341
def cancel
329342
raise "not implemented in #{self.class}"
330343
end

google-cloud-bigquery/lib/google/cloud/bigquery/dataset.rb

Lines changed: 171 additions & 15 deletions
Large diffs are not rendered by default.

google-cloud-bigquery/lib/google/cloud/bigquery/extract_job.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,8 @@ def self.from_options service, source, storage_files, options
280280
job_reference: job_ref,
281281
configuration: Google::Apis::BigqueryV2::JobConfiguration.new(
282282
extract: extract_config,
283-
dry_run: options[:dryrun]
283+
dry_run: options[:dryrun],
284+
reservation: options[:reservation]
284285
)
285286
)
286287

@@ -438,6 +439,18 @@ def use_avro_logical_types= value
438439
@gapi.configuration.extract.use_avro_logical_types = value
439440
end
440441

442+
##
443+
# Sets the reservation that job would use. User can specify a reservation
444+
# to execute the job. If reservation is not set, reservation is determined
445+
# based on the rules defined by the reservation assignments. The expected
446+
# format is `projects/`project`/locations/`location`/reservations/`reservation``.
447+
# @param [String] value The reservation name.
448+
#
449+
# @!group Attributes
450+
def reservation= value
451+
@gapi.configuration.update! reservation: value
452+
end
453+
441454
def cancel
442455
raise "not implemented in #{self.class}"
443456
end

google-cloud-bigquery/lib/google/cloud/bigquery/load_job.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ def time_zone
737737
end
738738

739739
##
740-
# The URI of thereference file with the reader schema. This file is only
740+
# The URI of the reference file with the reader schema. This file is only
741741
# loaded if it is part of source URIs, but is not loaded otherwise.
742742
# It is enabled for the following formats: `AVRO`, `PARQUET`, `ORC`.
743743
#
@@ -2779,7 +2779,7 @@ def time_zone= time_zone
27792779

27802780
##
27812781

2782-
# Sets the URI of thereference file with the reader schema. This file
2782+
# Sets the URI of the reference file with the reader schema. This file
27832783
# is only loaded if it is part of source URIs, but is not loaded
27842784
# otherwise. It is enabled for the following formats: `AVRO`,
27852785
# `PARQUET`, `ORC`.
@@ -2800,6 +2800,18 @@ def preserve_ascii_control_characters= val
28002800
@gapi.configuration.load.update! preserve_ascii_control_characters: val
28012801
end
28022802

2803+
##
2804+
# Sets the reservation that job would use. User can specify a reservation
2805+
# to execute the job. If reservation is not set, reservation is determined
2806+
# based on the rules defined by the reservation assignments. The expected
2807+
# format is `projects/`project`/locations/`location`/reservations/`reservation``.
2808+
# @param [String] value The reservation name.
2809+
#
2810+
# @!group Attributes
2811+
def reservation= value
2812+
@gapi.configuration.update! reservation: value
2813+
end
2814+
28032815
def cancel
28042816
raise "not implemented in #{self.class}"
28052817
end

google-cloud-bigquery/lib/google/cloud/bigquery/model.rb

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,11 @@ def training_runs
545545
# * The key portion of a label must be unique. However, you can use the
546546
# same key with multiple resources.
547547
# * Keys must start with a lowercase letter or international character.
548+
# @param [String] reservation The reservation that job would use. User
549+
# can specify a reservation to execute the job. If reservation is not
550+
# set, reservation is determined based on the rules defined by the
551+
# reservation assignments. The expected format is
552+
# `projects/`project`/locations/`location`/reservations/`reservation``.
548553
#
549554
# @yield [job] a job configuration object
550555
# @yieldparam [Google::Cloud::Bigquery::ExtractJob::Updater] job a job
@@ -566,9 +571,9 @@ def training_runs
566571
#
567572
# @!group Data
568573
#
569-
def extract_job extract_url, format: nil, job_id: nil, prefix: nil, labels: nil
574+
def extract_job extract_url, format: nil, job_id: nil, prefix: nil, labels: nil, reservation: nil
570575
ensure_service!
571-
options = { format: format, job_id: job_id, prefix: prefix, labels: labels }
576+
options = { format: format, job_id: job_id, prefix: prefix, labels: labels, reservation: reservation }
572577
updater = ExtractJob::Updater.from_options service, model_ref, extract_url, options
573578
updater.location = location if location # may be model reference
574579

@@ -603,6 +608,12 @@ def extract_job extract_url, format: nil, job_id: nil, prefix: nil, labels: nil
603608
#
604609
# * `ml_tf_saved_model` - TensorFlow SavedModel
605610
# * `ml_xgboost_booster` - XGBoost Booster
611+
# @param [String] reservation The reservation that job would use. User
612+
# can specify a reservation to execute the job. If reservation is not
613+
# set, reservation is determined based on the rules defined by the
614+
# reservation assignments. The expected format is
615+
# `projects/`project`/locations/`location`/reservations/`reservation``.
616+
#
606617
# @yield [job] a job configuration object
607618
# @yieldparam [Google::Cloud::Bigquery::ExtractJob::Updater] job a job
608619
# configuration object for setting additional options.
@@ -620,8 +631,8 @@ def extract_job extract_url, format: nil, job_id: nil, prefix: nil, labels: nil
620631
#
621632
# @!group Data
622633
#
623-
def extract extract_url, format: nil, &block
624-
job = extract_job extract_url, format: format, &block
634+
def extract extract_url, format: nil, reservation: nil, &block
635+
job = extract_job extract_url, format: format, reservation: reservation, &block
625636
job.wait_until_done!
626637
ensure_job_succeeded! job
627638
true

0 commit comments

Comments
 (0)