From 13e77c552ae535ee7616bcc9d663ff828d4b6bf8 Mon Sep 17 00:00:00 2001 From: Hengfeng Li Date: Tue, 14 Nov 2023 17:07:25 +1100 Subject: [PATCH 1/2] test(spanner): add PG.OID tests --- .../spanner/client/params/pgoid_test.rb | 28 ++++++++++++++++++ .../spanner/client/types/pgoid_test.rb | 29 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 google-cloud-spanner/acceptance/spanner/client/params/pgoid_test.rb create mode 100644 google-cloud-spanner/acceptance/spanner/client/types/pgoid_test.rb diff --git a/google-cloud-spanner/acceptance/spanner/client/params/pgoid_test.rb b/google-cloud-spanner/acceptance/spanner/client/params/pgoid_test.rb new file mode 100644 index 00000000..0fdaf03f --- /dev/null +++ b/google-cloud-spanner/acceptance/spanner/client/params/pgoid_test.rb @@ -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 diff --git a/google-cloud-spanner/acceptance/spanner/client/types/pgoid_test.rb b/google-cloud-spanner/acceptance/spanner/client/types/pgoid_test.rb new file mode 100644 index 00000000..fad47580 --- /dev/null +++ b/google-cloud-spanner/acceptance/spanner/client/types/pgoid_test.rb @@ -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 From 47203f51d6c361fabfb2ef43d2ded3b1a365b8d6 Mon Sep 17 00:00:00 2001 From: Hengfeng Li Date: Wed, 15 Nov 2023 22:02:29 +1100 Subject: [PATCH 2/2] Fix. --- google-cloud-spanner/lib/google/cloud/spanner/convert.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/google-cloud-spanner/lib/google/cloud/spanner/convert.rb b/google-cloud-spanner/lib/google/cloud/spanner/convert.rb index 2f86eb69..65d39789 100644 --- a/google-cloud-spanner/lib/google/cloud/spanner/convert.rb +++ b/google-cloud-spanner/lib/google/cloud/spanner/convert.rb @@ -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 + V1::Type.new(code: :INT64, type_annotation: :PG_OID) else V1::Type.new(code: field) end