Skip to content

Commit

Permalink
feat(bigquery): add method in load_job to set column name character m…
Browse files Browse the repository at this point in the history
…ap (#26135)
  • Loading branch information
juseveno authored Jun 24, 2024
1 parent 13ce4df commit 9ed0507
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion google-cloud-bigquery/google-cloud-bigquery.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Gem::Specification.new do |gem|

gem.add_dependency "bigdecimal", "~> 3.0"
gem.add_dependency "concurrent-ruby", "~> 1.0"
gem.add_dependency "google-apis-bigquery_v2", "~> 0.62"
gem.add_dependency "google-apis-bigquery_v2", "~> 0.71"
gem.add_dependency "google-apis-core", "~> 0.13"
gem.add_dependency "googleauth", "~> 1.9"
gem.add_dependency "google-cloud-core", "~> 1.6"
Expand Down
15 changes: 15 additions & 0 deletions google-cloud-bigquery/lib/google/cloud/bigquery/convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,21 @@ def self.write_disposition str
str
end

##
# Converts character map strings to API values.
#
# @return [String] API representation of character map.
def self.character_map mapping_version
val = {
"default" => "COLUMN_NAME_CHARACTER_MAP_UNSPECIFIED",
"strict" => "STRICT",
"v1" => "V1",
"v2" => "V2"
}[mapping_version.to_s.downcase]
return val unless val.nil?
mapping_version
end

##
# Converts source format strings to API values.
#
Expand Down
18 changes: 18 additions & 0 deletions google-cloud-bigquery/lib/google/cloud/bigquery/load_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1727,6 +1727,24 @@ def format= new_format
@gapi.configuration.load.update! source_format: Convert.source_format(new_format)
end

##
# Sets the character map for column name conversion. The default value is `default`.
#
# The following values are supported:
#
# * `default`
# * `strict`
# * `v1`
# * `v2`
#
# @param [String] new_character_map The new character map.
#
# @!group Attributes
#
def column_name_character_map= new_character_map
@gapi.configuration.load.update! column_name_character_map: Convert.character_map(new_character_map)
end

##
# Sets the create disposition.
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,29 @@ def new_updater
Google::Cloud::Bigquery::LoadJob::Updater.new new_job
end

it "can set the column name character map" do
updater = new_updater
updater.column_name_character_map = "default"
job_gapi = updater.to_gapi
_(job_gapi.configuration.load.column_name_character_map).must_equal "COLUMN_NAME_CHARACTER_MAP_UNSPECIFIED"

updater.column_name_character_map = "strict"
job_gapi = updater.to_gapi
_(job_gapi.configuration.load.column_name_character_map).must_equal "STRICT"

updater.column_name_character_map = "v1"
job_gapi = updater.to_gapi
_(job_gapi.configuration.load.column_name_character_map).must_equal "V1"

updater.column_name_character_map = "v2"
job_gapi = updater.to_gapi
_(job_gapi.configuration.load.column_name_character_map).must_equal "V2"

updater.column_name_character_map = "SOME_NEW_CHARACTER_MAP"
job_gapi = updater.to_gapi
_(job_gapi.configuration.load.column_name_character_map).must_equal "SOME_NEW_CHARACTER_MAP"
end

it "can set the source format" do
updater = new_updater
updater.format = "csv"
Expand Down

0 comments on commit 9ed0507

Please sign in to comment.