Repository: GoogleCloudPlatform/pgadapter
Pull request #524 (2022-11-29 14:57:13)

feat: enable JSONB array parsing
Enable JSONB array parsing and a test for JSONB that was disabled awaiting support for the type.

codecov[bot]: # [Codecov](https://codecov.io/gh/GoogleCloudPlatform/pgadapter/pull/524?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleCloudPlatform) Report
> Merging [#524](https://codecov.io/gh/GoogleCloudPlatform/pgadapter/pull/524?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleCloudPlatform) (4000a40) into [postgresql-dialect](https://codecov.io/gh/GoogleCloudPlatform/pgadapter/commit/8f23a48cf72eca6d5acf2c64a02fc61751e858bb?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleCloudPlatform) (8f23a48) will **increase** coverage by `0.04%`.
> The diff coverage is `n/a`.

```diff
@@                   Coverage Diff                    @@
##             postgresql-dialect     #524      +/-   ##
========================================================
+ Coverage                 87.90%   87.95%   +0.04%     
- Complexity                 2030     2046      +16     
========================================================
  Files                       121      122       +1     
  Lines                      6722     6766      +44     
  Branches                    945      948       +3     
========================================================
+ Hits                       5909     5951      +42     
- Misses                      579      580       +1     
- Partials                    234      235       +1     
```

| Flag | Coverage Δ | |
|---|---|---|
| all_tests | `87.95% <ø> (+0.04%)` | :arrow_up: |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleCloudPlatform#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/GoogleCloudPlatform/pgadapter/pull/524?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleCloudPlatform) | Coverage Δ | |
|---|---|---|
| [...e/cloud/spanner/pgadapter/parsers/ArrayParser.java](https://codecov.io/gh/GoogleCloudPlatform/pgadapter/pull/524/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleCloudPlatform#diff-c3JjL21haW4vamF2YS9jb20vZ29vZ2xlL2Nsb3VkL3NwYW5uZXIvcGdhZGFwdGVyL3BhcnNlcnMvQXJyYXlQYXJzZXIuamF2YQ==) | `78.37% <ø> (ø)` | |
| [...le/cloud/spanner/pgadapter/parsers/UuidParser.java](https://codecov.io/gh/GoogleCloudPlatform/pgadapter/pull/524/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleCloudPlatform#diff-c3JjL21haW4vamF2YS9jb20vZ29vZ2xlL2Nsb3VkL3NwYW5uZXIvcGdhZGFwdGVyL3BhcnNlcnMvVXVpZFBhcnNlci5qYXZh) | `95.34% <0.00%> (ø)` | |
| [...google/cloud/spanner/pgadapter/parsers/Parser.java](https://codecov.io/gh/GoogleCloudPlatform/pgadapter/pull/524/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleCloudPlatform#diff-c3JjL21haW4vamF2YS9jb20vZ29vZ2xlL2Nsb3VkL3NwYW5uZXIvcGdhZGFwdGVyL3BhcnNlcnMvUGFyc2VyLmphdmE=) | `88.11% <0.00%> (+0.11%)` | :arrow_up: |

:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleCloudPlatform)


Patch:
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 50c417de..0295b151 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
@@ -105,7 +105,8 @@ public class ArrayParser extends Parser<List<?>> {
     return arrayElementType == Code.BYTES
         || arrayElementType == Code.DATE
         || arrayElementType == Code.STRING
-        || arrayElementType == Code.TIMESTAMP;
+        || arrayElementType == Code.TIMESTAMP
+        || arrayElementType == Code.PG_JSONB;
   }
 
   /**


Test patch:
diff --git a/src/test/java/com/google/cloud/spanner/pgadapter/EmulatedPsqlMockServerTest.java b/src/test/java/com/google/cloud/spanner/pgadapter/EmulatedPsqlMockServerTest.java
index 6ddf6377..59ad5586 100644
--- a/src/test/java/com/google/cloud/spanner/pgadapter/EmulatedPsqlMockServerTest.java
+++ b/src/test/java/com/google/cloud/spanner/pgadapter/EmulatedPsqlMockServerTest.java
@@ -58,7 +58,6 @@ import org.postgresql.PGProperty;
 
 @RunWith(JUnit4.class)
 public class EmulatedPsqlMockServerTest extends AbstractMockServerTest {
-  // @Rule public Timeout globalTimeout = Timeout.seconds(10);
 
   private static final String INSERT1 = "insert into foo values (1)";
   private static final String INSERT2 = "insert into foo values (2)";
diff --git a/src/test/java/com/google/cloud/spanner/pgadapter/parsers/ArrayParserTest.java b/src/test/java/com/google/cloud/spanner/pgadapter/parsers/ArrayParserTest.java
index 54532011..4f7bedb6 100644
--- a/src/test/java/com/google/cloud/spanner/pgadapter/parsers/ArrayParserTest.java
+++ b/src/test/java/com/google/cloud/spanner/pgadapter/parsers/ArrayParserTest.java
@@ -31,7 +31,6 @@ import com.google.cloud.spanner.pgadapter.session.SessionState;
 import com.google.common.collect.ImmutableList;
 import java.time.ZoneId;
 import java.util.Arrays;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.JUnit4;
@@ -148,19 +147,19 @@ public class ArrayParserTest {
     assertEquals("{\"test1\",NULL,\"test2\"}", parser.stringParse());
   }
 
-  @Ignore("json not yet supported")
   @Test
   public void testJsonStringParse() {
     ArrayParser parser =
         new ArrayParser(
             createArrayResultSet(
-                Type.json(),
-                Value.jsonArray(
-                    Arrays.asList("{\"key\": \"value1\"}}", null, "{\"key\": \"value2\"}"))),
+                Type.pgJsonb(),
+                Value.pgJsonbArray(
+                    Arrays.asList("{\"key\": \"value1\"}", null, "{\"key\": \"value2\"}"))),
             0,
             mock(SessionState.class));
 
-    assertEquals("{\"test1\",NULL,\"test2\"}", parser.stringParse());
+    assertEquals(
+        "{\"{\"key\": \"value1\"}\",NULL,\"{\"key\": \"value2\"}\"}", parser.stringParse());
   }
 
   static ResultSet createArrayResultSet(Type arrayElementType, Value value) {