Skip to content

Commit 59d12eb

Browse files
committed
fix: unrecognized types with array element type should be considered unrecognized
1 parent 617120d commit 59d12eb

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/Type.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,13 @@ public int getFieldIndex(String fieldName) {
394394

395395
void toString(StringBuilder b) {
396396
if (code == Code.ARRAY || (proto != null && proto.hasArrayElementType())) {
397-
b.append("ARRAY<");
397+
if (code == Code.ARRAY) {
398+
b.append("ARRAY<");
399+
} else {
400+
// This is very unlikely to happen. It would mean that we have introduced a type that
401+
// is not an ARRAY, but does have an array element type.
402+
b.append("UNRECOGNIZED<");
403+
}
398404
arrayElementType.toString(b);
399405
b.append('>');
400406
} else if (code == Code.STRUCT) {

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import com.google.cloud.spanner.SessionPool.PooledSessionFuture;
5252
import com.google.cloud.spanner.SpannerException.ResourceNotFoundException;
5353
import com.google.cloud.spanner.SpannerOptions.SpannerCallContextTimeoutConfigurator;
54+
import com.google.cloud.spanner.Type.Code;
5455
import com.google.cloud.spanner.connection.RandomResultSetGenerator;
5556
import com.google.common.base.Stopwatch;
5657
import com.google.common.collect.ImmutableList;
@@ -2901,7 +2902,7 @@ public void testMetadataUnknownTypes() {
29012902
// There are no rows, but we need to call resultSet.next() before we can get the metadata.
29022903
assertFalse(resultSet.next());
29032904
assertEquals(
2904-
"STRUCT<c1 UNRECOGNIZED, c2 STRING<UNRECOGNIZED>, c3 UNRECOGNIZED<PG_NUMERIC>, c4 ARRAY<UNRECOGNIZED>, c5 ARRAY<STRING<UNRECOGNIZED>>, c6 ARRAY<UNRECOGNIZED>, c7 ARRAY<UNRECOGNIZED<PG_NUMERIC>>>",
2905+
"STRUCT<c1 UNRECOGNIZED, c2 STRING<UNRECOGNIZED>, c3 UNRECOGNIZED<PG_NUMERIC>, c4 ARRAY<UNRECOGNIZED>, c5 ARRAY<STRING<UNRECOGNIZED>>, c6 UNRECOGNIZED<UNRECOGNIZED>, c7 ARRAY<UNRECOGNIZED<PG_NUMERIC>>>",
29052906
resultSet.getType().toString());
29062907
assertEquals(
29072908
"UNRECOGNIZED", resultSet.getType().getStructFields().get(0).getType().toString());
@@ -2913,14 +2914,32 @@ public void testMetadataUnknownTypes() {
29132914
resultSet.getType().getStructFields().get(2).getType().toString());
29142915
assertEquals(
29152916
"ARRAY<UNRECOGNIZED>", resultSet.getType().getStructFields().get(3).getType().toString());
2917+
assertEquals(Code.ARRAY, resultSet.getType().getStructFields().get(3).getType().getCode());
2918+
assertEquals(
2919+
Code.UNRECOGNIZED,
2920+
resultSet.getType().getStructFields().get(3).getType().getArrayElementType().getCode());
29162921
assertEquals(
29172922
"ARRAY<STRING<UNRECOGNIZED>>",
29182923
resultSet.getType().getStructFields().get(4).getType().toString());
2924+
assertEquals(Code.ARRAY, resultSet.getType().getStructFields().get(4).getType().getCode());
2925+
assertEquals(
2926+
Code.UNRECOGNIZED,
2927+
resultSet.getType().getStructFields().get(4).getType().getArrayElementType().getCode());
2928+
assertEquals(
2929+
"UNRECOGNIZED<UNRECOGNIZED>",
2930+
resultSet.getType().getStructFields().get(5).getType().toString());
29192931
assertEquals(
2920-
"ARRAY<UNRECOGNIZED>", resultSet.getType().getStructFields().get(5).getType().toString());
2932+
Code.UNRECOGNIZED, resultSet.getType().getStructFields().get(5).getType().getCode());
2933+
assertEquals(
2934+
Code.UNRECOGNIZED,
2935+
resultSet.getType().getStructFields().get(5).getType().getArrayElementType().getCode());
29212936
assertEquals(
29222937
"ARRAY<UNRECOGNIZED<PG_NUMERIC>>",
29232938
resultSet.getType().getStructFields().get(6).getType().toString());
2939+
assertEquals(Code.ARRAY, resultSet.getType().getStructFields().get(6).getType().getCode());
2940+
assertEquals(
2941+
Code.UNRECOGNIZED,
2942+
resultSet.getType().getStructFields().get(6).getType().getArrayElementType().getCode());
29242943
}
29252944
}
29262945

0 commit comments

Comments
 (0)