Repository: googleapis/java-spanner-jdbc
Pull request #443 (2021-04-26 22:02:17)

chore(deps): update dependency com.google.cloud:google-cloud-spanner-jdbc to v2.0.2
[![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [com.google.cloud:google-cloud-spanner-jdbc](https://togithub.com/googleapis/java-spanner-jdbc) | `2.0.1` -> `2.0.2` | [![age](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-spanner-jdbc/2.0.2/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-spanner-jdbc/2.0.2/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-spanner-jdbc/2.0.2/compatibility-slim/2.0.1)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-spanner-jdbc/2.0.2/confidence-slim/2.0.1)](https://docs.renovatebot.com/merge-confidence/) |

---

### Configuration

:date: **Schedule**: At any time (no schedule defined).

:vertical_traffic_light: **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

:recycle: **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

:no_bell: **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box.

---

This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/java-spanner-jdbc).

codecov[bot]: # [Codecov](https://codecov.io/gh/googleapis/java-spanner-jdbc/pull/443?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=googleapis) Report
> Merging [#443](https://codecov.io/gh/googleapis/java-spanner-jdbc/pull/443?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=googleapis) (5db7892) into [master](https://codecov.io/gh/googleapis/java-spanner-jdbc/commit/cd52b2bc91ae87168f28663373b690f09b042955?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=googleapis) (cd52b2b) will **decrease** coverage by `0.00%`.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/googleapis/java-spanner-jdbc/pull/443/graphs/tree.svg?width=650&height=150&src=pr&token=ODlczvbGrj&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=googleapis)](https://codecov.io/gh/googleapis/java-spanner-jdbc/pull/443?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=googleapis)

```diff
@@             Coverage Diff              @@
##             master     #443      +/-   ##
============================================
- Coverage     72.70%   72.69%   -0.01%     
  Complexity     1162     1162              
============================================
  Files            24       24              
  Lines          3583     3582       -1     
  Branches        533      529       -4     
============================================
- Hits           2605     2604       -1     
+ Misses          757      756       -1     
- Partials        221      222       +1     
```


| [Impacted Files](https://codecov.io/gh/googleapis/java-spanner-jdbc/pull/443?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=googleapis) | Coverage Δ | Complexity Δ | |
|---|---|---|---|
| [...ud/spanner/jdbc/AbstractJdbcPreparedStatement.java](https://codecov.io/gh/googleapis/java-spanner-jdbc/pull/443/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=googleapis#diff-c3JjL21haW4vamF2YS9jb20vZ29vZ2xlL2Nsb3VkL3NwYW5uZXIvamRiYy9BYnN0cmFjdEpkYmNQcmVwYXJlZFN0YXRlbWVudC5qYXZh) | `89.82% <0.00%> (-0.60%)` | `52.00% <0.00%> (ø%)` | |
| [...a/com/google/cloud/spanner/jdbc/JdbcResultSet.java](https://codecov.io/gh/googleapis/java-spanner-jdbc/pull/443/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=googleapis#diff-c3JjL21haW4vamF2YS9jb20vZ29vZ2xlL2Nsb3VkL3NwYW5uZXIvamRiYy9KZGJjUmVzdWx0U2V0LmphdmE=) | `75.54% <0.00%> (+0.20%)` | `190.00% <0.00%> (ø%)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/googleapis/java-spanner-jdbc/pull/443?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=googleapis).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=googleapis)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/googleapis/java-spanner-jdbc/pull/443?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=googleapis). Last update [cd52b2b...5db7892](https://codecov.io/gh/googleapis/java-spanner-jdbc/pull/443?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=googleapis). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=googleapis).


Patch:
diff --git a/samples/install-without-bom/pom.xml b/samples/install-without-bom/pom.xml
index e5e5c85..e6a32e3 100644
--- a/samples/install-without-bom/pom.xml
+++ b/samples/install-without-bom/pom.xml
@@ -29,7 +29,7 @@
     <dependency>
       <groupId>com.google.cloud</groupId>
       <artifactId>google-cloud-spanner-jdbc</artifactId>
-      <version>2.0.1</version>
+      <version>2.0.2</version>
     </dependency>
     <!-- [END spanner-jdbc_install_without_bom] -->
 
diff --git a/src/main/java/com/google/cloud/spanner/jdbc/JdbcDataType.java b/src/main/java/com/google/cloud/spanner/jdbc/JdbcDataType.java
index 1dc5f0e..6e6c3bf 100644
--- a/src/main/java/com/google/cloud/spanner/jdbc/JdbcDataType.java
+++ b/src/main/java/com/google/cloud/spanner/jdbc/JdbcDataType.java
@@ -17,6 +17,7 @@
 package com.google.cloud.spanner.jdbc;
 
 import com.google.cloud.spanner.ResultSet;
+import com.google.cloud.spanner.Struct;
 import com.google.cloud.spanner.Type;
 import com.google.cloud.spanner.Type.Code;
 import java.math.BigDecimal;
@@ -253,6 +254,32 @@ enum JdbcDataType {
     public Type getSpannerType() {
       return Type.timestamp();
     }
+  },
+  STRUCT {
+    @Override
+    public int getSqlType() {
+      return Types.STRUCT;
+    }
+
+    @Override
+    public Class<Struct> getJavaClass() {
+      return Struct.class;
+    }
+
+    @Override
+    public Code getCode() {
+      return Code.STRUCT;
+    }
+
+    @Override
+    public List<Struct> getArrayElements(ResultSet rs, int columnIndex) {
+      return rs.getStructList(columnIndex);
+    }
+
+    @Override
+    public Type getSpannerType() {
+      return Type.struct();
+    }
   };
 
   public abstract int getSqlType();


Test patch:
diff --git a/src/test/java/com/google/cloud/spanner/jdbc/JdbcArrayTest.java b/src/test/java/com/google/cloud/spanner/jdbc/JdbcArrayTest.java
index 24e3e57..f8cacd9 100644
--- a/src/test/java/com/google/cloud/spanner/jdbc/JdbcArrayTest.java
+++ b/src/test/java/com/google/cloud/spanner/jdbc/JdbcArrayTest.java
@@ -18,15 +18,19 @@ package com.google.cloud.spanner.jdbc;
 
 import static com.google.cloud.spanner.jdbc.JdbcTypeConverter.toSqlDate;
 import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.fail;
 
 import com.google.cloud.spanner.ErrorCode;
+import com.google.cloud.spanner.Struct;
 import com.google.cloud.spanner.jdbc.JdbcSqlExceptionFactory.JdbcSqlExceptionImpl;
 import java.math.BigDecimal;
 import java.sql.Date;
 import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
 import java.sql.Timestamp;
 import java.sql.Types;
 import org.junit.Test;
@@ -174,16 +178,17 @@ public class JdbcArrayTest {
   }
 
   @Test
-  public void testCreateArrayOfStruct() {
-    try {
-      JdbcArray.createArray("STRUCT", new Object[] {});
-      fail("missing expected exception");
-    } catch (SQLException e) {
-      assertThat((Exception) e).isInstanceOf(JdbcSqlException.class);
-      JdbcSqlException jse = (JdbcSqlException) e;
-      assertThat(jse.getErrorCode())
-          .isEqualTo(ErrorCode.INVALID_ARGUMENT.getGrpcStatusCode().value());
-    }
+  public void testCreateArrayOfStruct() throws SQLException {
+    JdbcArray array =
+        JdbcArray.createArray(
+            "STRUCT",
+            new Struct[] {Struct.newBuilder().set("f1").to("v1").set("f2").to(1L).build(), null});
+    assertEquals(Types.STRUCT, array.getBaseType());
+    assertThat((Struct[]) array.getArray())
+        .asList()
+        .containsExactly(Struct.newBuilder().set("f1").to("v1").set("f2").to(1L).build(), null)
+        .inOrder();
+    assertThrows(SQLFeatureNotSupportedException.class, () -> array.getResultSet());
   }
 
   @Test
diff --git a/src/test/java/com/google/cloud/spanner/jdbc/it/ITJdbcSimpleStatementsTest.java b/src/test/java/com/google/cloud/spanner/jdbc/it/ITJdbcSimpleStatementsTest.java
index 15f25b9..fcb3b0e 100644
--- a/src/test/java/com/google/cloud/spanner/jdbc/it/ITJdbcSimpleStatementsTest.java
+++ b/src/test/java/com/google/cloud/spanner/jdbc/it/ITJdbcSimpleStatementsTest.java
@@ -17,14 +17,22 @@
 package com.google.cloud.spanner.jdbc.it;
 
 import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThrows;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import com.google.cloud.spanner.IntegrationTest;
+import com.google.cloud.spanner.Struct;
+import com.google.cloud.spanner.Value;
 import com.google.cloud.spanner.jdbc.ITAbstractJdbcTest;
+import java.sql.Array;
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
 import java.sql.Statement;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
@@ -149,4 +157,38 @@ public class ITJdbcSimpleStatementsTest extends ITAbstractJdbcTest {
               "Calling addBatch() is not allowed when a DML or DDL batch has been started on the connection.");
     }
   }
+
+  @Test
+  public void testSelectArrayOfStructs() throws SQLException {
+    String sql =
+        "WITH points AS\n"
+            + "  (SELECT [1, 5] as point\n"
+            + "   UNION ALL SELECT [2, 8] as point\n"
+            + "   UNION ALL SELECT [3, 7] as point\n"
+            + "   UNION ALL SELECT [4, 1] as point\n"
+            + "   UNION ALL SELECT [5, 7] as point)\n"
+            + "SELECT ARRAY(\n"
+            + "  SELECT STRUCT(point)\n"
+            + "  FROM points)\n"
+            + "  AS coordinates";
+    try (Connection connection = createConnection()) {
+      try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) {
+        assertTrue(resultSet.next());
+        assertEquals(resultSet.getMetaData().getColumnCount(), 1);
+        Array array = resultSet.getArray(1);
+        assertThat((Struct[]) array.getArray())
+            .asList()
+            .containsExactly(
+                Struct.newBuilder().set("point").to(Value.int64Array(new long[] {1L, 5L})).build(),
+                Struct.newBuilder().set("point").to(Value.int64Array(new long[] {2L, 8L})).build(),
+                Struct.newBuilder().set("point").to(Value.int64Array(new long[] {3L, 7L})).build(),
+                Struct.newBuilder().set("point").to(Value.int64Array(new long[] {4L, 1L})).build(),
+                Struct.newBuilder().set("point").to(Value.int64Array(new long[] {5L, 7L})).build());
+        // Getting a result set from an array of structs is not supported, as structs are not
+        // supported as a valid column type in a result set.
+        assertThrows(SQLFeatureNotSupportedException.class, () -> array.getResultSet());
+        assertFalse(resultSet.next());
+      }
+    }
+  }
 }