Skip to content

Commit 0a95dba

Browse files
authored
fix: cast for Proto type (#2862)
* fix: cast for Proto type * fix: add null check * feat(spanner): add ENUM compatibility with getLongArray * feat: fix argument * feat: fix bug
1 parent 244d6a8 commit 0a95dba

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,10 @@ private Object writeReplace() {
478478
case PROTO:
479479
builder
480480
.set(fieldName)
481-
.to(Value.protoMessage((ByteArray) value, fieldType.getProtoTypeFqn()));
481+
.to(
482+
Value.protoMessage(
483+
value == null ? null : ((LazyByteArray) value).getByteArray(),
484+
fieldType.getProtoTypeFqn()));
482485
break;
483486
case ENUM:
484487
builder.set(fieldName).to(Value.protoEnum((Long) value, fieldType.getProtoTypeFqn()));
@@ -810,7 +813,8 @@ protected Value getValueInternal(int columnIndex) {
810813
case INT64:
811814
return Value.int64(isNull ? null : getLongInternal(columnIndex));
812815
case ENUM:
813-
return Value.protoEnum(getLongInternal(columnIndex), columnType.getProtoTypeFqn());
816+
return Value.protoEnum(
817+
isNull ? null : getLongInternal(columnIndex), columnType.getProtoTypeFqn());
814818
case NUMERIC:
815819
return Value.numeric(isNull ? null : getBigDecimalInternal(columnIndex));
816820
case PG_NUMERIC:
@@ -826,7 +830,8 @@ protected Value getValueInternal(int columnIndex) {
826830
case BYTES:
827831
return Value.internalBytes(isNull ? null : getLazyBytesInternal(columnIndex));
828832
case PROTO:
829-
return Value.protoMessage(getBytesInternal(columnIndex), columnType.getProtoTypeFqn());
833+
return Value.protoMessage(
834+
isNull ? null : getBytesInternal(columnIndex), columnType.getProtoTypeFqn());
830835
case TIMESTAMP:
831836
return Value.timestamp(isNull ? null : getTimestampInternal(columnIndex));
832837
case DATE:

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,14 +340,16 @@ public List<Boolean> getBooleanList(String columnName) {
340340

341341
@Override
342342
public long[] getLongArray(int columnIndex) {
343-
checkNonNullOfType(columnIndex, Type.array(Type.int64()), columnIndex);
343+
checkNonNullOfCodes(columnIndex, Collections.singletonList(Code.ARRAY), columnIndex);
344+
checkArrayElementType(columnIndex, Arrays.asList(Code.ENUM, Code.INT64), columnIndex);
344345
return getLongArrayInternal(columnIndex);
345346
}
346347

347348
@Override
348349
public long[] getLongArray(String columnName) {
349350
int columnIndex = getColumnIndex(columnName);
350-
checkNonNullOfType(columnIndex, Type.array(Type.int64()), columnName);
351+
checkNonNullOfCodes(columnIndex, Collections.singletonList(Code.ARRAY), columnName);
352+
checkArrayElementType(columnIndex, Arrays.asList(Code.ENUM, Code.INT64), columnName);
351353
return getLongArrayInternal(columnIndex);
352354
}
353355

0 commit comments

Comments
 (0)