From 9165b9eb1e467db58577c180cf3563dd8b14e011 Mon Sep 17 00:00:00 2001 From: Mend Renovate Date: Tue, 30 Apr 2024 18:26:26 +0000 Subject: [PATCH 1/2] chore(deps): update dependency com.google.cloud:libraries-bom to v26.38.0 --- benchmarks/latency-comparison/java/pom.xml | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/benchmarks/latency-comparison/java/pom.xml b/benchmarks/latency-comparison/java/pom.xml index f78b3f63c..ef24a75d8 100644 --- a/benchmarks/latency-comparison/java/pom.xml +++ b/benchmarks/latency-comparison/java/pom.xml @@ -43,7 +43,7 @@ com.google.cloud libraries-bom - 26.37.0 + 26.38.0 pom import diff --git a/pom.xml b/pom.xml index 600a0a20a..995ff52b0 100644 --- a/pom.xml +++ b/pom.xml @@ -77,7 +77,7 @@ com.google.cloud libraries-bom - 26.37.0 + 26.38.0 pom import From 9ba85b1189403273c3aaa45edca1de9784982fab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Knut=20Olav=20L=C3=B8ite?= Date: Wed, 1 May 2024 09:47:31 +0200 Subject: [PATCH 2/2] chore: add support for pg_oid --- .../pgadapter/parsers/ArrayParser.java | 4 ++++ .../spanner/pgadapter/parsers/Parser.java | 20 +++++++++++++++++++ .../spanner/pgadapter/utils/Converter.java | 1 + .../spanner/pgadapter/JdbcMockServerTest.java | 2 +- .../OpenTelemetryMockServerTest.java | 2 +- 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/google/cloud/spanner/pgadapter/parsers/ArrayParser.java b/src/main/java/com/google/cloud/spanner/pgadapter/parsers/ArrayParser.java index e4d25bc54..6e68b59ce 100644 --- a/src/main/java/com/google/cloud/spanner/pgadapter/parsers/ArrayParser.java +++ b/src/main/java/com/google/cloud/spanner/pgadapter/parsers/ArrayParser.java @@ -110,6 +110,7 @@ private List toList(Value value, Code arrayElementType) { case BYTES: return value.getBytesArray(); case INT64: + case PG_OID: return value.getInt64Array(); case STRING: case PG_NUMERIC: @@ -377,6 +378,9 @@ public void bind(Statement.Builder statementBuilder, String name) { case Oid.INT8: statementBuilder.bind(name).toInt64Array((List) this.item); break; + case Oid.OID: + statementBuilder.bind(name).toPgOidArray((List) this.item); + break; case Oid.NUMERIC: statementBuilder.bind(name).toPgNumericArray((List) this.item); break; diff --git a/src/main/java/com/google/cloud/spanner/pgadapter/parsers/Parser.java b/src/main/java/com/google/cloud/spanner/pgadapter/parsers/Parser.java index 8929a5541..5968cdd90 100644 --- a/src/main/java/com/google/cloud/spanner/pgadapter/parsers/Parser.java +++ b/src/main/java/com/google/cloud/spanner/pgadapter/parsers/Parser.java @@ -23,6 +23,7 @@ import com.google.cloud.spanner.pgadapter.error.PGExceptionFactory; import com.google.cloud.spanner.pgadapter.error.SQLState; import com.google.cloud.spanner.pgadapter.session.SessionState; +import com.google.spanner.v1.TypeAnnotationCode; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import org.postgresql.core.Oid; @@ -81,6 +82,7 @@ public static Parser create( case Oid.INT4: return new IntegerParser(item, formatCode); case Oid.INT8: + case Oid.OID: return new LongParser(item, formatCode); case Oid.NUMERIC: return new NumericParser(item, formatCode); @@ -103,6 +105,7 @@ public static Parser create( case Oid.INT2_ARRAY: case Oid.INT4_ARRAY: case Oid.INT8_ARRAY: + case Oid.OID_ARRAY: case Oid.NUMERIC_ARRAY: case Oid.TEXT_ARRAY: case Oid.VARCHAR_ARRAY: @@ -141,6 +144,8 @@ static int getArrayElementOid(int arrayOid) { return Oid.INT4; case Oid.INT8_ARRAY: return Oid.INT8; + case Oid.OID_ARRAY: + return Oid.OID; case Oid.NUMERIC_ARRAY: return Oid.NUMERIC; case Oid.TEXT_ARRAY: @@ -182,6 +187,7 @@ public static Parser create( case FLOAT64: return new DoubleParser(result, columnarPosition); case INT64: + case PG_OID: return new LongParser(result, columnarPosition); case PG_NUMERIC: return new NumericParser(result, columnarPosition); @@ -221,6 +227,7 @@ protected static Parser create(Object result, Code typeCode, SessionState ses case FLOAT64: return new DoubleParser(result); case INT64: + case PG_OID: return new LongParser(result); case PG_NUMERIC: return new NumericParser(result); @@ -250,6 +257,8 @@ public static int toOid(Type type) { return Oid.BOOL; case INT64: return Oid.INT8; + case PG_OID: + return Oid.OID; case PG_NUMERIC: return Oid.NUMERIC; case FLOAT32: @@ -272,6 +281,8 @@ public static int toOid(Type type) { return Oid.BOOL_ARRAY; case INT64: return Oid.INT8_ARRAY; + case PG_OID: + return Oid.OID_ARRAY; case PG_NUMERIC: return Oid.NUMERIC_ARRAY; case FLOAT32: @@ -323,6 +334,8 @@ public static Type toType(int oid) { case Oid.INT4: case Oid.INT8: return Type.int64(); + case Oid.OID: + return Type.pgOid(); case Oid.NUMERIC: return Type.pgNumeric(); case Oid.TEXT: @@ -343,6 +356,7 @@ public static Type toType(int oid) { case Oid.INT2_ARRAY: case Oid.INT4_ARRAY: case Oid.INT8_ARRAY: + case Oid.OID_ARRAY: case Oid.NUMERIC_ARRAY: case Oid.TEXT_ARRAY: case Oid.VARCHAR_ARRAY: @@ -370,6 +384,9 @@ public static int toOid(com.google.spanner.v1.Type type) { case BOOL: return Oid.BOOL; case INT64: + if (type.getTypeAnnotation() == TypeAnnotationCode.PG_OID) { + return Oid.OID; + } return Oid.INT8; case NUMERIC: return Oid.NUMERIC; @@ -392,6 +409,9 @@ public static int toOid(com.google.spanner.v1.Type type) { case BOOL: return Oid.BOOL_ARRAY; case INT64: + if (type.getArrayElementType().getTypeAnnotation() == TypeAnnotationCode.PG_OID) { + return Oid.OID_ARRAY; + } return Oid.INT8_ARRAY; case NUMERIC: return Oid.NUMERIC_ARRAY; diff --git a/src/main/java/com/google/cloud/spanner/pgadapter/utils/Converter.java b/src/main/java/com/google/cloud/spanner/pgadapter/utils/Converter.java index 1569e5d6d..82e7454e4 100644 --- a/src/main/java/com/google/cloud/spanner/pgadapter/utils/Converter.java +++ b/src/main/java/com/google/cloud/spanner/pgadapter/utils/Converter.java @@ -167,6 +167,7 @@ public static byte[] convertToPG( case FLOAT64: return DoubleParser.convertToPG(result, position, format); case INT64: + case PG_OID: return LongParser.convertToPG(result, position, format); case PG_NUMERIC: return NumericParser.convertToPG(result, position, format); diff --git a/src/test/java/com/google/cloud/spanner/pgadapter/JdbcMockServerTest.java b/src/test/java/com/google/cloud/spanner/pgadapter/JdbcMockServerTest.java index 7b7fc476f..d1119624d 100644 --- a/src/test/java/com/google/cloud/spanner/pgadapter/JdbcMockServerTest.java +++ b/src/test/java/com/google/cloud/spanner/pgadapter/JdbcMockServerTest.java @@ -3288,7 +3288,7 @@ public void testRandomResults() throws SQLException { // type (jsonb is not one of the types that the JDBC driver will load // automatically). final int jsonbColumnIndex = 6; - final int jsonbArrayColumnIndex = 16; + final int jsonbArrayColumnIndex = 17; if (col == jsonbColumnIndex || col == jsonbArrayColumnIndex) { resultSet.getString(col + 1); } else { diff --git a/src/test/java/com/google/cloud/spanner/pgadapter/OpenTelemetryMockServerTest.java b/src/test/java/com/google/cloud/spanner/pgadapter/OpenTelemetryMockServerTest.java index a5a20fa1a..8773f5e96 100644 --- a/src/test/java/com/google/cloud/spanner/pgadapter/OpenTelemetryMockServerTest.java +++ b/src/test/java/com/google/cloud/spanner/pgadapter/OpenTelemetryMockServerTest.java @@ -62,7 +62,7 @@ public void testSelectInAutoCommit() throws SQLException { try (Connection connection = DriverManager.getConnection(createUrl())) { try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { while (resultSet.next()) { - assertEquals(20, resultSet.getMetaData().getColumnCount()); + assertEquals(22, resultSet.getMetaData().getColumnCount()); } } }