Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(spanner): add PG.OID tests #72

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require "spanner_helper"

describe "Spanner Client", :params, :bool, :spanner do
let(:db) { spanner_pg_client }

it "queries and returns a PG.OID parameter" do
skip if emulator_enabled?
results = db.execute_query "SELECT $1 AS value", params: { p1: 123 }, types: { p1: :PG_OID }

_(results).must_be_kind_of Google::Cloud::Spanner::Results
_(results.fields[:value]).must_equal :INT64
_(results.rows.first[:value]).must_equal 123
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require "spanner_helper"

describe "Spanner Client", :types, :oid, :spanner do
let(:db) { spanner_pg_client }
let(:table_name) { "stuffs" }

it "queries pg.oid" do
skip if emulator_enabled?
results = db.execute_sql "select 123::oid as value"

_(results).must_be_kind_of Google::Cloud::Spanner::Results
_(results.fields.to_h).must_equal({ value: :INT64 })
_(results.rows.first.to_h).must_equal({ value: 123 })
end
end
4 changes: 3 additions & 1 deletion google-cloud-spanner/lib/google/cloud/spanner/convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ def grpc_type_for_field field
when :PG_NUMERIC
V1::Type.new(code: :NUMERIC, type_annotation: :PG_NUMERIC)
when :PG_JSONB
V1::Type.new(code: :JSON, type_annotation: :PG_JSONB)
V1::Type.new(code: :JSON, type_annotation: :PG_JSONB)
when :PG_OID
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also add a unit test in
ruby-spanner/google-cloud-spanner/test/google/cloud/spanner/convert/grpc_type_for_field_test.rb

V1::Type.new(code: :INT64, type_annotation: :PG_OID)
else
V1::Type.new(code: field)
end
Expand Down
Loading