Skip to content

Commit d82115d

Browse files
authored
test: mock Spanner did not create jsonb parameters (#2182)
The mock Spanner server that is used for testing did not create statements with PG JSONB typed parameters. Instead, all parameters with TypeCode JSON would create statements with parameters of type JSON, regardless of any TypeAnnotationCode.
1 parent 19058b4 commit d82115d

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

google-cloud-spanner/src/test/java/com/google/cloud/spanner/MockSpannerServiceImpl.java

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,11 @@ private Statement buildStatement(
12891289
builder.bind(fieldName).toTimestampArray(null);
12901290
break;
12911291
case JSON:
1292-
builder.bind(fieldName).toJsonArray(null);
1292+
if (elementType.getTypeAnnotation() == TypeAnnotationCode.PG_JSONB) {
1293+
builder.bind(fieldName).toPgJsonbArray(null);
1294+
} else {
1295+
builder.bind(fieldName).toJsonArray(null);
1296+
}
12931297
break;
12941298
case STRUCT:
12951299
case TYPE_CODE_UNSPECIFIED:
@@ -1331,7 +1335,11 @@ private Statement buildStatement(
13311335
builder.bind(fieldName).to((com.google.cloud.Timestamp) null);
13321336
break;
13331337
case JSON:
1334-
builder.bind(fieldName).to(Value.json(null));
1338+
if (fieldType.getTypeAnnotation() == TypeAnnotationCode.PG_JSONB) {
1339+
builder.bind(fieldName).to(Value.pgJsonb(null));
1340+
} else {
1341+
builder.bind(fieldName).to(Value.json(null));
1342+
}
13351343
break;
13361344
case TYPE_CODE_UNSPECIFIED:
13371345
case UNRECOGNIZED:
@@ -1416,12 +1424,21 @@ private Statement buildStatement(
14161424
com.google.cloud.spanner.Type.timestamp(), value.getListValue()));
14171425
break;
14181426
case JSON:
1419-
builder
1420-
.bind(fieldName)
1421-
.toJsonArray(
1422-
(Iterable<String>)
1423-
GrpcStruct.decodeArrayValue(
1424-
com.google.cloud.spanner.Type.json(), value.getListValue()));
1427+
if (elementType.getTypeAnnotation() == TypeAnnotationCode.PG_JSONB) {
1428+
builder
1429+
.bind(fieldName)
1430+
.toPgJsonbArray(
1431+
(Iterable<String>)
1432+
GrpcStruct.decodeArrayValue(
1433+
com.google.cloud.spanner.Type.pgJsonb(), value.getListValue()));
1434+
} else {
1435+
builder
1436+
.bind(fieldName)
1437+
.toJsonArray(
1438+
(Iterable<String>)
1439+
GrpcStruct.decodeArrayValue(
1440+
com.google.cloud.spanner.Type.json(), value.getListValue()));
1441+
}
14251442
break;
14261443
case STRUCT:
14271444
case TYPE_CODE_UNSPECIFIED:
@@ -1464,7 +1481,11 @@ private Statement buildStatement(
14641481
.to(com.google.cloud.Timestamp.parseTimestamp(value.getStringValue()));
14651482
break;
14661483
case JSON:
1467-
builder.bind(fieldName).to(Value.json(value.getStringValue()));
1484+
if (fieldType.getTypeAnnotation() == TypeAnnotationCode.PG_JSONB) {
1485+
builder.bind(fieldName).to(Value.pgJsonb(value.getStringValue()));
1486+
} else {
1487+
builder.bind(fieldName).to(Value.json(value.getStringValue()));
1488+
}
14681489
break;
14691490
case TYPE_CODE_UNSPECIFIED:
14701491
case UNRECOGNIZED:

0 commit comments

Comments
 (0)