From cbabd6cf977bf00b9a92091e2a4c2290822c4a8a Mon Sep 17 00:00:00 2001 From: Gaurav Purohit Date: Wed, 28 Dec 2022 16:20:52 +0530 Subject: [PATCH 01/27] feat: Support for Proto Messages & Enums (#2155) * feat: Importing Proto Changes Commit will be reverted, once PROTO changes are available publicly. * feat: Proto Message Implementation * feat: Adding support for enum * feat: Code refactoring Adding default implementation for newly added methods ByteArray compatability changes for Proto Messages * docs: Adding Java docs for all the newly added methods. * test: Sample Proto & Generated classes for unit test * feat: Adding bytes/proto & int64/enum compatability Adding Additional check for ChecksumResultSet * test: Adding unit tests * test: Adding unit tests for ValueBinder.java * feat: refactoring to add support for getValue & other minor changes * feat: Minor refactoring 1. Adding docs and formatting the code. 2. Adding additional methods for enum and message which accepts descriptors. * feat: Adding bytes/message & int64/enum compatability in Value * refactor: Minor refactoring * feat: Adding Proto Array Implementation * test: Implementing unit tests for array of protos and enums * refactor: adding clirr ignores * feat: Adding support for enum as Primary Key * feat: Code Review Changes, minor refactoring and adding docs * feat: Addressing review comments -Modified Docs/Comments -Minor Refactoring * refactor: Using Column instead of column to avoid test failures * feat: Minor refactoring -code review comments -adding function docs --- .../clirr-ignored-differences.xml | 40 + .../cloud/spanner/AbstractResultSet.java | 124 +- .../cloud/spanner/AbstractStructReader.java | 128 +- .../cloud/spanner/ForwardingStructReader.java | 55 + .../java/com/google/cloud/spanner/Key.java | 12 + .../com/google/cloud/spanner/ResultSets.java | 47 + .../java/com/google/cloud/spanner/Struct.java | 30 + .../google/cloud/spanner/StructReader.java | 116 ++ .../java/com/google/cloud/spanner/Type.java | 48 +- .../java/com/google/cloud/spanner/Value.java | 429 +++++- .../com/google/cloud/spanner/ValueBinder.java | 60 + .../spanner/connection/ChecksumResultSet.java | 6 + .../connection/DirectExecuteResultSet.java | 55 + .../ReplaceableForwardingResultSet.java | 55 + .../AbstractStructReaderTypesTest.java | 26 + .../cloud/spanner/GrpcResultSetTest.java | 135 ++ .../google/cloud/spanner/MutationTest.java | 28 + .../google/cloud/spanner/ResultSetsTest.java | 84 +- .../com/google/cloud/spanner/SingerProto.java | 1199 +++++++++++++++++ .../com/google/cloud/spanner/TypeTest.java | 64 +- .../google/cloud/spanner/ValueBinderTest.java | 42 +- .../com/google/cloud/spanner/ValueTest.java | 116 ++ .../connection/ChecksumResultSetTest.java | 47 +- .../DirectExecuteResultSetTest.java | 52 +- .../connection/RandomResultSetGenerator.java | 171 ++- .../connection/ReadWriteTransactionTest.java | 74 +- .../ReplaceableForwardingResultSetTest.java | 52 +- .../com/google/cloud/spanner/singer.proto | 21 + .../main/java/com/google/spanner/v1/Type.java | 305 ++++- .../java/com/google/spanner/v1/TypeCode.java | 12 + .../com/google/spanner/v1/TypeOrBuilder.java | 13 + .../java/com/google/spanner/v1/TypeProto.java | 37 +- .../main/proto/google/spanner/v1/type.proto | 12 + 33 files changed, 3520 insertions(+), 175 deletions(-) create mode 100644 google-cloud-spanner/src/test/java/com/google/cloud/spanner/SingerProto.java create mode 100644 google-cloud-spanner/src/test/resources/com/google/cloud/spanner/singer.proto diff --git a/google-cloud-spanner/clirr-ignored-differences.xml b/google-cloud-spanner/clirr-ignored-differences.xml index 637ca06280a..8e4710354e3 100644 --- a/google-cloud-spanner/clirr-ignored-differences.xml +++ b/google-cloud-spanner/clirr-ignored-differences.xml @@ -192,6 +192,46 @@ com/google/cloud/spanner/StructReader java.util.List getPgJsonbList(java.lang.String) + + 7012 + com/google/cloud/spanner/StructReader + com.google.protobuf.ProtocolMessageEnum getProtoEnum(int, java.util.function.Function) + + + 7012 + com/google/cloud/spanner/StructReader + com.google.protobuf.ProtocolMessageEnum getProtoEnum(java.lang.String, java.util.function.Function) + + + 7012 + com/google/cloud/spanner/StructReader + com.google.protobuf.AbstractMessage getProtoMessage(int, com.google.protobuf.AbstractMessage) + + + 7012 + com/google/cloud/spanner/StructReader + com.google.protobuf.AbstractMessage getProtoMessage(java.lang.String, com.google.protobuf.AbstractMessage) + + + 7012 + com/google/cloud/spanner/StructReader + java.util.List getProtoEnumList(int, java.util.function.Function) + + + 7012 + com/google/cloud/spanner/StructReader + java.util.List getProtoEnumList(java.lang.String, java.util.function.Function) + + + 7012 + com/google/cloud/spanner/StructReader + java.util.List getProtoMessageList(int, com.google.protobuf.AbstractMessage) + + + 7012 + com/google/cloud/spanner/StructReader + java.util.List getProtoMessageList(java.lang.String, com.google.protobuf.AbstractMessage) + 7012 com/google/cloud/spanner/BatchClient diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AbstractResultSet.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AbstractResultSet.java index 789e0945e17..938668c74c0 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AbstractResultSet.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AbstractResultSet.java @@ -32,12 +32,16 @@ import com.google.cloud.spanner.spi.v1.SpannerRpc; import com.google.cloud.spanner.v1.stub.SpannerStubSettings; import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Preconditions; import com.google.common.collect.AbstractIterator; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import com.google.common.util.concurrent.Uninterruptibles; +import com.google.protobuf.AbstractMessage; import com.google.protobuf.ByteString; +import com.google.protobuf.InvalidProtocolBufferException; import com.google.protobuf.ListValue; +import com.google.protobuf.ProtocolMessageEnum; import com.google.protobuf.Value.KindCase; import com.google.spanner.v1.PartialResultSet; import com.google.spanner.v1.ResultSetMetadata; @@ -65,6 +69,7 @@ import java.util.concurrent.Executor; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; +import java.util.function.Function; import java.util.logging.Level; import java.util.logging.Logger; import javax.annotation.Nullable; @@ -391,6 +396,14 @@ private Object writeReplace() { case JSON: builder.set(fieldName).to(Value.json((String) value)); break; + case PROTO: + builder + .set(fieldName) + .to(Value.protoMessage((ByteArray) value, fieldType.getProtoTypeFqn())); + break; + case ENUM: + builder.set(fieldName).to(Value.protoEnum((Long) value, fieldType.getProtoTypeFqn())); + break; case PG_JSONB: builder.set(fieldName).to(Value.pgJsonb((String) value)); break; @@ -410,6 +423,7 @@ private Object writeReplace() { builder.set(fieldName).toBoolArray((Iterable) value); break; case INT64: + case ENUM: builder.set(fieldName).toInt64Array((Iterable) value); break; case FLOAT64: @@ -431,6 +445,7 @@ private Object writeReplace() { builder.set(fieldName).toPgJsonbArray((Iterable) value); break; case BYTES: + case PROTO: builder.set(fieldName).toBytesArray((Iterable) value); break; case TIMESTAMP: @@ -496,6 +511,7 @@ private static Object decodeValue(Type fieldType, com.google.protobuf.Value prot checkType(fieldType, proto, KindCase.BOOL_VALUE); return proto.getBoolValue(); case INT64: + case ENUM: checkType(fieldType, proto, KindCase.STRING_VALUE); return Long.parseLong(proto.getStringValue()); case FLOAT64: @@ -510,6 +526,7 @@ private static Object decodeValue(Type fieldType, com.google.protobuf.Value prot checkType(fieldType, proto, KindCase.STRING_VALUE); return proto.getStringValue(); case BYTES: + case PROTO: checkType(fieldType, proto, KindCase.STRING_VALUE); return ByteArray.fromBase64(proto.getStringValue()); case TIMESTAMP: @@ -547,7 +564,8 @@ private static Struct decodeStructValue(Type structType, ListValue structValue) static Object decodeArrayValue(Type elementType, ListValue listValue) { switch (elementType.getCode()) { case INT64: - // For int64/float64 types, use custom containers. These avoid wrapper object + case ENUM: + // For int64/float64/enum types, use custom containers. These avoid wrapper object // creation for non-null arrays. return new Int64Array(listValue); case FLOAT64: @@ -562,6 +580,7 @@ static Object decodeArrayValue(Type elementType, ListValue listValue) { case TIMESTAMP: case DATE: case STRUCT: + case PROTO: return Lists.transform( listValue.getValuesList(), input -> decodeValue(elementType, input)); default: @@ -597,6 +616,30 @@ public boolean isNull(int columnIndex) { return rowData.get(columnIndex) == null; } + @Override + protected T getProtoMessageInternal(int columnIndex, T message) { + Preconditions.checkNotNull( + message, + "Proto message may not be null. Use MyProtoClass.getDefaultInstance() as a parameter value."); + try { + return (T) + message + .toBuilder() + .mergeFrom(((ByteArray) rowData.get(columnIndex)).toByteArray()) + .build(); + } catch (InvalidProtocolBufferException e) { + throw SpannerExceptionFactory.asSpannerException(e); + } + } + + @Override + protected T getProtoEnumInternal( + int columnIndex, Function method) { + Preconditions.checkNotNull( + method, "Method may not be null. Use 'MyProtoEnum::forNumber' as a parameter value."); + return (T) method.apply((int) getLongInternal(columnIndex)); + } + @Override protected boolean getBooleanInternal(int columnIndex) { return (Boolean) rowData.get(columnIndex); @@ -658,6 +701,8 @@ protected Value getValueInternal(int columnIndex) { return Value.bool(isNull ? null : getBooleanInternal(columnIndex)); case INT64: return Value.int64(isNull ? null : getLongInternal(columnIndex)); + case ENUM: + return Value.protoEnum(getLongInternal(columnIndex), columnType.getProtoTypeFqn()); case NUMERIC: return Value.numeric(isNull ? null : getBigDecimalInternal(columnIndex)); case PG_NUMERIC: @@ -672,6 +717,8 @@ protected Value getValueInternal(int columnIndex) { return Value.pgJsonb(isNull ? null : getPgJsonbInternal(columnIndex)); case BYTES: return Value.bytes(isNull ? null : getBytesInternal(columnIndex)); + case PROTO: + return Value.protoMessage(getBytesInternal(columnIndex), columnType.getProtoTypeFqn()); case TIMESTAMP: return Value.timestamp(isNull ? null : getTimestampInternal(columnIndex)); case DATE: @@ -699,6 +746,12 @@ protected Value getValueInternal(int columnIndex) { return Value.pgJsonbArray(isNull ? null : getPgJsonbListInternal(columnIndex)); case BYTES: return Value.bytesArray(isNull ? null : getBytesListInternal(columnIndex)); + case PROTO: + return Value.protoMessageArray( + isNull ? null : getBytesListInternal(columnIndex), elementType.getProtoTypeFqn()); + case ENUM: + return Value.protoEnumArray( + isNull ? null : getLongListInternal(columnIndex), elementType.getProtoTypeFqn()); case TIMESTAMP: return Value.timestampArray(isNull ? null : getTimestampListInternal(columnIndex)); case DATE: @@ -778,6 +831,52 @@ protected List getJsonListInternal(int columnIndex) { return Collections.unmodifiableList((List) rowData.get(columnIndex)); } + @Override + @SuppressWarnings("unchecked") // We know ARRAY produces a List. + protected List getProtoMessageListInternal( + int columnIndex, T message) { + Preconditions.checkNotNull( + message, + "Proto message may not be null. Use MyProtoClass.getDefaultInstance() as a parameter value."); + + List bytesArray = (List) rowData.get(columnIndex); + + try { + List protoMessagesList = new ArrayList<>(bytesArray.size()); + for (ByteArray protoMessageBytes : bytesArray) { + if (protoMessageBytes == null) { + protoMessagesList.add(null); + } else { + protoMessagesList.add( + (T) message.toBuilder().mergeFrom(protoMessageBytes.toByteArray()).build()); + } + } + return protoMessagesList; + } catch (InvalidProtocolBufferException e) { + throw SpannerExceptionFactory.asSpannerException(e); + } + } + + @Override + @SuppressWarnings("unchecked") // We know ARRAY produces a List. + protected List getProtoEnumListInternal( + int columnIndex, Function method) { + Preconditions.checkNotNull( + method, "Method may not be null. Use 'MyProtoEnum::forNumber' as a parameter value."); + + List enumIntArray = (List) rowData.get(columnIndex); + List protoEnumList = new ArrayList<>(enumIntArray.size()); + for (Long enumIntValue : enumIntArray) { + if (enumIntValue == null) { + protoEnumList.add(null); + } else { + protoEnumList.add((T) method.apply(enumIntValue.intValue())); + } + } + + return protoEnumList; + } + @Override @SuppressWarnings("unchecked") // We know ARRAY produces a List. protected List getPgJsonbListInternal(int columnIndex) { @@ -1310,6 +1409,17 @@ protected String getStringInternal(int columnIndex) { return currRow().getStringInternal(columnIndex); } + @Override + protected T getProtoMessageInternal(int columnIndex, T message) { + return currRow().getProtoMessageInternal(columnIndex, message); + } + + @Override + protected T getProtoEnumInternal( + int columnIndex, Function method) { + return currRow().getProtoEnumInternal(columnIndex, method); + } + @Override protected String getJsonInternal(int columnIndex) { return currRow().getJsonInternal(columnIndex); @@ -1395,6 +1505,18 @@ protected List getBytesListInternal(int columnIndex) { return currRow().getBytesListInternal(columnIndex); } + @Override + protected List getProtoMessageListInternal( + int columnIndex, T message) { + return currRow().getProtoMessageListInternal(columnIndex, message); + } + + @Override + protected List getProtoEnumListInternal( + int columnIndex, Function method) { + return currRow().getProtoEnumListInternal(columnIndex, method); + } + @Override protected List getTimestampListInternal(int columnIndex) { return currRow().getTimestampListInternal(columnIndex); diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AbstractStructReader.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AbstractStructReader.java index 1e897636245..5c205b967eb 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AbstractStructReader.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AbstractStructReader.java @@ -21,9 +21,14 @@ import com.google.cloud.ByteArray; import com.google.cloud.Date; import com.google.cloud.Timestamp; +import com.google.cloud.spanner.Type.Code; +import com.google.protobuf.AbstractMessage; +import com.google.protobuf.ProtocolMessageEnum; import java.math.BigDecimal; import java.util.Arrays; +import java.util.Collections; import java.util.List; +import java.util.function.Function; /** * Base class for assisting {@link StructReader} implementations. @@ -58,6 +63,25 @@ protected String getPgJsonbInternal(int columnIndex) { protected abstract Date getDateInternal(int columnIndex); + protected T getProtoMessageInternal(int columnIndex, T message) { + throw new UnsupportedOperationException("Not implemented"); + } + + protected T getProtoEnumInternal( + int columnIndex, Function method) { + throw new UnsupportedOperationException("Not implemented"); + } + + protected List getProtoMessageListInternal( + int columnIndex, T message) { + throw new UnsupportedOperationException("Not implemented"); + } + + protected List getProtoEnumListInternal( + int columnIndex, Function method) { + throw new UnsupportedOperationException("Not implemented"); + } + protected Value getValueInternal(int columnIndex) { throw new UnsupportedOperationException("method should be overwritten"); } @@ -129,14 +153,14 @@ public boolean getBoolean(String columnName) { @Override public long getLong(int columnIndex) { - checkNonNullOfType(columnIndex, Type.int64(), columnIndex); + checkNonNullOfCodes(columnIndex, Arrays.asList(Code.ENUM, Code.INT64), columnIndex); return getLongInternal(columnIndex); } @Override public long getLong(String columnName) { int columnIndex = getColumnIndex(columnName); - checkNonNullOfType(columnIndex, Type.int64(), columnName); + checkNonNullOfCodes(columnIndex, Arrays.asList(Code.ENUM, Code.INT64), columnName); return getLongInternal(columnIndex); } @@ -212,14 +236,14 @@ public String getPgJsonb(String columnName) { @Override public ByteArray getBytes(int columnIndex) { - checkNonNullOfType(columnIndex, Type.bytes(), columnIndex); + checkNonNullOfCodes(columnIndex, Arrays.asList(Code.PROTO, Code.BYTES), columnIndex); return getBytesInternal(columnIndex); } @Override public ByteArray getBytes(String columnName) { int columnIndex = getColumnIndex(columnName); - checkNonNullOfType(columnIndex, Type.bytes(), columnName); + checkNonNullOfCodes(columnIndex, Arrays.asList(Code.PROTO, Code.BYTES), columnName); return getBytesInternal(columnIndex); } @@ -249,6 +273,34 @@ public Date getDate(String columnName) { return getDateInternal(columnIndex); } + @Override + public T getProtoEnum( + int columnIndex, Function method) { + checkNonNullOfCodes(columnIndex, Arrays.asList(Code.ENUM, Code.INT64), columnIndex); + return getProtoEnumInternal(columnIndex, method); + } + + @Override + public T getProtoEnum( + String columnName, Function method) { + int columnIndex = getColumnIndex(columnName); + checkNonNullOfCodes(columnIndex, Arrays.asList(Code.ENUM, Code.INT64), columnName); + return getProtoEnumInternal(columnIndex, method); + } + + @Override + public T getProtoMessage(int columnIndex, T message) { + checkNonNullOfCodes(columnIndex, Arrays.asList(Code.PROTO, Code.BYTES), columnIndex); + return getProtoMessageInternal(columnIndex, message); + } + + @Override + public T getProtoMessage(String columnName, T message) { + int columnIndex = getColumnIndex(columnName); + checkNonNullOfCodes(columnIndex, Arrays.asList(Code.PROTO, Code.BYTES), columnName); + return getProtoMessageInternal(columnIndex, message); + } + @Override public Value getValue(int columnIndex) { checkNonNull(columnIndex, columnIndex); @@ -302,14 +354,16 @@ public long[] getLongArray(String columnName) { @Override public List getLongList(int columnIndex) { - checkNonNullOfType(columnIndex, Type.array(Type.int64()), columnIndex); + checkNonNullOfCodes(columnIndex, Collections.singletonList(Code.ARRAY), columnIndex); + checkArrayElementType(columnIndex, Arrays.asList(Code.ENUM, Code.INT64), columnIndex); return getLongListInternal(columnIndex); } @Override public List getLongList(String columnName) { int columnIndex = getColumnIndex(columnName); - checkNonNullOfType(columnIndex, Type.array(Type.int64()), columnName); + checkNonNullOfCodes(columnIndex, Collections.singletonList(Code.ARRAY), columnName); + checkArrayElementType(columnIndex, Arrays.asList(Code.ENUM, Code.INT64), columnName); return getLongListInternal(columnIndex); } @@ -401,17 +455,51 @@ public List getPgJsonbList(String columnName) { @Override public List getBytesList(int columnIndex) { - checkNonNullOfType(columnIndex, Type.array(Type.bytes()), columnIndex); + checkNonNullOfCodes(columnIndex, Collections.singletonList(Code.ARRAY), columnIndex); + checkArrayElementType(columnIndex, Arrays.asList(Code.PROTO, Code.BYTES), columnIndex); return getBytesListInternal(columnIndex); } @Override public List getBytesList(String columnName) { int columnIndex = getColumnIndex(columnName); - checkNonNullOfType(columnIndex, Type.array(Type.bytes()), columnName); + checkNonNullOfCodes(columnIndex, Collections.singletonList(Code.ARRAY), columnName); + checkArrayElementType(columnIndex, Arrays.asList(Code.PROTO, Code.BYTES), columnName); return getBytesListInternal(columnIndex); } + @Override + public List getProtoMessageList(int columnIndex, T message) { + checkNonNullOfCodes(columnIndex, Collections.singletonList(Code.ARRAY), columnIndex); + checkArrayElementType(columnIndex, Arrays.asList(Code.PROTO, Code.BYTES), columnIndex); + return getProtoMessageListInternal(columnIndex, message); + } + + @Override + public List getProtoMessageList(String columnName, T message) { + int columnIndex = getColumnIndex(columnName); + checkNonNullOfCodes(columnIndex, Collections.singletonList(Code.ARRAY), columnName); + checkArrayElementType(columnIndex, Arrays.asList(Code.PROTO, Code.BYTES), columnName); + return getProtoMessageListInternal(columnIndex, message); + } + + @Override + public List getProtoEnumList( + int columnIndex, Function method) { + checkNonNullOfCodes(columnIndex, Collections.singletonList(Code.ARRAY), columnIndex); + checkArrayElementType(columnIndex, Arrays.asList(Code.ENUM, Code.INT64), columnIndex); + return getProtoEnumListInternal(columnIndex, method); + } + + @Override + public List getProtoEnumList( + String columnName, Function method) { + int columnIndex = getColumnIndex(columnName); + checkNonNullOfCodes(columnIndex, Collections.singletonList(Code.ARRAY), columnName); + checkArrayElementType(columnIndex, Arrays.asList(Code.ENUM, Code.INT64), columnName); + return getProtoEnumListInternal(columnIndex, method); + } + @Override public List getTimestampList(int columnIndex) { checkNonNullOfType(columnIndex, Type.array(Type.timestamp()), columnIndex); @@ -477,6 +565,30 @@ private void checkNonNullOfType(int columnIndex, Type expectedType, Object colum checkNonNull(columnIndex, columnNameForError); } + /** Checks if the value at {@code columnIndex} is one of {@code expectedCode} */ + private void checkNonNullOfCodes( + int columnIndex, List expectedCodes, Object columnNameForError) { + Type actualType = getColumnType(columnIndex); + checkState( + expectedCodes.contains(actualType.getCode()), + "Column %s is not of correct type code: expected one of [%s] but was %s", + columnNameForError, + expectedCodes, + actualType); + checkNonNull(columnIndex, columnNameForError); + } + + private void checkArrayElementType( + int columnIndex, List expectedCodes, Object columnNameForError) { + Type arrayElementType = getColumnType(columnIndex).getArrayElementType(); + checkState( + expectedCodes.contains(arrayElementType.getCode()), + "Array element for Column %s is not of correct type code: expected one of [%s] but was %s", + columnNameForError, + expectedCodes, + Type.array(arrayElementType)); + } + private void checkNonNullOfTypes( int columnIndex, List expectedTypes, diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/ForwardingStructReader.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/ForwardingStructReader.java index 2a85006fa95..97c39c00a8d 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/ForwardingStructReader.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/ForwardingStructReader.java @@ -22,8 +22,11 @@ import com.google.common.base.Preconditions; import com.google.common.base.Supplier; import com.google.common.base.Suppliers; +import com.google.protobuf.AbstractMessage; +import com.google.protobuf.ProtocolMessageEnum; import java.math.BigDecimal; import java.util.List; +import java.util.function.Function; /** Forwarding implements of StructReader */ public class ForwardingStructReader implements StructReader { @@ -370,6 +373,32 @@ public List getDateList(String columnName) { return delegate.get().getDateList(columnName); } + @Override + public List getProtoMessageList(int columnIndex, T message) { + checkValidState(); + return delegate.get().getProtoMessageList(columnIndex, message); + } + + @Override + public List getProtoMessageList(String columnName, T message) { + checkValidState(); + return delegate.get().getProtoMessageList(columnName, message); + } + + @Override + public List getProtoEnumList( + int columnIndex, Function method) { + checkValidState(); + return delegate.get().getProtoEnumList(columnIndex, method); + } + + @Override + public List getProtoEnumList( + String columnName, Function method) { + checkValidState(); + return delegate.get().getProtoEnumList(columnName, method); + } + @Override public List getStructList(int columnIndex) { checkValidState(); @@ -382,6 +411,32 @@ public List getStructList(String columnName) { return delegate.get().getStructList(columnName); } + @Override + public T getProtoMessage(int columnIndex, T message) { + checkValidState(); + return delegate.get().getProtoMessage(columnIndex, message); + } + + @Override + public T getProtoMessage(String columnName, T message) { + checkValidState(); + return delegate.get().getProtoMessage(columnName, message); + } + + @Override + public T getProtoEnum( + int columnIndex, Function method) { + checkValidState(); + return delegate.get().getProtoEnum(columnIndex, method); + } + + @Override + public T getProtoEnum( + String columnName, Function method) { + checkValidState(); + return delegate.get().getProtoEnum(columnName, method); + } + @Override public Value getValue(int columnIndex) { checkValidState(); diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Key.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Key.java index 15d4e995bf0..3467052605a 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Key.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Key.java @@ -24,6 +24,7 @@ import com.google.common.base.Joiner; import com.google.protobuf.ListValue; import com.google.protobuf.NullValue; +import com.google.protobuf.ProtocolMessageEnum; import com.google.protobuf.Value; import java.io.Serializable; import java.math.BigDecimal; @@ -141,6 +142,11 @@ public Builder append(@Nullable BigDecimal value) { buffer.add(value); return this; } + /** Appends a {@code ENUM} value to the key. */ + public Builder append(@Nullable ProtocolMessageEnum value) { + buffer.add(value); + return this; + } /** Appends a {@code STRING} value to the key. */ public Builder append(@Nullable String value) { buffer.add(value); @@ -192,6 +198,8 @@ public Builder appendObject(@Nullable Object value) { append((Timestamp) value); } else if (value instanceof Date) { append((Date) value); + } else if (value instanceof ProtocolMessageEnum) { + append((ProtocolMessageEnum) value); } else { throw new IllegalArgumentException( "Unsupported type [" @@ -300,6 +308,10 @@ ListValue toProto() { builder.addValuesBuilder().setStringValue(part.toString()); } else if (part instanceof Date) { builder.addValuesBuilder().setStringValue(part.toString()); + } else if (part instanceof ProtocolMessageEnum) { + builder + .addValuesBuilder() + .setStringValue(Long.toString(((ProtocolMessageEnum) part).getNumber())); } else { throw new AssertionError("Illegal key part: " + part.getClass()); } diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/ResultSets.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/ResultSets.java index fa054ba0cda..d55d4091b9f 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/ResultSets.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/ResultSets.java @@ -29,10 +29,13 @@ import com.google.common.base.Supplier; import com.google.common.collect.Lists; import com.google.common.util.concurrent.ThreadFactoryBuilder; +import com.google.protobuf.AbstractMessage; +import com.google.protobuf.ProtocolMessageEnum; import com.google.spanner.v1.ResultSetMetadata; import com.google.spanner.v1.ResultSetStats; import java.math.BigDecimal; import java.util.List; +import java.util.function.Function; /** Utility methods for working with {@link com.google.cloud.spanner.ResultSet}. */ public final class ResultSets { @@ -300,6 +303,28 @@ public Date getDate(String columnName) { return getCurrentRowAsStruct().getDate(columnName); } + @Override + public T getProtoMessage(int columnIndex, T message) { + return getCurrentRowAsStruct().getProtoMessage(columnIndex, message); + } + + @Override + public T getProtoMessage(String columnName, T message) { + return getCurrentRowAsStruct().getProtoMessage(columnName, message); + } + + @Override + public T getProtoEnum( + int columnIndex, Function method) { + return getCurrentRowAsStruct().getProtoEnum(columnIndex, method); + } + + @Override + public T getProtoEnum( + String columnName, Function method) { + return getCurrentRowAsStruct().getProtoEnum(columnName, method); + } + @Override public Value getValue(int columnIndex) { return getCurrentRowAsStruct().getValue(columnIndex); @@ -440,6 +465,28 @@ public List getDateList(String columnName) { return getCurrentRowAsStruct().getDateList(columnName); } + @Override + public List getProtoMessageList(int columnIndex, T message) { + return getCurrentRowAsStruct().getProtoMessageList(columnIndex, message); + } + + @Override + public List getProtoMessageList(String columnName, T message) { + return getCurrentRowAsStruct().getProtoMessageList(columnName, message); + } + + @Override + public List getProtoEnumList( + int columnIndex, Function method) { + return getCurrentRowAsStruct().getProtoEnumList(columnIndex, method); + } + + @Override + public List getProtoEnumList( + String columnName, Function method) { + return getCurrentRowAsStruct().getProtoEnumList(columnName, method); + } + @Override public List getStructList(int columnIndex) { return getCurrentRowAsStruct().getStructList(columnIndex); diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Struct.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Struct.java index 48c989d145e..40c30148d0e 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Struct.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Struct.java @@ -28,11 +28,14 @@ import com.google.common.primitives.Booleans; import com.google.common.primitives.Doubles; import com.google.common.primitives.Longs; +import com.google.protobuf.AbstractMessage; +import com.google.protobuf.ProtocolMessageEnum; import java.io.Serializable; import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; import java.util.Objects; +import java.util.function.Function; import javax.annotation.concurrent.Immutable; /** @@ -217,6 +220,17 @@ protected Date getDateInternal(int columnIndex) { return values.get(columnIndex).getDate(); } + @Override + protected T getProtoMessageInternal(int columnIndex, T message) { + return values.get(columnIndex).getProtoMessage(message); + } + + @Override + protected T getProtoEnumInternal( + int columnIndex, Function method) { + return values.get(columnIndex).getProtoEnum(method); + } + @Override protected Value getValueInternal(int columnIndex) { return values.get(columnIndex); @@ -287,6 +301,18 @@ protected List getTimestampListInternal(int columnIndex) { return values.get(columnIndex).getTimestampArray(); } + @Override + protected List getProtoMessageListInternal( + int columnIndex, T message) { + return values.get(columnIndex).getProtoMessageArray(message); + } + + @Override + protected List getProtoEnumListInternal( + int columnIndex, Function method) { + return values.get(columnIndex).getProtoEnumArray(method); + } + @Override protected List getDateListInternal(int columnIndex) { return values.get(columnIndex).getDateArray(); @@ -354,6 +380,7 @@ private Object getAsObject(int columnIndex) { case BOOL: return getBooleanInternal(columnIndex); case INT64: + case ENUM: return getLongInternal(columnIndex); case FLOAT64: return getDoubleInternal(columnIndex); @@ -368,6 +395,7 @@ private Object getAsObject(int columnIndex) { case PG_JSONB: return getPgJsonbInternal(columnIndex); case BYTES: + case PROTO: return getBytesInternal(columnIndex); case TIMESTAMP: return getTimestampInternal(columnIndex); @@ -380,6 +408,7 @@ private Object getAsObject(int columnIndex) { case BOOL: return getBooleanListInternal(columnIndex); case INT64: + case ENUM: return getLongListInternal(columnIndex); case FLOAT64: return getDoubleListInternal(columnIndex); @@ -394,6 +423,7 @@ private Object getAsObject(int columnIndex) { case PG_JSONB: return getPgJsonbListInternal(columnIndex); case BYTES: + case PROTO: return getBytesListInternal(columnIndex); case TIMESTAMP: return getTimestampListInternal(columnIndex); diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/StructReader.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/StructReader.java index b767bd6d82c..7108e49ebc2 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/StructReader.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/StructReader.java @@ -19,8 +19,11 @@ import com.google.cloud.ByteArray; import com.google.cloud.Date; import com.google.cloud.Timestamp; +import com.google.protobuf.AbstractMessage; +import com.google.protobuf.ProtocolMessageEnum; import java.math.BigDecimal; import java.util.List; +import java.util.function.Function; /** * A base interface for reading the fields of a {@code STRUCT}. The Cloud Spanner yields {@code @@ -51,6 +54,7 @@ * Struct} is an immutable implementation of {@code StructReader}. */ public interface StructReader { + /** * Returns the type of the underlying data. This will always be a {@code STRUCT} type, with fields * corresponding to the data's columns. For the result of a read or query, this will always match @@ -134,6 +138,60 @@ default String getPgJsonb(String columnName) { throw new UnsupportedOperationException("method should be overwritten"); } + /** + * To get the proto message of generic type {@code T} from Struct. + * + * @param columnIndex Index of the column. + * @param message Proto message object. Message can't be null as it's internally used to find the + * type of proto. Use @code{MyProtoClass.getDefaultInstance()}. @see getDefaultInstance() + * @return The value of a non-{@code NULL} column with type {@link Type#proto(String)} ()}. + */ + default T getProtoMessage(int columnIndex, T message) { + throw new UnsupportedOperationException("method should be overwritten"); + } + + /** + * To get the proto message of type {@code T} from Struct. + * + * @param columnName Name of the column. + * @param message Proto message object. Message can't be null as it's internally used to find the + * type of proto. Use @code{MyProtoClass.getDefaultInstance()}. @see getDefaultInstance() + * @return The value of a non-{@code NULL} column with type {@link Type#proto(String)} ()}. + */ + default T getProtoMessage(String columnName, T message) { + throw new UnsupportedOperationException("method should be overwritten"); + } + + /** + * To get the proto enum of type {@code T} from Struct. + * + * @param columnIndex Index of the column. + * @param method A function that takes enum integer constant as argument and returns the enum. Use + * method @code{forNumber} from generated enum class (eg: MyProtoEnum::forNumber). @see forNumber + * @return The value of a non-{@code NULL} column with type {@link Type#protoEnum(String)} ()}. + */ + default T getProtoEnum( + int columnIndex, Function method) { + throw new UnsupportedOperationException("method should be overwritten"); + } + + /** + * To get the proto enum of type {@code T} from Struct. + * + * @param columnName Name of the column. + * @param method A function that takes enum integer constant as argument and returns the enum. Use + * method @code{forNumber} from generated enum class (eg: MyProtoEnum::forNumber). @see forNumber + * @return The value of a non-{@code NULL} column with type {@link Type#protoEnum(String)} ()}. + */ + default T getProtoEnum( + String columnName, Function method) { + throw new UnsupportedOperationException("method should be overwritten"); + } + /** Returns the value of a non-{@code NULL} column with type {@link Type#bytes()}. */ ByteArray getBytes(int columnIndex); @@ -316,6 +374,64 @@ default List getPgJsonbList(String columnName) { throw new UnsupportedOperationException("method should be overwritten"); }; + /** + * To get the proto message of generic type {@code T} from Struct. + * + * @param columnIndex Index of the column. + * @param message Proto message object. Message can't be null as it's internally used to find the + * type of proto. Use @code{MyProtoClass.getDefaultInstance()}. @see getDefaultInstance() + * @return The value of a non-{@code NULL} column with type {@code + * Type.array(Type.proto(String))}. + */ + default List getProtoMessageList(int columnIndex, T message) { + throw new UnsupportedOperationException("method should be overwritten"); + } + + /** + * To get the proto message of type {@code T} from Struct. + * + * @param columnName Name of the column. + * @param message Proto message object. Message can't be null as it's internally used to find the + * type of proto. Use @code{MyProtoClass.getDefaultInstance()}. @see getDefaultInstance() + * @return The value of a non-{@code NULL} column with type {@code + * Type.array(Type.proto(String))}. + */ + default List getProtoMessageList(String columnName, T message) { + throw new UnsupportedOperationException("method should be overwritten"); + } + + /** + * To get the proto enum of type {@code T} from Struct. + * + * @param columnIndex Index of the column. + * @param method A function that takes enum integer constant as argument and returns the enum. Use + * method @code{forNumber} from generated enum class (eg: MyProtoEnum::forNumber). @see forNumber + * @return The value of a non-{@code NULL} column with type {@code + * Type.array(Type.protoEnum(String))}. + */ + default List getProtoEnumList( + int columnIndex, Function method) { + throw new UnsupportedOperationException("method should be overwritten"); + } + + /** + * To get the proto enum list of type {@code T} from Struct. + * + * @param columnName Name of the column. + * @param method A function that takes enum integer constant as argument and returns the enum. Use + * method @code{forNumber} from generated enum class (eg: MyProtoEnum::forNumber). @see forNumber + * @return The value of a non-{@code NULL} column with type {@code + * Type.array(Type.protoEnum(String))}. + */ + default List getProtoEnumList( + String columnName, Function method) { + throw new UnsupportedOperationException("method should be overwritten"); + } + /** * Returns the value of a non-{@code NULL} column with type {@code Type.array(Type.bytes())}. The * list returned by this method is lazily constructed. Create a copy of it if you intend to access diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Type.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Type.java index 7ba6b9a41e4..e81f0c874ea 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Type.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Type.java @@ -33,6 +33,7 @@ import java.util.Map.Entry; import java.util.Objects; import java.util.TreeMap; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; @@ -122,6 +123,24 @@ public static Type pgJsonb() { return TYPE_PG_JSONB; } + /** + * To get the descriptor for the {@code PROTO} type. + * + * @param protoTypeFqn Proto full name + */ + public static Type proto(String protoTypeFqn) { + return new Type(Code.PROTO, protoTypeFqn); + } + + /** + * To get the descriptor for the {@code ENUM} type. + * + * @param protoTypeFqn Proto ENUM full name + */ + public static Type protoEnum(String protoTypeFqn) { + return new Type(Code.ENUM, protoTypeFqn); + } + /** Returns the descriptor for the {@code BYTES} type: a variable-length byte string. */ public static Type bytes() { return TYPE_BYTES; @@ -193,6 +212,7 @@ public static Type struct(StructField... fields) { private final Code code; private final Type arrayElementType; private final ImmutableList structFields; + private String protoTypeFqn; /** * Map of field name to field index. Ambiguous names are indexed to {@link #AMBIGUOUS_FIELD}. The @@ -209,6 +229,11 @@ private Type( this.structFields = structFields; } + private Type(Code code, @Nonnull String protoTypeFqn) { + this(code, null, null); + this.protoTypeFqn = protoTypeFqn; + } + /** Enumerates the categories of types. */ public enum Code { BOOL(TypeCode.BOOL), @@ -219,6 +244,8 @@ public enum Code { STRING(TypeCode.STRING), JSON(TypeCode.JSON), PG_JSONB(TypeCode.JSON, TypeAnnotationCode.PG_JSONB), + PROTO(TypeCode.PROTO), + ENUM(TypeCode.ENUM), BYTES(TypeCode.BYTES), TIMESTAMP(TypeCode.TIMESTAMP), DATE(TypeCode.DATE), @@ -340,6 +367,17 @@ public List getStructFields() { return structFields; } + /** + * Returns the full package name for elements of this {@code Proto or @code Enum} type. + * + * @throws IllegalStateException if {@code code() != Code.PROTO or code() != Code.ENUM} + */ + public String getProtoTypeFqn() { + Preconditions.checkState( + (code == Code.PROTO || code == Code.ENUM), "Illegal call for non-Proto type"); + return protoTypeFqn; + } + /** * Returns the index of the field named {@code fieldName} in this {@code STRUCT} type. * @@ -416,7 +454,8 @@ public boolean equals(Object o) { Type that = (Type) o; return code == that.code && Objects.equals(arrayElementType, that.arrayElementType) - && Objects.equals(structFields, that.structFields); + && Objects.equals(structFields, that.structFields) + && Objects.equals(protoTypeFqn, that.protoTypeFqn); } @Override @@ -435,7 +474,10 @@ com.google.spanner.v1.Type toProto() { for (StructField field : structFields) { fields.addFieldsBuilder().setName(field.getName()).setType(field.getType().toProto()); } + } else if (code == Code.PROTO || code == Code.ENUM) { + proto.setProtoTypeFqn(protoTypeFqn); } + return proto.build(); } @@ -464,6 +506,10 @@ static Type fromProto(com.google.spanner.v1.Type proto) { return timestamp(); case DATE: return date(); + case PROTO: + return proto(proto.getProtoTypeFqn()); + case ENUM: + return protoEnum(proto.getProtoTypeFqn()); case ARRAY: checkArgument( proto.hasArrayElementType(), diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Value.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Value.java index 82f03e859e1..23ca8f335e2 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Value.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Value.java @@ -24,8 +24,13 @@ import com.google.common.base.Preconditions; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; +import com.google.protobuf.AbstractMessage; +import com.google.protobuf.Descriptors.Descriptor; +import com.google.protobuf.Descriptors.EnumDescriptor; +import com.google.protobuf.InvalidProtocolBufferException; import com.google.protobuf.ListValue; import com.google.protobuf.NullValue; +import com.google.protobuf.ProtocolMessageEnum; import java.io.Serializable; import java.math.BigDecimal; import java.util.ArrayList; @@ -35,6 +40,7 @@ import java.util.Collections; import java.util.List; import java.util.Objects; +import java.util.function.Function; import java.util.stream.Collectors; import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; @@ -218,7 +224,87 @@ public static Value pgJsonb(@Nullable String v) { } /** - * Returns a {@code BYTES} value. + * Return a {@code PROTO} value for not null proto messages. + * + * @param v Not null Proto message. + */ + public static Value protoMessage(AbstractMessage v) { + Preconditions.checkNotNull( + v, "Use protoMessage((ByteArray) null, MyProtoClass.getDescriptor()) for null values."); + return protoMessage( + ByteArray.copyFrom(v.toByteArray()), v.getDescriptorForType().getFullName()); + } + + /** + * Return a {@code PROTO} value + * + * @param v Serialized Proto Array, which may be null. + * @param protoTypeFqn Fully qualified name of proto representing the proto definition. Use static + * method from proto class {@code MyProtoClass.getDescriptor().getFullName()} + */ + public static Value protoMessage(@Nullable ByteArray v, String protoTypeFqn) { + return new ProtoMessageImpl(v == null, v, protoTypeFqn); + } + + /** + * Return a {@code PROTO} value + * + * @param v Serialized Proto Array, which may be null. + * @param descriptor Proto Type Descriptor, use static method from proto class {@code + * MyProtoClass.getDescriptor()}. + */ + public static Value protoMessage(@Nullable ByteArray v, Descriptor descriptor) { + Preconditions.checkNotNull(descriptor, "descriptor can't be null."); + return protoMessage(v, descriptor.getFullName()); + } + + /** + * Return a {@code ENUM} value for not null proto messages. + * + * @param v Proto Enum, which may be null. + */ + public static Value protoEnum(ProtocolMessageEnum v) { + Preconditions.checkNotNull( + v, "Use protoEnum((Long) null, MyProtoEnum.getDescriptor()) for null values."); + return protoEnum(v.getNumber(), v.getDescriptorForType().getFullName()); + } + + /** + * Return a {@code ENUM} value. + * + * @param v Enum non-primitive Integer constant. + * @param protoTypeFqn Fully qualified name of proto representing the enum definition. Use static + * method from proto class {@code MyProtoEnum.getDescriptor().getFullName()} + */ + public static Value protoEnum(@Nullable Long v, String protoTypeFqn) { + return new ProtoEnumImpl(v == null, v, protoTypeFqn); + } + + /** + * Return a {@code ENUM} value. + * + * @param v Enum non-primitive Integer constant. + * @param enumDescriptor Enum Type Descriptor. Use static method from proto class {@code * + * MyProtoEnum.getDescriptor()}. + */ + public static Value protoEnum(@Nullable Long v, EnumDescriptor enumDescriptor) { + Preconditions.checkNotNull(enumDescriptor, "descriptor can't be null."); + return protoEnum(v, enumDescriptor.getFullName()); + } + + /** + * Return a {@code ENUM} value. + * + * @param v Enum integer primitive constant. + * @param protoTypeFqn Fully qualified name of proto representing the enum definition. Use static + * method from proto class {@code MyProtoEnum.getDescriptor().getFullName()} + */ + public static Value protoEnum(long v, String protoTypeFqn) { + return new ProtoEnumImpl(false, v, protoTypeFqn); + } + + /** + * e Returns a {@code BYTES} value. Returns a {@code BYTES} value. * * @param v the value, which may be null */ @@ -421,6 +507,85 @@ public static Value pgJsonbArray(@Nullable Iterable v) { return new PgJsonbArrayImpl(v == null, v == null ? null : immutableCopyOf(v)); } + /** + * Returns an {@code ARRAY} value. + * + * @param v the source of element values. This may be {@code null} to produce a value for which + * {@code isNull()} is {@code true}. Individual elements may also be {@code null}. + * @param descriptor Proto Type Descriptor, use static method from proto class {@code + * MyProtoClass.getDescriptor()}. + */ + public static Value protoMessageArray( + @Nullable Iterable v, Descriptor descriptor) { + if (v == null) { + return new ProtoMessageArrayImpl(true, null, descriptor.getFullName()); + } + + List serializedArray = new ArrayList<>(); + v.forEach( + (message) -> { + if (message != null) { + serializedArray.add(ByteArray.copyFrom(message.toByteArray())); + } else { + serializedArray.add(null); + } + }); + + return new ProtoMessageArrayImpl(false, serializedArray, descriptor.getFullName()); + } + + /** + * Returns an {@code ARRAY} value. + * + * @param v the source of element values. This may be {@code null} to produce a value for which + * {@code isNull()} is {@code true}. Individual elements may also be {@code null}. + * @param protoTypeFqn Fully qualified name of proto representing the proto definition. Use static + * method from proto class {@code MyProtoClass.getDescriptor().getFullName()} + */ + public static Value protoMessageArray(@Nullable Iterable v, String protoTypeFqn) { + return new ProtoMessageArrayImpl( + v == null, v != null ? immutableCopyOf(v) : null, protoTypeFqn); + } + + /** + * Returns an {@code ARRAY} value. + * + * @param v the source of element values. This may be {@code null} to produce a value for which + * {@code isNull()} is {@code true}. Individual elements may also be {@code null}. + * @param descriptor Proto Type Descriptor, use static method from proto class {@code + * MyProtoClass.getDescriptor()}. + */ + public static Value protoEnumArray( + @Nullable Iterable v, EnumDescriptor descriptor) { + if (v == null) { + return new ProtoEnumArrayImpl(true, null, descriptor.getFullName()); + } + + List enumConstValues = new ArrayList<>(); + v.forEach( + (protoEnum) -> { + if (protoEnum != null) { + enumConstValues.add((long) protoEnum.getNumber()); + } else { + enumConstValues.add(null); + } + }); + + return new ProtoEnumArrayImpl(false, enumConstValues, descriptor.getFullName()); + } + + /** + * Returns an {@code ARRAY} value. + * + * @param v the source of element values. This may be {@code null} to produce a value for which + * {@code isNull()} is {@code true}. Individual elements may also be {@code null}. + * @param protoTypeFqn Fully qualified name of proto representing the enum definition. Use static + * method from proto class {@code MyProtoEnum.getDescriptor().getFullName()} + */ + public static Value protoEnumArray(@Nullable Iterable v, String protoTypeFqn) { + return new ProtoEnumArrayImpl(v == null, v != null ? immutableCopyOf(v) : null, protoTypeFqn); + } + /** * Returns an {@code ARRAY} value. * @@ -541,6 +706,25 @@ public String getPgJsonb() { throw new UnsupportedOperationException("Not implemented"); } + /** + * Returns the value of a {@code PROTO}-typed instance. + * + * @throws IllegalStateException if {@code isNull()} or the value is not of the expected type + */ + public T getProtoMessage(T m) { + throw new UnsupportedOperationException("Not implemented"); + } + + /** + * Returns the value of a {@code ENUM}-typed instance. + * + * @throws IllegalStateException if {@code isNull()} or the value is not of the expected type + */ + public T getProtoEnum( + Function method) { + throw new UnsupportedOperationException("Not implemented"); + } + /** * Returns the value of a {@code BYTES}-typed instance. * @@ -633,6 +817,27 @@ public List getPgJsonbArray() { throw new UnsupportedOperationException("Not implemented"); } + /** + * Returns the value of an {@code ARRAY}-typed instance. While the returned list itself + * will never be {@code null}, elements of that list may be null. + * + * @throws IllegalStateException if {@code isNull()} or the value is not of the expected type + */ + public List getProtoMessageArray(T m) { + throw new UnsupportedOperationException("Not implemented"); + } + + /** + * Returns the value of an {@code ARRAY}-typed instance. While the returned list itself will + * never be {@code null}, elements of that list may be null. + * + * @throws IllegalStateException if {@code isNull()} or the value is not of the expected type + */ + public List getProtoEnumArray( + Function method) { + throw new UnsupportedOperationException("Not implemented"); + } + /** * Returns the value of an {@code ARRAY}-typed instance. While the returned list itself * will never be {@code null}, elements of that list may be null. @@ -1123,6 +1328,15 @@ public long getInt64() { return value; } + @Override + public T getProtoEnum( + Function method) { + Preconditions.checkNotNull( + method, "Method may not be null. Use 'MyProtoEnum::forNumber' as a parameter value."); + checkNotNull(); + return (T) method.apply((int) value); + } + @Override com.google.protobuf.Value valueToProto() { return com.google.protobuf.Value.newBuilder().setStringValue(Long.toString(value)).build(); @@ -1310,6 +1524,19 @@ public ByteArray getBytes() { return value; } + @Override + public T getProtoMessage(T m) { + Preconditions.checkNotNull( + m, + "Proto message may not be null. Use MyProtoClass.getDefaultInstance() as a parameter value."); + checkNotNull(); + try { + return (T) m.toBuilder().mergeFrom(value.toByteArray()).build(); + } catch (InvalidProtocolBufferException e) { + throw SpannerExceptionFactory.asSpannerException(e); + } + } + @Override com.google.protobuf.Value valueToProto() { return com.google.protobuf.Value.newBuilder().setStringValue(value.toBase64()).build(); @@ -1321,6 +1548,75 @@ void valueToString(StringBuilder b) { } } + private static class ProtoMessageImpl extends AbstractObjectValue { + + private ProtoMessageImpl(boolean isNull, ByteArray serializedProtoArray, String protoTypeFqn) { + super(isNull, Type.proto(protoTypeFqn), serializedProtoArray); + } + + @Override + public ByteArray getBytes() { + checkNotNull(); + return value; + } + + @Override + public T getProtoMessage(T m) { + Preconditions.checkNotNull( + m, + "Proto message may not be null. Use MyProtoClass.getDefaultInstance() as a parameter value."); + checkNotNull(); + try { + return (T) m.toBuilder().mergeFrom(value.toByteArray()).build(); + } catch (InvalidProtocolBufferException e) { + throw SpannerExceptionFactory.asSpannerException(e); + } + } + + @Override + com.google.protobuf.Value valueToProto() { + String base64EncodedString = value.toBase64(); + return com.google.protobuf.Value.newBuilder().setStringValue(base64EncodedString).build(); + } + + @Override + void valueToString(StringBuilder b) { + b.append(value.toString()); + } + } + + private static class ProtoEnumImpl extends AbstractObjectValue { + + private ProtoEnumImpl(boolean isNull, Long enumValue, String protoTypeFqn) { + super(isNull, Type.protoEnum(protoTypeFqn), enumValue); + } + + @Override + public long getInt64() { + checkNotNull(); + return value; + } + + @Override + public T getProtoEnum( + Function method) { + Preconditions.checkNotNull( + method, "Method may not be null. Use 'MyProtoEnum::forNumber' as a parameter value."); + checkNotNull(); + return (T) method.apply(value.intValue()); + } + + @Override + void valueToString(StringBuilder b) { + b.append(value.toString()); + } + + @Override + com.google.protobuf.Value valueToProto() { + return com.google.protobuf.Value.newBuilder().setStringValue(Long.toString(value)).build(); + } + } + private static class TimestampImpl extends AbstractObjectValue { private static final String COMMIT_TIMESTAMP_STRING = "spanner.commit_timestamp()"; @@ -1573,6 +1869,24 @@ public List getInt64Array() { return getArray(); } + @Override + public List getProtoEnumArray( + Function method) { + Preconditions.checkNotNull( + method, "Method may not be null. Use 'MyProtoEnum::forNumber' as a parameter value."); + checkNotNull(); + + List protoEnumList = new ArrayList<>(); + for (Long enumIntValue : values) { + if (enumIntValue == null) { + protoEnumList.add(null); + } else { + protoEnumList.add((T) method.apply(enumIntValue.intValue())); + } + } + return protoEnumList; + } + @Override boolean valueEquals(Value v) { Int64ArrayImpl that = (Int64ArrayImpl) v; @@ -1760,6 +2074,28 @@ public List getBytesArray() { return value; } + @Override + public List getProtoMessageArray(T m) { + Preconditions.checkNotNull( + m, + "Proto message may not be null. Use MyProtoClass.getDefaultInstance() as a parameter value."); + checkNotNull(); + try { + List protoMessagesList = new ArrayList<>(value.size()); + for (ByteArray protoMessageBytes : value) { + if (protoMessageBytes == null) { + protoMessagesList.add(null); + } else { + protoMessagesList.add( + (T) m.toBuilder().mergeFrom(protoMessageBytes.toByteArray()).build()); + } + } + return protoMessagesList; + } catch (InvalidProtocolBufferException e) { + throw SpannerExceptionFactory.asSpannerException(e); + } + } + @Override String elementToString(ByteArray element) { return element.toBase64(); @@ -1789,6 +2125,91 @@ void appendElement(StringBuilder b, Timestamp element) { } } + private static class ProtoMessageArrayImpl extends AbstractArrayValue { + + private ProtoMessageArrayImpl( + boolean isNull, @Nullable List values, String protoTypeFqn) { + super(isNull, Type.proto(protoTypeFqn), values); + } + + @Override + public List getBytesArray() { + return value; + } + + @Override + public List getProtoMessageArray(T m) { + Preconditions.checkNotNull( + m, + "Proto message may not be null. Use MyProtoClass.getDefaultInstance() as a parameter value."); + checkNotNull(); + try { + List protoMessagesList = new ArrayList<>(value.size()); + for (ByteArray protoMessageBytes : value) { + if (protoMessageBytes == null) { + protoMessagesList.add(null); + } else { + protoMessagesList.add( + (T) m.toBuilder().mergeFrom(protoMessageBytes.toByteArray()).build()); + } + } + return protoMessagesList; + } catch (InvalidProtocolBufferException e) { + throw SpannerExceptionFactory.asSpannerException(e); + } + } + + @Override + String elementToString(ByteArray element) { + return element.toBase64(); + } + + @Override + void appendElement(StringBuilder b, ByteArray element) { + b.append(element.toString()); + } + } + + private static class ProtoEnumArrayImpl extends AbstractArrayValue { + + private ProtoEnumArrayImpl(boolean isNull, @Nullable List values, String protoTypeFqn) { + super(isNull, Type.protoEnum(protoTypeFqn), values); + } + + @Override + public List getInt64Array() { + return value; + } + + @Override + public List getProtoEnumArray( + Function method) { + Preconditions.checkNotNull( + method, "Method may not be null. Use 'MyProtoEnum::forNumber' as a parameter value."); + checkNotNull(); + + List protoEnumList = new ArrayList<>(); + for (Long enumIntValue : value) { + if (enumIntValue == null) { + protoEnumList.add(null); + } else { + protoEnumList.add((T) method.apply(enumIntValue.intValue())); + } + } + return protoEnumList; + } + + @Override + String elementToString(Long element) { + return Long.toString(element); + } + + @Override + void appendElement(StringBuilder b, Long element) { + b.append(element); + } + } + private static class DateArrayImpl extends AbstractArrayValue { private DateArrayImpl(boolean isNull, @Nullable List values) { @@ -1946,6 +2367,10 @@ private Value getValue(int fieldIndex) { return Value.date(value.getDate(fieldIndex)); case TIMESTAMP: return Value.timestamp(value.getTimestamp(fieldIndex)); + case PROTO: + return Value.protoMessage(value.getBytes(fieldIndex), fieldType.getProtoTypeFqn()); + case ENUM: + return Value.protoEnum(value.getLong(fieldIndex), fieldType.getProtoTypeFqn()); case STRUCT: return Value.struct(value.getStruct(fieldIndex)); case ARRAY: @@ -1955,6 +2380,7 @@ private Value getValue(int fieldIndex) { case BOOL: return Value.boolArray(value.getBooleanList(fieldIndex)); case INT64: + case ENUM: return Value.int64Array(value.getLongList(fieldIndex)); case STRING: return Value.stringArray(value.getStringList(fieldIndex)); @@ -1963,6 +2389,7 @@ private Value getValue(int fieldIndex) { case PG_JSONB: return Value.pgJsonbArray(value.getPgJsonbList(fieldIndex)); case BYTES: + case PROTO: return Value.bytesArray(value.getBytesList(fieldIndex)); case FLOAT64: return Value.float64Array(value.getDoubleList(fieldIndex)); diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/ValueBinder.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/ValueBinder.java index ec9e5a43d8f..cdb1fd10b51 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/ValueBinder.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/ValueBinder.java @@ -19,6 +19,10 @@ import com.google.cloud.ByteArray; import com.google.cloud.Date; import com.google.cloud.Timestamp; +import com.google.protobuf.AbstractMessage; +import com.google.protobuf.Descriptors.Descriptor; +import com.google.protobuf.Descriptors.EnumDescriptor; +import com.google.protobuf.ProtocolMessageEnum; import java.math.BigDecimal; import javax.annotation.Nullable; @@ -95,6 +99,41 @@ public R to(@Nullable String value) { return handle(Value.string(value)); } + /** Binds to {@code Value.protoMessage(value)} */ + public R to(AbstractMessage m) { + return handle(Value.protoMessage(m)); + } + + /** Binds to {@code Value.protoMessage(value, protoType)} */ + public R to(@Nullable ByteArray v, String protoTypFqn) { + return handle(Value.protoMessage(v, protoTypFqn)); + } + + /** Binds to {@code Value.protoMessage(value, descriptor)} */ + public R to(@Nullable ByteArray v, Descriptor descriptor) { + return handle(Value.protoMessage(v, descriptor)); + } + + /** Binds to {@code Value.protoEnum(value)} */ + public R to(ProtocolMessageEnum value) { + return handle(Value.protoEnum(value)); + } + + /** Binds to {@code Value.protoEnum(value, protoType)} */ + public R to(@Nullable Long v, String protoTypFqn) { + return handle(Value.protoEnum(v, protoTypFqn)); + } + + /** Binds to {@code Value.protoEnum(value, enumDescriptor)} */ + public R to(@Nullable Long v, EnumDescriptor enumDescriptor) { + return handle(Value.protoEnum(v, enumDescriptor)); + } + + /** Binds to {@code Value.protoEnum(value, protoType)} */ + public R to(long v, String protoTypFqn) { + return handle(Value.protoEnum(v, protoTypFqn)); + } + /** Binds to {@code Value.bytes(value)} */ public R to(@Nullable ByteArray value) { return handle(Value.bytes(value)); @@ -203,6 +242,27 @@ public R toTimestampArray(@Nullable Iterable values) { return handle(Value.timestampArray(values)); } + /** Binds to {@code Value.protoMessageArray(values, descriptor)} */ + public R toProtoMessageArray(@Nullable Iterable values, Descriptor descriptor) { + return handle(Value.protoMessageArray(values, descriptor)); + } + + /** Binds to {@code Value.protoMessageArray(values, protoTypeFq)} */ + public R toProtoMessageArray(@Nullable Iterable values, String protoTypeFq) { + return handle(Value.protoMessageArray(values, protoTypeFq)); + } + + /** Binds to {@code Value.protoEnumArray(values, descriptor)} */ + public R toProtoEnumArray( + @Nullable Iterable values, EnumDescriptor descriptor) { + return handle(Value.protoEnumArray(values, descriptor)); + } + + /** Binds to {@code Value.protoEnumArray(values, protoTypeFq)} */ + public R toProtoEnumArray(@Nullable Iterable values, String protoTypeFq) { + return handle(Value.protoEnumArray(values, protoTypeFq)); + } + /** Binds to {@code Value.dateArray(values)} */ public R toDateArray(@Nullable Iterable values) { return handle(Value.dateArray(values)); diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ChecksumResultSet.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ChecksumResultSet.java index bb2f2fb817a..24389546669 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ChecksumResultSet.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ChecksumResultSet.java @@ -225,6 +225,7 @@ public void funnel(Struct row, PrimitiveSink into) { funnelValue(type, row.getBoolean(i), into); break; case BYTES: + case PROTO: funnelValue(type, row.getBytes(i), into); break; case DATE: @@ -240,6 +241,7 @@ public void funnel(Struct row, PrimitiveSink into) { funnelValue(type, row.getString(i), into); break; case INT64: + case ENUM: funnelValue(type, row.getLong(i), into); break; case STRING: @@ -274,6 +276,7 @@ private void funnelArray( } break; case BYTES: + case PROTO: into.putInt(row.getBytesList(columnIndex).size()); for (ByteArray value : row.getBytesList(columnIndex)) { funnelValue(Code.BYTES, value, into); @@ -304,6 +307,7 @@ private void funnelArray( } break; case INT64: + case ENUM: into.putInt(row.getLongList(columnIndex).size()); for (Long value : row.getLongList(columnIndex)) { funnelValue(Code.INT64, value, into); @@ -357,6 +361,7 @@ private void funnelValue(Code type, T value, PrimitiveSink into) { into.putBoolean((Boolean) value); break; case BYTES: + case PROTO: ByteArray byteArray = (ByteArray) value; into.putInt(byteArray.length()); into.putBytes(byteArray.toByteArray()); @@ -374,6 +379,7 @@ private void funnelValue(Code type, T value, PrimitiveSink into) { into.putUnencodedChars(stringRepresentation); break; case INT64: + case ENUM: into.putLong((Long) value); break; case PG_NUMERIC: diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/DirectExecuteResultSet.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/DirectExecuteResultSet.java index 8690e154f4e..dff915e2cce 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/DirectExecuteResultSet.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/DirectExecuteResultSet.java @@ -25,10 +25,13 @@ import com.google.cloud.spanner.Type; import com.google.cloud.spanner.Value; import com.google.common.base.Preconditions; +import com.google.protobuf.AbstractMessage; +import com.google.protobuf.ProtocolMessageEnum; import com.google.spanner.v1.ResultSetMetadata; import com.google.spanner.v1.ResultSetStats; import java.math.BigDecimal; import java.util.List; +import java.util.function.Function; /** * {@link ResultSet} implementation used by the Spanner connection API to ensure that the query for @@ -425,6 +428,32 @@ public List getDateList(String columnName) { return delegate.getDateList(columnName); } + @Override + public List getProtoMessageList(int columnIndex, T message) { + Preconditions.checkState(nextCalledByClient, MISSING_NEXT_CALL); + return delegate.getProtoMessageList(columnIndex, message); + } + + @Override + public List getProtoMessageList(String columnName, T message) { + Preconditions.checkState(nextCalledByClient, MISSING_NEXT_CALL); + return delegate.getProtoMessageList(columnName, message); + } + + @Override + public List getProtoEnumList( + int columnIndex, Function method) { + Preconditions.checkState(nextCalledByClient, MISSING_NEXT_CALL); + return delegate.getProtoEnumList(columnIndex, method); + } + + @Override + public List getProtoEnumList( + String columnName, Function method) { + Preconditions.checkState(nextCalledByClient, MISSING_NEXT_CALL); + return delegate.getProtoEnumList(columnName, method); + } + @Override public List getStructList(int columnIndex) { Preconditions.checkState(nextCalledByClient, MISSING_NEXT_CALL); @@ -437,6 +466,32 @@ public List getStructList(String columnName) { return delegate.getStructList(columnName); } + @Override + public T getProtoEnum( + int columnIndex, Function method) { + Preconditions.checkState(nextCalledByClient, MISSING_NEXT_CALL); + return delegate.getProtoEnum(columnIndex, method); + } + + @Override + public T getProtoEnum( + String columnName, Function method) { + Preconditions.checkState(nextCalledByClient, MISSING_NEXT_CALL); + return delegate.getProtoEnum(columnName, method); + } + + @Override + public T getProtoMessage(int columnIndex, T message) { + Preconditions.checkState(nextCalledByClient, MISSING_NEXT_CALL); + return delegate.getProtoMessage(columnIndex, message); + } + + @Override + public T getProtoMessage(String columnName, T message) { + Preconditions.checkState(nextCalledByClient, MISSING_NEXT_CALL); + return delegate.getProtoMessage(columnName, message); + } + @Override public boolean equals(Object o) { if (!(o instanceof DirectExecuteResultSet)) { diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ReplaceableForwardingResultSet.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ReplaceableForwardingResultSet.java index 07e755b2b25..7370551a46f 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ReplaceableForwardingResultSet.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ReplaceableForwardingResultSet.java @@ -27,10 +27,13 @@ import com.google.cloud.spanner.Type; import com.google.cloud.spanner.Value; import com.google.common.base.Preconditions; +import com.google.protobuf.AbstractMessage; +import com.google.protobuf.ProtocolMessageEnum; import com.google.spanner.v1.ResultSetMetadata; import com.google.spanner.v1.ResultSetStats; import java.math.BigDecimal; import java.util.List; +import java.util.function.Function; /** * Forwarding implementation of {@link ResultSet} that forwards all calls to a delegate that can be @@ -430,6 +433,32 @@ public List getDateList(String columnName) { return delegate.getDateList(columnName); } + @Override + public List getProtoMessageList(int columnIndex, T message) { + checkClosed(); + return delegate.getProtoMessageList(columnIndex, message); + } + + @Override + public List getProtoMessageList(String columnName, T message) { + checkClosed(); + return delegate.getProtoMessageList(columnName, message); + } + + @Override + public List getProtoEnumList( + int columnIndex, Function method) { + checkClosed(); + return delegate.getProtoEnumList(columnIndex, method); + } + + @Override + public List getProtoEnumList( + String columnName, Function method) { + checkClosed(); + return delegate.getProtoEnumList(columnName, method); + } + @Override public List getStructList(int columnIndex) { checkClosed(); @@ -441,4 +470,30 @@ public List getStructList(String columnName) { checkClosed(); return delegate.getStructList(columnName); } + + @Override + public T getProtoMessage(int columnIndex, T message) { + checkClosed(); + return delegate.getProtoMessage(columnIndex, message); + } + + @Override + public T getProtoMessage(String columnName, T message) { + checkClosed(); + return delegate.getProtoMessage(columnName, message); + } + + @Override + public T getProtoEnum( + int columnIndex, Function method) { + checkClosed(); + return delegate.getProtoEnum(columnIndex, method); + } + + @Override + public T getProtoEnum( + String columnName, Function method) { + checkClosed(); + return delegate.getProtoEnum(columnName, method); + } } diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/AbstractStructReaderTypesTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/AbstractStructReaderTypesTest.java index 1b6280a6369..4fc3c67ceba 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/AbstractStructReaderTypesTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/AbstractStructReaderTypesTest.java @@ -27,6 +27,8 @@ import com.google.cloud.Date; import com.google.cloud.Timestamp; import com.google.common.base.Throwables; +import com.google.protobuf.AbstractMessage; +import com.google.protobuf.ProtocolMessageEnum; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.math.BigDecimal; @@ -34,6 +36,7 @@ import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.function.Function; import javax.annotation.Nullable; import org.junit.Before; import org.junit.Test; @@ -95,6 +98,17 @@ protected Date getDateInternal(int columnIndex) { return null; } + @Override + protected T getProtoMessageInternal(int columnIndex, T message) { + return null; + } + + @Override + protected T getProtoEnumInternal( + int columnIndex, Function method) { + return null; + } + @Override protected Value getValueInternal(int columnIndex) { return null; @@ -160,6 +174,18 @@ protected List getTimestampListInternal(int columnIndex) { return null; } + @Override + protected List getProtoMessageListInternal( + int columnIndex, T message) { + return null; + } + + @Override + protected List getProtoEnumListInternal( + int columnIndex, Function method) { + return null; + } + @Override protected List getDateListInternal(int columnIndex) { return null; diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/GrpcResultSetTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/GrpcResultSetTest.java index ff4e92a5215..dba2d2d1136 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/GrpcResultSetTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/GrpcResultSetTest.java @@ -25,6 +25,8 @@ import com.google.cloud.ByteArray; import com.google.cloud.Date; import com.google.cloud.Timestamp; +import com.google.cloud.spanner.SingerProto.Genre; +import com.google.cloud.spanner.SingerProto.SingerInfo; import com.google.cloud.spanner.spi.v1.SpannerRpc; import com.google.common.base.Function; import com.google.common.base.Strings; @@ -735,6 +737,68 @@ public void getPgJsonb() { assertEquals("[]", resultSet.getPgJsonb(0)); } + @Test + public void getProtoMessage() { + SingerInfo singerInfo1 = + SingerInfo.newBuilder() + .setSingerId(111) + .setNationality("COUNTRY1") + .setGenre(Genre.FOLK) + .build(); + SingerInfo singerInfo2 = SingerInfo.newBuilder().setSingerId(222).setGenre(Genre.JAZZ).build(); + String singerInfoFullName = SingerInfo.getDescriptor().getFullName(); + + consumer.onPartialResultSet( + PartialResultSet.newBuilder() + .setMetadata( + makeMetadata(Type.struct(Type.StructField.of("f", Type.proto(singerInfoFullName))))) + .addValues(Value.protoMessage(singerInfo1).toProto()) + .addValues( + Value.protoMessage( + ByteArray.copyFrom(singerInfo2.toByteArray()), singerInfoFullName) + .toProto()) + .addValues(Value.protoMessage(null, SingerInfo.getDescriptor().getFullName()).toProto()) + .build()); + consumer.onCompleted(); + + assertTrue(resultSet.next()); + assertEquals(singerInfo1, resultSet.getProtoMessage(0, SingerInfo.getDefaultInstance())); + assertTrue(resultSet.next()); + assertEquals(singerInfo2, resultSet.getProtoMessage(0, SingerInfo.getDefaultInstance())); + assertTrue(resultSet.next()); + assertThrows( + NullPointerException.class, + () -> { + resultSet.getProtoMessage(0, SingerInfo.getDefaultInstance()); + }); + } + + @Test + public void getProtoEnum() { + String genreFullyQualifiedName = Genre.getDescriptor().getFullName(); + consumer.onPartialResultSet( + PartialResultSet.newBuilder() + .setMetadata( + makeMetadata( + Type.struct(Type.StructField.of("f", Type.protoEnum(genreFullyQualifiedName))))) + .addValues(Value.protoEnum(Genre.FOLK).toProto()) + .addValues(Value.protoEnum(Genre.JAZZ.getNumber(), genreFullyQualifiedName).toProto()) + .addValues(Value.protoEnum(null, genreFullyQualifiedName).toProto()) + .build()); + consumer.onCompleted(); + + assertTrue(resultSet.next()); + assertEquals(Genre.FOLK, resultSet.getProtoEnum(0, Genre::forNumber)); + assertTrue(resultSet.next()); + assertEquals(Genre.JAZZ, resultSet.getProtoEnum(0, Genre::forNumber)); + assertTrue(resultSet.next()); + assertThrows( + NullPointerException.class, + () -> { + resultSet.getProtoEnum(0, Genre::forNumber); + }); + } + @Test public void getBooleanArray() { boolean[] boolArray = {true, true, false}; @@ -876,4 +940,75 @@ public void getPgJsonbList() { assertTrue(resultSet.next()); assertEquals(jsonList, resultSet.getPgJsonbList(0)); } + + @Test + public void getProtoMessageList() { + SingerInfo singerInfo1 = + SingerInfo.newBuilder() + .setSingerId(111) + .setNationality("COUNTRY1") + .setGenre(Genre.FOLK) + .build(); + SingerInfo singerInfo2 = SingerInfo.newBuilder().setSingerId(222).setGenre(Genre.JAZZ).build(); + String singerInfoFullName = SingerInfo.getDescriptor().getFullName(); + + consumer.onPartialResultSet( + PartialResultSet.newBuilder() + .setMetadata( + makeMetadata( + Type.struct( + Type.StructField.of("f", Type.array(Type.proto(singerInfoFullName)))))) + .addValues( + Value.protoMessageArray( + Arrays.asList(singerInfo1, singerInfo2), SingerInfo.getDescriptor()) + .toProto()) + .addValues( + Value.protoMessageArray( + Arrays.asList(singerInfo2, null, singerInfo1), SingerInfo.getDescriptor()) + .toProto()) + .addValues(Value.protoMessageArray(null, SingerInfo.getDescriptor()).toProto()) + .build()); + consumer.onCompleted(); + + assertTrue(resultSet.next()); + assertEquals( + Arrays.asList(singerInfo1, singerInfo2), + resultSet.getProtoMessageList(0, SingerInfo.getDefaultInstance())); + assertTrue(resultSet.next()); + assertEquals( + Arrays.asList(singerInfo2, null, singerInfo1), + resultSet.getProtoMessageList(0, SingerInfo.getDefaultInstance())); + assertTrue(resultSet.next()); + assertThrows( + NullPointerException.class, + () -> { + resultSet.getProtoMessageList(0, SingerInfo.getDefaultInstance()); + }); + } + + @Test + public void getProtoEnumList() { + String genreFullyQualifiedName = Genre.getDescriptor().getFullName(); + consumer.onPartialResultSet( + PartialResultSet.newBuilder() + .setMetadata( + makeMetadata( + Type.struct(Type.StructField.of("f", Type.protoEnum(genreFullyQualifiedName))))) + .addValues(Value.protoEnum(Genre.FOLK).toProto()) + .addValues(Value.protoEnum(Genre.JAZZ.getNumber(), genreFullyQualifiedName).toProto()) + .addValues(Value.protoEnum(null, genreFullyQualifiedName).toProto()) + .build()); + consumer.onCompleted(); + + assertTrue(resultSet.next()); + assertEquals(Genre.FOLK, resultSet.getProtoEnum(0, Genre::forNumber)); + assertTrue(resultSet.next()); + assertEquals(Genre.JAZZ, resultSet.getProtoEnum(0, Genre::forNumber)); + assertTrue(resultSet.next()); + assertThrows( + NullPointerException.class, + () -> { + resultSet.getProtoEnum(0, Genre::forNumber); + }); + } } diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MutationTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MutationTest.java index fe2b7aec94b..f38b5e47b8d 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MutationTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MutationTest.java @@ -23,6 +23,8 @@ import com.google.cloud.ByteArray; import com.google.cloud.Date; import com.google.cloud.Timestamp; +import com.google.cloud.spanner.SingerProto.Genre; +import com.google.cloud.spanner.SingerProto.SingerInfo; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.testing.EqualsTester; @@ -545,6 +547,14 @@ private Mutation.WriteBuilder appendAllTypes(Mutation.WriteBuilder builder) { .to(Value.json("{\"key\": \"value\"}}")) .set("jsonNull") .to(Value.json(null)) + .set("protoMessage") + .to(SingerInfo.newBuilder().setSingerId(232).setGenre(Genre.POP).build()) + .set("protoMessageNull") + .to(Value.protoMessage(null, SingerInfo.getDescriptor().getFullName())) + .set("protoEnum") + .to(Genre.JAZZ) + .set("protoEnumNull") + .to(Value.protoEnum(null, SingerInfo.getDescriptor().getFullName())) .set("pgJsonb") .to(Value.pgJsonb("{\"key\": \"value\"}}")) .set("pgJsonbNull") @@ -603,6 +613,24 @@ private Mutation.WriteBuilder appendAllTypes(Mutation.WriteBuilder builder) { .toJsonArray(null) .set("jsonArrValue") .to(Value.jsonArray(ImmutableList.of("{\"key\": \"value1\"}}", "{\"key\": \"value2\"}"))) + .set("protoMessageArr") + .toProtoMessageArray( + ImmutableList.of(SingerInfo.newBuilder().setSingerId(232).setGenre(Genre.POP).build()), + SingerInfo.getDescriptor()) + .set("protoMessageArrNull") + .toProtoMessageArray(null, SingerInfo.getDescriptor()) + .set("protoMessageArrValue") + .to( + Value.protoMessageArray( + ImmutableList.of( + SingerInfo.newBuilder().setSingerId(232).setGenre(Genre.POP).build()), + SingerInfo.getDescriptor())) + .set("protoEnumArr") + .toProtoEnumArray(ImmutableList.of(Genre.JAZZ), Genre.getDescriptor()) + .set("protoEnumArrNull") + .toProtoEnumArray(null, Genre.getDescriptor()) + .set("protoEnumArrValue") + .to(Value.protoEnumArray(ImmutableList.of(Genre.JAZZ), Genre.getDescriptor())) .set("pgJsonbArr") .toPgJsonbArray(ImmutableList.of("{\"key\": \"value1\"}}", "{\"key\": \"value2\"}")) .set("pgJsonbArrNull") diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/ResultSetsTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/ResultSetsTest.java index 87be602808c..8e1f257594b 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/ResultSetsTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/ResultSetsTest.java @@ -28,9 +28,13 @@ import com.google.cloud.Date; import com.google.cloud.Timestamp; import com.google.cloud.spanner.AsyncResultSet.CallbackResponse; +import com.google.cloud.spanner.SingerProto.Genre; +import com.google.cloud.spanner.SingerProto.SingerInfo; import com.google.common.primitives.Doubles; import com.google.common.primitives.Longs; import com.google.common.util.concurrent.MoreExecutors; +import com.google.protobuf.AbstractMessage; +import com.google.protobuf.ProtocolMessageEnum; import java.math.BigDecimal; import java.util.Arrays; import java.util.Collections; @@ -52,6 +56,13 @@ public void resultSetIteration() { BigDecimal bigDecimalVal = BigDecimal.valueOf(123, 2); String stringVal = "stringVal"; String jsonVal = "{\"color\":\"red\",\"value\":\"#f00\"}"; + SingerInfo protoMessageVal = + SingerInfo.newBuilder() + .setSingerId(111) + .setNationality("COUNTRY1") + .setGenre(Genre.FOLK) + .build(); + ProtocolMessageEnum protoEnumVal = Genre.ROCK; String byteVal = "101"; long usecs = 32343; int year = 2018; @@ -80,6 +91,10 @@ public void resultSetIteration() { }; String[] stringArray = {"abc", "def", "ghi"}; String[] jsonArray = {"{}", "{\"color\":\"red\",\"value\":\"#f00\"}", "[]"}; + AbstractMessage[] protoMessageArray = { + protoMessageVal, SingerInfo.newBuilder().setSingerId(1).build() + }; + ProtocolMessageEnum[] protoEnumArray = {protoEnumVal, Genre.JAZZ}; Type type = Type.struct( @@ -94,6 +109,10 @@ public void resultSetIteration() { Type.StructField.of("byteVal", Type.bytes()), Type.StructField.of("timestamp", Type.timestamp()), Type.StructField.of("date", Type.date()), + Type.StructField.of( + "protoMessage", Type.proto(protoMessageVal.getDescriptorForType().getFullName())), + Type.StructField.of( + "protoEnum", Type.protoEnum(protoEnumVal.getDescriptorForType().getFullName())), Type.StructField.of("boolArray", Type.array(Type.bool())), Type.StructField.of("longArray", Type.array(Type.int64())), Type.StructField.of("doubleArray", Type.array(Type.float64())), @@ -103,7 +122,12 @@ public void resultSetIteration() { Type.StructField.of("dateArray", Type.array(Type.date())), Type.StructField.of("stringArray", Type.array(Type.string())), Type.StructField.of("jsonArray", Type.array(Type.json())), - Type.StructField.of("pgJsonbArray", Type.array(Type.pgJsonb()))); + Type.StructField.of("pgJsonbArray", Type.array(Type.pgJsonb())), + Type.StructField.of( + "protoMessageArray", + Type.array(Type.proto(SingerInfo.getDescriptor().getFullName()))), + Type.StructField.of( + "protoEnumArray", Type.array(Type.protoEnum(Genre.getDescriptor().getFullName())))); Struct struct1 = Struct.newBuilder() .set("f1") @@ -128,6 +152,10 @@ public void resultSetIteration() { .to(Timestamp.ofTimeMicroseconds(usecs)) .set("date") .to(Date.fromYearMonthDay(year, month, day)) + .set("protoMessage") + .to(protoMessageVal) + .set("protoEnum") + .to(protoEnumVal) .set("boolArray") .to(Value.boolArray(boolArray)) .set("longArray") @@ -148,6 +176,14 @@ public void resultSetIteration() { .to(Value.jsonArray(Arrays.asList(jsonArray))) .set("pgJsonbArray") .to(Value.pgJsonbArray(Arrays.asList(jsonArray))) + .set("protoMessageArray") + .to( + Value.protoMessageArray( + Arrays.asList(protoMessageArray), protoMessageVal.getDescriptorForType())) + .set("protoEnumArray") + .to( + Value.protoEnumArray( + Arrays.asList(protoEnumArray), protoEnumVal.getDescriptorForType())) .build(); Struct struct2 = Struct.newBuilder() @@ -173,6 +209,10 @@ public void resultSetIteration() { .to(Timestamp.ofTimeMicroseconds(usecs)) .set("date") .to(Date.fromYearMonthDay(year, month, day)) + .set("protoMessage") + .to(protoMessageVal) + .set("protoEnum") + .to(protoEnumVal) .set("boolArray") .to(Value.boolArray(boolArray)) .set("longArray") @@ -193,6 +233,14 @@ public void resultSetIteration() { .to(Value.jsonArray(Arrays.asList(jsonArray))) .set("pgJsonbArray") .to(Value.pgJsonbArray(Arrays.asList(jsonArray))) + .set("protoMessageArray") + .to( + Value.protoMessageArray( + Arrays.asList(protoMessageArray), protoMessageVal.getDescriptorForType())) + .set("protoEnumArray") + .to( + Value.protoEnumArray( + Arrays.asList(protoEnumArray), protoEnumVal.getDescriptorForType())) .build(); ResultSet rs = ResultSets.forRows(type, Arrays.asList(struct1, struct2)); @@ -259,6 +307,18 @@ public void resultSetIteration() { .isEqualTo(Value.date(Date.fromYearMonthDay(year, month, day))); assertThat(rs.getDate("date")).isEqualTo(Date.fromYearMonthDay(year, month, day)); assertThat(rs.getValue("date")).isEqualTo(Value.date(Date.fromYearMonthDay(year, month, day))); + + assertEquals(protoMessageVal, rs.getProtoMessage(columnIndex, SingerInfo.getDefaultInstance())); + assertEquals(Value.protoMessage(protoMessageVal), rs.getValue(columnIndex++)); + assertEquals( + protoMessageVal, rs.getProtoMessage("protoMessage", SingerInfo.getDefaultInstance())); + assertEquals(Value.protoMessage(protoMessageVal), rs.getValue("protoMessage")); + + assertEquals(protoEnumVal, rs.getProtoEnum(columnIndex, Genre::forNumber)); + assertEquals(Value.protoEnum(protoEnumVal), rs.getValue(columnIndex++)); + assertEquals(protoEnumVal, rs.getProtoEnum("protoEnum", Genre::forNumber)); + assertEquals(Value.protoEnum(protoEnumVal), rs.getValue("protoEnum")); + assertThat(rs.getBooleanArray(columnIndex)).isEqualTo(boolArray); assertThat(rs.getValue(columnIndex++)).isEqualTo(Value.boolArray(boolArray)); assertThat(rs.getBooleanArray("boolArray")).isEqualTo(boolArray); @@ -305,9 +365,29 @@ public void resultSetIteration() { assertThat(rs.getJsonList(columnIndex++)).isEqualTo(Arrays.asList(jsonArray)); assertThat(rs.getJsonList("jsonArray")).isEqualTo(Arrays.asList(jsonArray)); - assertEquals(Arrays.asList(jsonArray), rs.getPgJsonbList(columnIndex)); + assertEquals(Arrays.asList(jsonArray), rs.getPgJsonbList(columnIndex++)); assertEquals(Arrays.asList(jsonArray), rs.getPgJsonbList("pgJsonbArray")); + assertThat(rs.getProtoMessageList(columnIndex, SingerInfo.getDefaultInstance())) + .isEqualTo(Arrays.asList(protoMessageArray)); + assertThat(rs.getValue(columnIndex++)) + .isEqualTo( + Value.protoMessageArray(Arrays.asList(protoMessageArray), SingerInfo.getDescriptor())); + assertThat(rs.getProtoMessageList("protoMessageArray", SingerInfo.getDefaultInstance())) + .isEqualTo(Arrays.asList(protoMessageArray)); + assertThat(rs.getValue("protoMessageArray")) + .isEqualTo( + Value.protoMessageArray(Arrays.asList(protoMessageArray), SingerInfo.getDescriptor())); + + assertThat(rs.getProtoEnumList(columnIndex, Genre::forNumber)) + .isEqualTo(Arrays.asList(protoEnumArray)); + assertThat(rs.getValue(columnIndex)) + .isEqualTo(Value.protoEnumArray(Arrays.asList(protoEnumArray), Genre.getDescriptor())); + assertThat(rs.getProtoEnumList("protoEnumArray", Genre::forNumber)) + .isEqualTo(Arrays.asList(protoEnumArray)); + assertThat(rs.getValue("protoEnumArray")) + .isEqualTo(Value.protoEnumArray(Arrays.asList(protoEnumArray), Genre.getDescriptor())); + assertThat(rs.next()).isTrue(); assertThat(rs.getCurrentRowAsStruct()).isEqualTo(struct2); assertThat(rs.getString(0)).isEqualTo("y"); diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SingerProto.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SingerProto.java new file mode 100644 index 00000000000..56fb82c15d2 --- /dev/null +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SingerProto.java @@ -0,0 +1,1199 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: src/test/resources/com/google/cloud/spanner/singer.proto +package com.google.cloud.spanner; + +public final class SingerProto { + private SingerProto() {} + + public static void registerAllExtensions(com.google.protobuf.ExtensionRegistryLite registry) {} + + public static void registerAllExtensions(com.google.protobuf.ExtensionRegistry registry) { + registerAllExtensions((com.google.protobuf.ExtensionRegistryLite) registry); + } + /** Protobuf enum {@code spanner.examples.music.Genre} */ + public enum Genre implements com.google.protobuf.ProtocolMessageEnum { + /** POP = 0; */ + POP(0), + /** JAZZ = 1; */ + JAZZ(1), + /** FOLK = 2; */ + FOLK(2), + /** ROCK = 3; */ + ROCK(3), + ; + + /** POP = 0; */ + public static final int POP_VALUE = 0; + /** JAZZ = 1; */ + public static final int JAZZ_VALUE = 1; + /** FOLK = 2; */ + public static final int FOLK_VALUE = 2; + /** ROCK = 3; */ + public static final int ROCK_VALUE = 3; + + public final int getNumber() { + return value; + } + + /** + * @param value The numeric wire value of the corresponding enum entry. + * @return The enum associated with the given numeric wire value. + * @deprecated Use {@link #forNumber(int)} instead. + */ + @java.lang.Deprecated + public static Genre valueOf(int value) { + return forNumber(value); + } + + /** + * @param value The numeric wire value of the corresponding enum entry. + * @return The enum associated with the given numeric wire value. + */ + public static Genre forNumber(int value) { + switch (value) { + case 0: + return POP; + case 1: + return JAZZ; + case 2: + return FOLK; + case 3: + return ROCK; + default: + return null; + } + } + + public static com.google.protobuf.Internal.EnumLiteMap internalGetValueMap() { + return internalValueMap; + } + + private static final com.google.protobuf.Internal.EnumLiteMap internalValueMap = + new com.google.protobuf.Internal.EnumLiteMap() { + public Genre findValueByNumber(int number) { + return Genre.forNumber(number); + } + }; + + public final com.google.protobuf.Descriptors.EnumValueDescriptor getValueDescriptor() { + return getDescriptor().getValues().get(ordinal()); + } + + public final com.google.protobuf.Descriptors.EnumDescriptor getDescriptorForType() { + return getDescriptor(); + } + + public static final com.google.protobuf.Descriptors.EnumDescriptor getDescriptor() { + return com.google.cloud.spanner.SingerProto.getDescriptor().getEnumTypes().get(0); + } + + private static final Genre[] VALUES = values(); + + public static Genre valueOf(com.google.protobuf.Descriptors.EnumValueDescriptor desc) { + if (desc.getType() != getDescriptor()) { + throw new java.lang.IllegalArgumentException("EnumValueDescriptor is not for this type."); + } + return VALUES[desc.getIndex()]; + } + + private final int value; + + private Genre(int value) { + this.value = value; + } + + // @@protoc_insertion_point(enum_scope:spanner.examples.music.Genre) + } + + public interface SingerInfoOrBuilder + extends + // @@protoc_insertion_point(interface_extends:spanner.examples.music.SingerInfo) + com.google.protobuf.MessageOrBuilder { + + /** + * optional int64 singer_id = 1; + * + * @return Whether the singerId field is set. + */ + boolean hasSingerId(); + /** + * optional int64 singer_id = 1; + * + * @return The singerId. + */ + long getSingerId(); + + /** + * optional string birth_date = 2; + * + * @return Whether the birthDate field is set. + */ + boolean hasBirthDate(); + /** + * optional string birth_date = 2; + * + * @return The birthDate. + */ + java.lang.String getBirthDate(); + /** + * optional string birth_date = 2; + * + * @return The bytes for birthDate. + */ + com.google.protobuf.ByteString getBirthDateBytes(); + + /** + * optional string nationality = 3; + * + * @return Whether the nationality field is set. + */ + boolean hasNationality(); + /** + * optional string nationality = 3; + * + * @return The nationality. + */ + java.lang.String getNationality(); + /** + * optional string nationality = 3; + * + * @return The bytes for nationality. + */ + com.google.protobuf.ByteString getNationalityBytes(); + + /** + * optional .spanner.examples.music.Genre genre = 4; + * + * @return Whether the genre field is set. + */ + boolean hasGenre(); + /** + * optional .spanner.examples.music.Genre genre = 4; + * + * @return The genre. + */ + com.google.cloud.spanner.SingerProto.Genre getGenre(); + } + /** Protobuf type {@code spanner.examples.music.SingerInfo} */ + public static final class SingerInfo extends com.google.protobuf.GeneratedMessageV3 + implements + // @@protoc_insertion_point(message_implements:spanner.examples.music.SingerInfo) + SingerInfoOrBuilder { + private static final long serialVersionUID = 0L; + // Use SingerInfo.newBuilder() to construct. + private SingerInfo(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + + private SingerInfo() { + birthDate_ = ""; + nationality_ = ""; + genre_ = 0; + } + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance(UnusedPrivateParameter unused) { + return new SingerInfo(); + } + + @java.lang.Override + public final com.google.protobuf.UnknownFieldSet getUnknownFields() { + return this.unknownFields; + } + + private SingerInfo( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + this(); + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + int mutable_bitField0_ = 0; + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.protobuf.UnknownFieldSet.newBuilder(); + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 8: + { + bitField0_ |= 0x00000001; + singerId_ = input.readInt64(); + break; + } + case 18: + { + com.google.protobuf.ByteString bs = input.readBytes(); + bitField0_ |= 0x00000002; + birthDate_ = bs; + break; + } + case 26: + { + com.google.protobuf.ByteString bs = input.readBytes(); + bitField0_ |= 0x00000004; + nationality_ = bs; + break; + } + case 32: + { + int rawValue = input.readEnum(); + @SuppressWarnings("deprecation") + com.google.cloud.spanner.SingerProto.Genre value = + com.google.cloud.spanner.SingerProto.Genre.valueOf(rawValue); + if (value == null) { + unknownFields.mergeVarintField(4, rawValue); + } else { + bitField0_ |= 0x00000008; + genre_ = rawValue; + } + break; + } + default: + { + if (!parseUnknownField(input, unknownFields, extensionRegistry, tag)) { + done = true; + } + break; + } + } + } + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(this); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e).setUnfinishedMessage(this); + } finally { + this.unknownFields = unknownFields.build(); + makeExtensionsImmutable(); + } + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.cloud.spanner.SingerProto + .internal_static_spanner_examples_music_SingerInfo_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.cloud.spanner.SingerProto + .internal_static_spanner_examples_music_SingerInfo_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.cloud.spanner.SingerProto.SingerInfo.class, + com.google.cloud.spanner.SingerProto.SingerInfo.Builder.class); + } + + private int bitField0_; + public static final int SINGER_ID_FIELD_NUMBER = 1; + private long singerId_; + /** + * optional int64 singer_id = 1; + * + * @return Whether the singerId field is set. + */ + @java.lang.Override + public boolean hasSingerId() { + return ((bitField0_ & 0x00000001) != 0); + } + /** + * optional int64 singer_id = 1; + * + * @return The singerId. + */ + @java.lang.Override + public long getSingerId() { + return singerId_; + } + + public static final int BIRTH_DATE_FIELD_NUMBER = 2; + private volatile java.lang.Object birthDate_; + /** + * optional string birth_date = 2; + * + * @return Whether the birthDate field is set. + */ + @java.lang.Override + public boolean hasBirthDate() { + return ((bitField0_ & 0x00000002) != 0); + } + /** + * optional string birth_date = 2; + * + * @return The birthDate. + */ + @java.lang.Override + public java.lang.String getBirthDate() { + java.lang.Object ref = birthDate_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + birthDate_ = s; + } + return s; + } + } + /** + * optional string birth_date = 2; + * + * @return The bytes for birthDate. + */ + @java.lang.Override + public com.google.protobuf.ByteString getBirthDateBytes() { + java.lang.Object ref = birthDate_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + birthDate_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int NATIONALITY_FIELD_NUMBER = 3; + private volatile java.lang.Object nationality_; + /** + * optional string nationality = 3; + * + * @return Whether the nationality field is set. + */ + @java.lang.Override + public boolean hasNationality() { + return ((bitField0_ & 0x00000004) != 0); + } + /** + * optional string nationality = 3; + * + * @return The nationality. + */ + @java.lang.Override + public java.lang.String getNationality() { + java.lang.Object ref = nationality_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + nationality_ = s; + } + return s; + } + } + /** + * optional string nationality = 3; + * + * @return The bytes for nationality. + */ + @java.lang.Override + public com.google.protobuf.ByteString getNationalityBytes() { + java.lang.Object ref = nationality_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + nationality_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int GENRE_FIELD_NUMBER = 4; + private int genre_; + /** + * optional .spanner.examples.music.Genre genre = 4; + * + * @return Whether the genre field is set. + */ + @java.lang.Override + public boolean hasGenre() { + return ((bitField0_ & 0x00000008) != 0); + } + /** + * optional .spanner.examples.music.Genre genre = 4; + * + * @return The genre. + */ + @java.lang.Override + public com.google.cloud.spanner.SingerProto.Genre getGenre() { + @SuppressWarnings("deprecation") + com.google.cloud.spanner.SingerProto.Genre result = + com.google.cloud.spanner.SingerProto.Genre.valueOf(genre_); + return result == null ? com.google.cloud.spanner.SingerProto.Genre.POP : result; + } + + private byte memoizedIsInitialized = -1; + + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + if (((bitField0_ & 0x00000001) != 0)) { + output.writeInt64(1, singerId_); + } + if (((bitField0_ & 0x00000002) != 0)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 2, birthDate_); + } + if (((bitField0_ & 0x00000004) != 0)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 3, nationality_); + } + if (((bitField0_ & 0x00000008) != 0)) { + output.writeEnum(4, genre_); + } + unknownFields.writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (((bitField0_ & 0x00000001) != 0)) { + size += com.google.protobuf.CodedOutputStream.computeInt64Size(1, singerId_); + } + if (((bitField0_ & 0x00000002) != 0)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, birthDate_); + } + if (((bitField0_ & 0x00000004) != 0)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, nationality_); + } + if (((bitField0_ & 0x00000008) != 0)) { + size += com.google.protobuf.CodedOutputStream.computeEnumSize(4, genre_); + } + size += unknownFields.getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof com.google.cloud.spanner.SingerProto.SingerInfo)) { + return super.equals(obj); + } + com.google.cloud.spanner.SingerProto.SingerInfo other = + (com.google.cloud.spanner.SingerProto.SingerInfo) obj; + + if (hasSingerId() != other.hasSingerId()) return false; + if (hasSingerId()) { + if (getSingerId() != other.getSingerId()) return false; + } + if (hasBirthDate() != other.hasBirthDate()) return false; + if (hasBirthDate()) { + if (!getBirthDate().equals(other.getBirthDate())) return false; + } + if (hasNationality() != other.hasNationality()) return false; + if (hasNationality()) { + if (!getNationality().equals(other.getNationality())) return false; + } + if (hasGenre() != other.hasGenre()) return false; + if (hasGenre()) { + if (genre_ != other.genre_) return false; + } + if (!unknownFields.equals(other.unknownFields)) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + if (hasSingerId()) { + hash = (37 * hash) + SINGER_ID_FIELD_NUMBER; + hash = (53 * hash) + com.google.protobuf.Internal.hashLong(getSingerId()); + } + if (hasBirthDate()) { + hash = (37 * hash) + BIRTH_DATE_FIELD_NUMBER; + hash = (53 * hash) + getBirthDate().hashCode(); + } + if (hasNationality()) { + hash = (37 * hash) + NATIONALITY_FIELD_NUMBER; + hash = (53 * hash) + getNationality().hashCode(); + } + if (hasGenre()) { + hash = (37 * hash) + GENRE_FIELD_NUMBER; + hash = (53 * hash) + genre_; + } + hash = (29 * hash) + unknownFields.hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static com.google.cloud.spanner.SingerProto.SingerInfo parseFrom( + java.nio.ByteBuffer data) throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.cloud.spanner.SingerProto.SingerInfo parseFrom( + java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.cloud.spanner.SingerProto.SingerInfo parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.cloud.spanner.SingerProto.SingerInfo parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.cloud.spanner.SingerProto.SingerInfo parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.cloud.spanner.SingerProto.SingerInfo parseFrom( + byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.cloud.spanner.SingerProto.SingerInfo parseFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.cloud.spanner.SingerProto.SingerInfo parseFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.cloud.spanner.SingerProto.SingerInfo parseDelimitedFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); + } + + public static com.google.cloud.spanner.SingerProto.SingerInfo parseDelimitedFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.cloud.spanner.SingerProto.SingerInfo parseFrom( + com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.cloud.spanner.SingerProto.SingerInfo parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder(com.google.cloud.spanner.SingerProto.SingerInfo prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** Protobuf type {@code spanner.examples.music.SingerInfo} */ + public static final class Builder + extends com.google.protobuf.GeneratedMessageV3.Builder + implements + // @@protoc_insertion_point(builder_implements:spanner.examples.music.SingerInfo) + com.google.cloud.spanner.SingerProto.SingerInfoOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.cloud.spanner.SingerProto + .internal_static_spanner_examples_music_SingerInfo_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.cloud.spanner.SingerProto + .internal_static_spanner_examples_music_SingerInfo_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.cloud.spanner.SingerProto.SingerInfo.class, + com.google.cloud.spanner.SingerProto.SingerInfo.Builder.class); + } + + // Construct using com.google.cloud.spanner.SingerProto.SingerInfo.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders) {} + } + + @java.lang.Override + public Builder clear() { + super.clear(); + singerId_ = 0L; + bitField0_ = (bitField0_ & ~0x00000001); + birthDate_ = ""; + bitField0_ = (bitField0_ & ~0x00000002); + nationality_ = ""; + bitField0_ = (bitField0_ & ~0x00000004); + genre_ = 0; + bitField0_ = (bitField0_ & ~0x00000008); + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return com.google.cloud.spanner.SingerProto + .internal_static_spanner_examples_music_SingerInfo_descriptor; + } + + @java.lang.Override + public com.google.cloud.spanner.SingerProto.SingerInfo getDefaultInstanceForType() { + return com.google.cloud.spanner.SingerProto.SingerInfo.getDefaultInstance(); + } + + @java.lang.Override + public com.google.cloud.spanner.SingerProto.SingerInfo build() { + com.google.cloud.spanner.SingerProto.SingerInfo result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public com.google.cloud.spanner.SingerProto.SingerInfo buildPartial() { + com.google.cloud.spanner.SingerProto.SingerInfo result = + new com.google.cloud.spanner.SingerProto.SingerInfo(this); + int from_bitField0_ = bitField0_; + int to_bitField0_ = 0; + if (((from_bitField0_ & 0x00000001) != 0)) { + result.singerId_ = singerId_; + to_bitField0_ |= 0x00000001; + } + if (((from_bitField0_ & 0x00000002) != 0)) { + to_bitField0_ |= 0x00000002; + } + result.birthDate_ = birthDate_; + if (((from_bitField0_ & 0x00000004) != 0)) { + to_bitField0_ |= 0x00000004; + } + result.nationality_ = nationality_; + if (((from_bitField0_ & 0x00000008) != 0)) { + to_bitField0_ |= 0x00000008; + } + result.genre_ = genre_; + result.bitField0_ = to_bitField0_; + onBuilt(); + return result; + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.setField(field, value); + } + + @java.lang.Override + public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + + @java.lang.Override + public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + int index, + java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.addRepeatedField(field, value); + } + + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.google.cloud.spanner.SingerProto.SingerInfo) { + return mergeFrom((com.google.cloud.spanner.SingerProto.SingerInfo) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.google.cloud.spanner.SingerProto.SingerInfo other) { + if (other == com.google.cloud.spanner.SingerProto.SingerInfo.getDefaultInstance()) + return this; + if (other.hasSingerId()) { + setSingerId(other.getSingerId()); + } + if (other.hasBirthDate()) { + bitField0_ |= 0x00000002; + birthDate_ = other.birthDate_; + onChanged(); + } + if (other.hasNationality()) { + bitField0_ |= 0x00000004; + nationality_ = other.nationality_; + onChanged(); + } + if (other.hasGenre()) { + setGenre(other.getGenre()); + } + this.mergeUnknownFields(other.unknownFields); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + com.google.cloud.spanner.SingerProto.SingerInfo parsedMessage = null; + try { + parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + parsedMessage = + (com.google.cloud.spanner.SingerProto.SingerInfo) e.getUnfinishedMessage(); + throw e.unwrapIOException(); + } finally { + if (parsedMessage != null) { + mergeFrom(parsedMessage); + } + } + return this; + } + + private int bitField0_; + + private long singerId_; + /** + * optional int64 singer_id = 1; + * + * @return Whether the singerId field is set. + */ + @java.lang.Override + public boolean hasSingerId() { + return ((bitField0_ & 0x00000001) != 0); + } + /** + * optional int64 singer_id = 1; + * + * @return The singerId. + */ + @java.lang.Override + public long getSingerId() { + return singerId_; + } + /** + * optional int64 singer_id = 1; + * + * @param value The singerId to set. + * @return This builder for chaining. + */ + public Builder setSingerId(long value) { + bitField0_ |= 0x00000001; + singerId_ = value; + onChanged(); + return this; + } + /** + * optional int64 singer_id = 1; + * + * @return This builder for chaining. + */ + public Builder clearSingerId() { + bitField0_ = (bitField0_ & ~0x00000001); + singerId_ = 0L; + onChanged(); + return this; + } + + private java.lang.Object birthDate_ = ""; + /** + * optional string birth_date = 2; + * + * @return Whether the birthDate field is set. + */ + public boolean hasBirthDate() { + return ((bitField0_ & 0x00000002) != 0); + } + /** + * optional string birth_date = 2; + * + * @return The birthDate. + */ + public java.lang.String getBirthDate() { + java.lang.Object ref = birthDate_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + birthDate_ = s; + } + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * optional string birth_date = 2; + * + * @return The bytes for birthDate. + */ + public com.google.protobuf.ByteString getBirthDateBytes() { + java.lang.Object ref = birthDate_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + birthDate_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * optional string birth_date = 2; + * + * @param value The birthDate to set. + * @return This builder for chaining. + */ + public Builder setBirthDate(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000002; + birthDate_ = value; + onChanged(); + return this; + } + /** + * optional string birth_date = 2; + * + * @return This builder for chaining. + */ + public Builder clearBirthDate() { + bitField0_ = (bitField0_ & ~0x00000002); + birthDate_ = getDefaultInstance().getBirthDate(); + onChanged(); + return this; + } + /** + * optional string birth_date = 2; + * + * @param value The bytes for birthDate to set. + * @return This builder for chaining. + */ + public Builder setBirthDateBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000002; + birthDate_ = value; + onChanged(); + return this; + } + + private java.lang.Object nationality_ = ""; + /** + * optional string nationality = 3; + * + * @return Whether the nationality field is set. + */ + public boolean hasNationality() { + return ((bitField0_ & 0x00000004) != 0); + } + /** + * optional string nationality = 3; + * + * @return The nationality. + */ + public java.lang.String getNationality() { + java.lang.Object ref = nationality_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + nationality_ = s; + } + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * optional string nationality = 3; + * + * @return The bytes for nationality. + */ + public com.google.protobuf.ByteString getNationalityBytes() { + java.lang.Object ref = nationality_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + nationality_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * optional string nationality = 3; + * + * @param value The nationality to set. + * @return This builder for chaining. + */ + public Builder setNationality(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000004; + nationality_ = value; + onChanged(); + return this; + } + /** + * optional string nationality = 3; + * + * @return This builder for chaining. + */ + public Builder clearNationality() { + bitField0_ = (bitField0_ & ~0x00000004); + nationality_ = getDefaultInstance().getNationality(); + onChanged(); + return this; + } + /** + * optional string nationality = 3; + * + * @param value The bytes for nationality to set. + * @return This builder for chaining. + */ + public Builder setNationalityBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000004; + nationality_ = value; + onChanged(); + return this; + } + + private int genre_ = 0; + /** + * optional .spanner.examples.music.Genre genre = 4; + * + * @return Whether the genre field is set. + */ + @java.lang.Override + public boolean hasGenre() { + return ((bitField0_ & 0x00000008) != 0); + } + /** + * optional .spanner.examples.music.Genre genre = 4; + * + * @return The genre. + */ + @java.lang.Override + public com.google.cloud.spanner.SingerProto.Genre getGenre() { + @SuppressWarnings("deprecation") + com.google.cloud.spanner.SingerProto.Genre result = + com.google.cloud.spanner.SingerProto.Genre.valueOf(genre_); + return result == null ? com.google.cloud.spanner.SingerProto.Genre.POP : result; + } + /** + * optional .spanner.examples.music.Genre genre = 4; + * + * @param value The genre to set. + * @return This builder for chaining. + */ + public Builder setGenre(com.google.cloud.spanner.SingerProto.Genre value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000008; + genre_ = value.getNumber(); + onChanged(); + return this; + } + /** + * optional .spanner.examples.music.Genre genre = 4; + * + * @return This builder for chaining. + */ + public Builder clearGenre() { + bitField0_ = (bitField0_ & ~0x00000008); + genre_ = 0; + onChanged(); + return this; + } + + @java.lang.Override + public final Builder setUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + // @@protoc_insertion_point(builder_scope:spanner.examples.music.SingerInfo) + } + + // @@protoc_insertion_point(class_scope:spanner.examples.music.SingerInfo) + private static final com.google.cloud.spanner.SingerProto.SingerInfo DEFAULT_INSTANCE; + + static { + DEFAULT_INSTANCE = new com.google.cloud.spanner.SingerProto.SingerInfo(); + } + + public static com.google.cloud.spanner.SingerProto.SingerInfo getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + @java.lang.Deprecated + public static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + @java.lang.Override + public SingerInfo parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return new SingerInfo(input, extensionRegistry); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public com.google.cloud.spanner.SingerProto.SingerInfo getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + } + + private static final com.google.protobuf.Descriptors.Descriptor + internal_static_spanner_examples_music_SingerInfo_descriptor; + private static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_spanner_examples_music_SingerInfo_fieldAccessorTable; + + public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { + return descriptor; + } + + private static com.google.protobuf.Descriptors.FileDescriptor descriptor; + + static { + java.lang.String[] descriptorData = { + "\n\014singer.proto\022\026spanner.examples.music\"v" + + "\n\nSingerInfo\022\021\n\tsinger_id\030\001 \001(\003\022\022\n\nbirth" + + "_date\030\002 \001(\t\022\023\n\013nationality\030\003 \001(\t\022,\n\005genr" + + "e\030\004 \001(\0162\035.spanner.examples.music.Genre*." + + "\n\005Genre\022\007\n\003POP\020\000\022\010\n\004JAZZ\020\001\022\010\n\004FOLK\020\002\022\010\n\004" + + "ROCK\020\003B)\n\030com.google.cloud.spannerB\013Sing" + + "erProtoP\000" + }; + descriptor = + com.google.protobuf.Descriptors.FileDescriptor.internalBuildGeneratedFileFrom( + descriptorData, new com.google.protobuf.Descriptors.FileDescriptor[] {}); + internal_static_spanner_examples_music_SingerInfo_descriptor = + getDescriptor().getMessageTypes().get(0); + internal_static_spanner_examples_music_SingerInfo_fieldAccessorTable = + new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_spanner_examples_music_SingerInfo_descriptor, + new java.lang.String[] { + "SingerId", "BirthDate", "Nationality", "Genre", + }); + } + + // @@protoc_insertion_point(outer_class_scope) +} diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/TypeTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/TypeTest.java index 3ed6fc6c577..9b525f08e70 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/TypeTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/TypeTest.java @@ -38,6 +38,7 @@ private abstract static class ScalarTypeTester { private final Type.Code expectedCode; private final TypeCode expectedTypeCode; private final TypeAnnotationCode expectedTypeAnnotationCode; + private String protoTypeFqn = ""; ScalarTypeTester(Type.Code expectedCode, TypeCode expectedTypeCode) { this(expectedCode, expectedTypeCode, TypeAnnotationCode.TYPE_ANNOTATION_CODE_UNSPECIFIED); @@ -52,12 +53,17 @@ private abstract static class ScalarTypeTester { this.expectedTypeAnnotationCode = expectedTypeAnnotationCode; } + ScalarTypeTester(Type.Code expectedCode, TypeCode expectedTypeCode, String protoTypeFqn) { + this(expectedCode, expectedTypeCode); + this.protoTypeFqn = protoTypeFqn; + } + abstract Type newType(); void test() { Type t = newType(); assertThat(t.getCode()).isEqualTo(expectedCode); - assertThat(newType()).isSameInstanceAs(t); // Interned. + assertThat(newType()).isEqualTo(t); // Interned. // String form is deliberately the same as the corresponding type enum in the public API. if (expectedTypeAnnotationCode != TypeAnnotationCode.TYPE_ANNOTATION_CODE_UNSPECIFIED) { assertThat(t.toString()) @@ -70,13 +76,13 @@ void test() { com.google.spanner.v1.Type proto = t.toProto(); assertThat(proto.getCode()).isEqualTo(expectedTypeCode); assertThat(proto.getTypeAnnotation()).isEqualTo(expectedTypeAnnotationCode); + assertThat(proto.getProtoTypeFqn()).isEqualTo(protoTypeFqn); assertThat(proto.hasArrayElementType()).isFalse(); assertThat(proto.hasStructType()).isFalse(); // Round trip. Type fromProto = Type.fromProto(proto); assertThat(fromProto).isEqualTo(t); - assertThat(fromProto).isSameInstanceAs(t); reserializeAndAssert(t); } @@ -172,6 +178,26 @@ Type newType() { }.test(); } + @Test + public void proto() { + new ScalarTypeTester(Type.Code.PROTO, TypeCode.PROTO, "com.google.temp") { + @Override + Type newType() { + return Type.proto("com.google.temp"); + } + }.test(); + } + + @Test + public void protoEnum() { + new ScalarTypeTester(Type.Code.ENUM, TypeCode.ENUM, "com.google.temp.enum") { + @Override + Type newType() { + return Type.protoEnum("com.google.temp.enum"); + } + }.test(); + } + @Test public void timestamp() { new ScalarTypeTester(Type.Code.TIMESTAMP, TypeCode.TIMESTAMP) { @@ -197,6 +223,7 @@ abstract static class ArrayTypeTester { private final TypeCode expectedElementTypeCode; private final TypeAnnotationCode expectedTypeAnnotationCode; private final boolean expectInterned; + private String protoTypeFqn = ""; ArrayTypeTester( Type.Code expectedElementCode, TypeCode expectedElementTypeCode, boolean expectInterned) { @@ -207,6 +234,19 @@ abstract static class ArrayTypeTester { expectInterned); } + ArrayTypeTester( + Type.Code expectedElementCode, + TypeCode expectedElementTypeCode, + String protoTypeFqn, + boolean expectInterned) { + this( + expectedElementCode, + expectedElementTypeCode, + TypeAnnotationCode.TYPE_ANNOTATION_CODE_UNSPECIFIED, + expectInterned); + this.protoTypeFqn = protoTypeFqn; + } + ArrayTypeTester( Type.Code expectedElementCode, TypeCode expectedElementTypeCode, @@ -356,6 +396,26 @@ Type newElementType() { }.test(); } + @Test + public void protoArray() { + new ArrayTypeTester(Type.Code.PROTO, TypeCode.PROTO, "com.google.temp", false) { + @Override + Type newElementType() { + return Type.proto("com.google.temp"); + } + }.test(); + } + + @Test + public void protoEnumArray() { + new ArrayTypeTester(Type.Code.ENUM, TypeCode.ENUM, "com.google.temp.enum", false) { + @Override + Type newElementType() { + return Type.protoEnum("com.google.temp.enum"); + } + }.test(); + } + @Test public void arrayOfArray() { new ArrayTypeTester(Type.Code.ARRAY, TypeCode.ARRAY, false /* not interned */) { diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/ValueBinderTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/ValueBinderTest.java index 91263457baf..8962c0accfc 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/ValueBinderTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/ValueBinderTest.java @@ -24,6 +24,12 @@ import com.google.cloud.ByteArray; import com.google.cloud.Date; import com.google.cloud.Timestamp; +import com.google.cloud.spanner.SingerProto.Genre; +import com.google.cloud.spanner.SingerProto.SingerInfo; +import com.google.protobuf.AbstractMessage; +import com.google.protobuf.Descriptors.Descriptor; +import com.google.protobuf.Descriptors.EnumDescriptor; +import com.google.protobuf.ProtocolMessageEnum; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; @@ -40,6 +46,8 @@ public class ValueBinderTest { private static final String JSON_METHOD_NAME = "json"; private static final String PG_JSONB_METHOD_NAME = "pgJsonb"; private static final String PG_NUMERIC_METHOD_NAME = "pgNumeric"; + private static final String PROTO_MESSAGE_METHOD_NAME = "protoMessage"; + private static final String PROTO_ENUM_METHOD_NAME = "protoEnum"; public static final String DEFAULT_PG_NUMERIC = "1.23"; private Value lastValue; @@ -121,7 +129,9 @@ public void reflection() } } else if (binderMethod.getParameterTypes().length == 1) { // Test unary null. - if (!binderMethod.getParameterTypes()[0].isPrimitive()) { + if (!binderMethod.getParameterTypes()[0].isPrimitive() + && (!method.getName().equalsIgnoreCase(PROTO_MESSAGE_METHOD_NAME) + && !method.getName().equalsIgnoreCase(PROTO_ENUM_METHOD_NAME))) { if (method.getName().equalsIgnoreCase(JSON_METHOD_NAME)) { // Special case for json to change the method from ValueBinder.to(String) to // ValueBinder.to(Value) @@ -139,7 +149,6 @@ public void reflection() } Value expected = (Value) method.invoke(Value.class, (Object) null); assertThat(lastValue).isEqualTo(expected); - assertThat(binder.to(expected)).isEqualTo(lastReturnValue); assertThat(lastValue).isEqualTo(expected); } @@ -167,6 +176,27 @@ public void reflection() Value expected = (Value) method.invoke(Value.class, defaultObject); assertThat(lastValue).isEqualTo(expected); + assertThat(binder.to(expected)).isEqualTo(lastReturnValue); + assertThat(lastValue).isEqualTo(expected); + } else if (binderMethod.getParameterTypes().length == 2 + && (method.getName().contains(PROTO_MESSAGE_METHOD_NAME) + || method.getName().contains(PROTO_ENUM_METHOD_NAME))) { + // Test unary null. + Object firstArgument = null; + if (binderMethod.getParameterTypes()[0].isPrimitive()) { + firstArgument = 0; + } + + Object secondArgument = "com.proto.example"; + if (binderMethod.getParameterTypes()[1] == Descriptor.class) { + secondArgument = SingerInfo.getDescriptor(); + } else if (binderMethod.getParameterTypes()[1] == EnumDescriptor.class) { + secondArgument = Genre.getDescriptor(); + } + assertThat(binderMethod.invoke(binder, firstArgument, secondArgument)) + .isEqualTo(lastReturnValue); + Value expected = (Value) method.invoke(Value.class, firstArgument, secondArgument); + assertThat(lastValue).isEqualTo(expected); assertThat(binder.to(expected)).isEqualTo(lastReturnValue); assertThat(lastValue).isEqualTo(expected); } else { @@ -234,6 +264,14 @@ public static BigDecimal defaultBigDecimal() { return BigDecimal.valueOf(123, 2); } + public static AbstractMessage defaultAbstractMessage() { + return SingerInfo.newBuilder().setSingerId(323).build(); + } + + public static ProtocolMessageEnum defaultProtocolMessageEnum() { + return Genre.FOLK; + } + public static String defaultString() { return "x"; } diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/ValueTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/ValueTest.java index a466fab1ab4..7c96d95b514 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/ValueTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/ValueTest.java @@ -32,6 +32,8 @@ import com.google.cloud.ByteArray; import com.google.cloud.Date; import com.google.cloud.Timestamp; +import com.google.cloud.spanner.SingerProto.Genre; +import com.google.cloud.spanner.SingerProto.SingerInfo; import com.google.cloud.spanner.Type.StructField; import com.google.common.base.Strings; import com.google.common.collect.ForwardingList; @@ -629,6 +631,56 @@ public void dateNull() { assertThat(e.getMessage()).contains("null value"); } + @Test + public void protoMessage() { + SingerInfo singerInfo = SingerInfo.newBuilder().setSingerId(111).setGenre(Genre.FOLK).build(); + Value v = Value.protoMessage(singerInfo); + assertThat(v.getType()).isEqualTo(Type.proto(SingerInfo.getDescriptor().getFullName())); + assertThat(v.isNull()).isFalse(); + assertThat(v.getProtoMessage(SingerInfo.getDefaultInstance())).isEqualTo(singerInfo); + assertThat(v.getBytes().toByteArray()).isEqualTo(singerInfo.toByteArray()); + } + + @Test + public void protoMessageNull() { + Value v = Value.protoMessage(null, SingerInfo.getDescriptor().getFullName()); + assertThat(v.getType()).isEqualTo(Type.proto(SingerInfo.getDescriptor().getFullName())); + assertThat(v.isNull()).isTrue(); + assertThat(v.toString()).isEqualTo(NULL_STRING); + IllegalStateException e = + assertThrows( + IllegalStateException.class, + () -> { + v.getProtoMessage(SingerInfo.getDefaultInstance()); + }); + assertThat(e.getMessage()).contains("null value"); + } + + @Test + public void protoEnum() { + Genre genre = Genre.FOLK; + Value v = Value.protoEnum(genre); + assertThat(v.getType()).isEqualTo(Type.protoEnum(Genre.getDescriptor().getFullName())); + assertThat(v.isNull()).isFalse(); + assertThat(v.getInt64()).isEqualTo(genre.getNumber()); + assertEquals(genre, v.getProtoEnum(Genre::forNumber)); + } + + @Test + public void protoEnumNull() { + Value v = Value.protoEnum(null, Genre.getDescriptor().getFullName()); + assertThat(v.getType()).isEqualTo(Type.protoEnum(Genre.getDescriptor().getFullName())); + assertThat(v.isNull()).isTrue(); + assertThat(v.toString()).isEqualTo(NULL_STRING); + IllegalStateException e = + assertThrows( + IllegalStateException.class, + () -> { + v.getProtoEnum(Genre::forNumber); + }); + assertThat(e.getMessage()).contains("null value"); + } + @Test public void boolArray() { Value v = Value.boolArray(new boolean[] {true, false}); @@ -1050,6 +1102,70 @@ public void dateArrayNull() { assertThat(e.getMessage()).contains("null value"); } + @Test + public void protoMessageArray() { + SingerInfo singerInfo1 = SingerInfo.newBuilder().setSingerId(111).setGenre(Genre.FOLK).build(); + SingerInfo singerInfo2 = SingerInfo.newBuilder().setSingerId(222).build(); + Value v = + Value.protoMessageArray( + Arrays.asList(singerInfo1, null, singerInfo2), SingerInfo.getDescriptor()); + assertThat(v.getType()) + .isEqualTo(Type.array(Type.proto(SingerInfo.getDescriptor().getFullName()))); + assertThat(v.isNull()).isFalse(); + assertThat(v.getProtoMessageArray(SingerInfo.getDefaultInstance())) + .containsExactly(singerInfo1, null, singerInfo2); + assertThat(v.getBytesArray()) + .containsExactly( + ByteArray.copyFrom(singerInfo1.toByteArray()), + null, + ByteArray.copyFrom(singerInfo2.toByteArray())); + } + + @Test + public void protoMessageNullArray() { + Value v = Value.protoMessageArray(null, SingerInfo.getDescriptor()); + assertThat(v.getType()) + .isEqualTo(Type.array(Type.proto(SingerInfo.getDescriptor().getFullName()))); + assertThat(v.isNull()).isTrue(); + assertThat(v.toString()).isEqualTo(NULL_STRING); + IllegalStateException e = + assertThrows( + IllegalStateException.class, + () -> { + v.getProtoMessageArray(SingerInfo.getDefaultInstance()); + }); + assertThat(e.getMessage()).contains("null value"); + } + + @Test + public void protoEnumArray() { + Genre genre1 = Genre.ROCK; + Genre genre2 = Genre.JAZZ; + Value v = Value.protoEnumArray(Arrays.asList(genre1, null, genre2), Genre.getDescriptor()); + assertThat(v.getType()) + .isEqualTo(Type.array(Type.protoEnum(Genre.getDescriptor().getFullName()))); + assertThat(v.isNull()).isFalse(); + assertThat(v.getProtoEnumArray(Genre::forNumber)).containsExactly(genre1, null, genre2); + assertThat(v.getInt64Array()) + .containsExactly((long) genre1.getNumber(), null, (long) genre2.getNumber()); + } + + @Test + public void protoEnumNullArray() { + Value v = Value.protoEnumArray(null, Genre.getDescriptor()); + assertThat(v.getType()) + .isEqualTo(Type.array(Type.protoEnum(Genre.getDescriptor().getFullName()))); + assertThat(v.isNull()).isTrue(); + assertThat(v.toString()).isEqualTo(NULL_STRING); + IllegalStateException e = + assertThrows( + IllegalStateException.class, + () -> { + v.getProtoEnumArray(Genre::forNumber); + }); + assertThat(e.getMessage()).contains("null value"); + } + @Test public void struct() { Struct struct = Struct.newBuilder().set("f1").to("v1").set("f2").to(30).build(); diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/ChecksumResultSetTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/ChecksumResultSetTest.java index 1f3f59e96ab..4e8fb0cfcbb 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/ChecksumResultSetTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/ChecksumResultSetTest.java @@ -29,6 +29,8 @@ import com.google.cloud.spanner.AbortedException; import com.google.cloud.spanner.ResultSet; import com.google.cloud.spanner.ResultSets; +import com.google.cloud.spanner.SingerProto.Genre; +import com.google.cloud.spanner.SingerProto.SingerInfo; import com.google.cloud.spanner.Statement; import com.google.cloud.spanner.Struct; import com.google.cloud.spanner.Struct.Builder; @@ -65,6 +67,10 @@ public class ChecksumResultSetTest { .to(Value.json("{\"color\":\"red\",\"value\":\"#ff0\"}")) .set("pgJsonbVal") .to(Value.pgJsonb("{\"color\":\"red\",\"value\":\"#00f\"}")) + .set("protoMessageVal") + .to(SingerInfo.newBuilder().setSingerId(23).build()) + .set("protoEnumVal") + .to(Genre.JAZZ) .set("byteVal") .to(Value.bytes(ByteArray.copyFrom("bytes".getBytes(StandardCharsets.UTF_8)))) .set("timestamp") @@ -104,6 +110,15 @@ public class ChecksumResultSetTest { .to( Value.pgJsonbArray( Arrays.asList("{\"color\":\"red\",\"value\":\"#f00\"}", null, "[]"))) + .set("protoMessageArray") + .to( + Value.protoMessageArray( + Arrays.asList( + SingerInfo.newBuilder().setSingerId(23).build(), + SingerInfo.getDefaultInstance()), + SingerInfo.getDescriptor())) + .set("protoEnumArray") + .to(Value.protoEnumArray(Arrays.asList(Genre.JAZZ, Genre.ROCK), Genre.getDescriptor())) .build(); @Test @@ -118,6 +133,10 @@ public void testRetry() { Type.StructField.of("stringVal", Type.string()), Type.StructField.of("jsonVal", Type.json()), Type.StructField.of("pgJsonbVal", Type.pgJsonb()), + Type.StructField.of( + "protoMessageVal", Type.proto(SingerInfo.getDescriptor().getFullName())), + Type.StructField.of( + "protoEnumVal", Type.protoEnum(Genre.getDescriptor().getFullName())), Type.StructField.of("byteVal", Type.bytes()), Type.StructField.of("timestamp", Type.timestamp()), Type.StructField.of("date", Type.date()), @@ -131,7 +150,12 @@ public void testRetry() { Type.StructField.of("dateArray", Type.array(Type.date())), Type.StructField.of("stringArray", Type.array(Type.string())), Type.StructField.of("jsonArray", Type.array(Type.json())), - Type.StructField.of("pgJsonbArray", Type.array(Type.pgJsonb()))); + Type.StructField.of("pgJsonbArray", Type.array(Type.pgJsonb())), + Type.StructField.of( + "protoMessageArray", + Type.array(Type.proto(SingerInfo.getDescriptor().getFullName()))), + Type.StructField.of( + "protoEnumArray", Type.array(Type.protoEnum(Genre.getDescriptor().getFullName())))); Struct rowNonNullValues = Struct.newBuilder() .set("boolVal") @@ -150,6 +174,10 @@ public void testRetry() { .to(Value.json("{\"color\":\"red\",\"value\":\"#f00\"}")) .set("pgJsonbVal") .to(Value.pgJsonb("{\"color\":\"red\",\"value\":\"#f00\"}")) + .set("protoMessageVal") + .to(SingerInfo.newBuilder().setSingerId(98).setNationality("C1").build()) + .set("protoEnumVal") + .to(Genre.POP) .set("byteVal") .to(Value.bytes(ByteArray.copyFrom("test".getBytes(StandardCharsets.UTF_8)))) .set("timestamp") @@ -192,6 +220,15 @@ public void testRetry() { .to( Value.pgJsonbArray( Arrays.asList("{\"color\":\"red\",\"value\":\"#f00\"}", null, "{}"))) + .set("protoMessageArray") + .to( + Value.protoMessageArray( + Arrays.asList( + SingerInfo.newBuilder().setSingerId(11).setNationality("C1").build(), + SingerInfo.getDefaultInstance()), + SingerInfo.getDescriptor())) + .set("protoEnumArray") + .to(Value.protoEnumArray(Arrays.asList(Genre.POP, Genre.ROCK), Genre.getDescriptor())) .build(); Struct rowNullValues = Struct.newBuilder() @@ -211,6 +248,10 @@ public void testRetry() { .to(Value.json(null)) .set("pgJsonbVal") .to(Value.pgJsonb(null)) + .set("protoMessageVal") + .to(Value.protoMessage(null, SingerInfo.getDescriptor().getFullName())) + .set("protoEnumVal") + .to(Value.protoEnum(null, Genre.getDescriptor().getFullName())) .set("byteVal") .to((ByteArray) null) .set("timestamp") @@ -239,6 +280,10 @@ public void testRetry() { .toJsonArray(null) .set("pgJsonbArray") .toPgJsonbArray(null) + .set("protoMessageArray") + .to(Value.protoMessageArray(null, SingerInfo.getDescriptor())) + .set("protoEnumArray") + .to(Value.protoEnumArray(null, Genre.getDescriptor())) .build(); ParsedStatement parsedStatement = mock(ParsedStatement.class); diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/DirectExecuteResultSetTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/DirectExecuteResultSetTest.java index 346055060ab..1e4f96d1568 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/DirectExecuteResultSetTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/DirectExecuteResultSetTest.java @@ -25,15 +25,20 @@ import com.google.cloud.spanner.ResultSet; import com.google.cloud.spanner.ResultSets; +import com.google.cloud.spanner.SingerProto.Genre; +import com.google.cloud.spanner.SingerProto.SingerInfo; import com.google.cloud.spanner.Struct; import com.google.cloud.spanner.Type; import com.google.cloud.spanner.Type.StructField; +import com.google.protobuf.AbstractMessage; +import com.google.protobuf.ProtocolMessageEnum; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.function.Function; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -123,7 +128,7 @@ private void callMethods( boolean exception = false; int numberOfParameters = method.getParameterTypes().length; Class firstParameterType = null; - if (numberOfParameters == 1) { + if (numberOfParameters >= 1) { firstParameterType = method.getParameterTypes()[0]; } try { @@ -140,8 +145,32 @@ private void callMethods( fail("unknown parameter type"); } break; + case 2: + Class secondParameterType = method.getParameterTypes()[1]; + Object firstArgument = null, secondArgument = null; + + if (firstParameterType == String.class) { + firstArgument = "test"; + } else if (firstParameterType == int.class) { + firstArgument = 0; + } + + if (secondParameterType == Function.class) { + Function lambdaFunction = + (val) -> Genre.forNumber(val.intValue()); + secondArgument = lambdaFunction; + } else if (secondParameterType == AbstractMessage.class) { + secondArgument = SingerInfo.getDefaultInstance(); + } + + if (firstArgument != null && secondArgument != null) { + method.invoke(subject, firstArgument, secondArgument); + } else { + fail("unknown parameter type"); + } + break; default: - fail("method with more than 1 parameter is unknown"); + fail("method with more than 2 parameters is unknown"); } } catch (InvocationTargetException e) { if (e.getCause().getClass().equals(expectedException)) { @@ -261,6 +290,25 @@ public void testValidMethodCall() throws IllegalArgumentException { subject.getPgJsonbList("test2"); verify(delegate).getPgJsonbList("test2"); + subject.getProtoMessage(0, SingerInfo.getDefaultInstance()); + verify(delegate).getProtoMessage(0, SingerInfo.getDefaultInstance()); + subject.getProtoMessage("test0", SingerInfo.getDefaultInstance()); + verify(delegate).getProtoMessage("test0", SingerInfo.getDefaultInstance()); + subject.getProtoMessageList(0, SingerInfo.getDefaultInstance()); + verify(delegate).getProtoMessageList(0, SingerInfo.getDefaultInstance()); + subject.getProtoMessageList("test0", SingerInfo.getDefaultInstance()); + verify(delegate).getProtoMessageList("test0", SingerInfo.getDefaultInstance()); + + Function lambdaFunction = Genre::forNumber; + subject.getProtoEnum(0, lambdaFunction); + verify(delegate).getProtoEnum(0, lambdaFunction); + subject.getProtoEnum("test0", lambdaFunction); + verify(delegate).getProtoEnum("test0", lambdaFunction); + subject.getProtoEnumList(0, lambdaFunction); + verify(delegate).getProtoEnumList(0, lambdaFunction); + subject.getProtoEnumList("test0", lambdaFunction); + verify(delegate).getProtoEnumList("test0", lambdaFunction); + subject.getStructList(0); subject.getStructList("test0"); diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/RandomResultSetGenerator.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/RandomResultSetGenerator.java index c3ac655a40e..e783cff25bf 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/RandomResultSetGenerator.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/RandomResultSetGenerator.java @@ -19,6 +19,8 @@ import com.google.cloud.Date; import com.google.cloud.Timestamp; import com.google.cloud.spanner.Dialect; +import com.google.cloud.spanner.SingerProto.Genre; +import com.google.cloud.spanner.SingerProto.SingerInfo; import com.google.common.io.BaseEncoding; import com.google.protobuf.ListValue; import com.google.protobuf.NullValue; @@ -32,6 +34,9 @@ import com.google.spanner.v1.TypeAnnotationCode; import com.google.spanner.v1.TypeCode; import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import java.util.Random; /** @@ -40,73 +45,103 @@ */ public class RandomResultSetGenerator { private static Type[] generateTypes(Dialect dialect) { - return new Type[] { - Type.newBuilder().setCode(TypeCode.BOOL).build(), - Type.newBuilder().setCode(TypeCode.INT64).build(), - Type.newBuilder().setCode(TypeCode.FLOAT64).build(), - dialect == Dialect.POSTGRESQL - ? Type.newBuilder() - .setCode(TypeCode.NUMERIC) - .setTypeAnnotation(TypeAnnotationCode.PG_NUMERIC) - .build() - : Type.newBuilder().setCode(TypeCode.NUMERIC).build(), - Type.newBuilder().setCode(TypeCode.STRING).build(), - dialect == Dialect.POSTGRESQL - ? Type.newBuilder() - .setCode(TypeCode.JSON) - .setTypeAnnotation(TypeAnnotationCode.PG_JSONB) - .build() - : Type.newBuilder().setCode(TypeCode.JSON).build(), - Type.newBuilder().setCode(TypeCode.BYTES).build(), - Type.newBuilder().setCode(TypeCode.DATE).build(), - Type.newBuilder().setCode(TypeCode.TIMESTAMP).build(), - Type.newBuilder() - .setCode(TypeCode.ARRAY) - .setArrayElementType(Type.newBuilder().setCode(TypeCode.BOOL)) - .build(), - Type.newBuilder() - .setCode(TypeCode.ARRAY) - .setArrayElementType(Type.newBuilder().setCode(TypeCode.INT64)) - .build(), - Type.newBuilder() - .setCode(TypeCode.ARRAY) - .setArrayElementType(Type.newBuilder().setCode(TypeCode.FLOAT64)) - .build(), - Type.newBuilder() - .setCode(TypeCode.ARRAY) - .setArrayElementType( - dialect == Dialect.POSTGRESQL - ? Type.newBuilder() - .setCode(TypeCode.NUMERIC) - .setTypeAnnotation(TypeAnnotationCode.PG_NUMERIC) - : Type.newBuilder().setCode(TypeCode.NUMERIC)) - .build(), - Type.newBuilder() - .setCode(TypeCode.ARRAY) - .setArrayElementType(Type.newBuilder().setCode(TypeCode.STRING)) - .build(), - Type.newBuilder() - .setCode(TypeCode.ARRAY) - .setArrayElementType( - dialect == Dialect.POSTGRESQL - ? Type.newBuilder() - .setCode(TypeCode.JSON) - .setTypeAnnotation(TypeAnnotationCode.PG_JSONB) - : Type.newBuilder().setCode(TypeCode.JSON)) - .build(), - Type.newBuilder() - .setCode(TypeCode.ARRAY) - .setArrayElementType(Type.newBuilder().setCode(TypeCode.BYTES)) - .build(), - Type.newBuilder() - .setCode(TypeCode.ARRAY) - .setArrayElementType(Type.newBuilder().setCode(TypeCode.DATE)) - .build(), - Type.newBuilder() - .setCode(TypeCode.ARRAY) - .setArrayElementType(Type.newBuilder().setCode(TypeCode.TIMESTAMP)) - .build(), - }; + List types = + new ArrayList( + Arrays.asList( + Type.newBuilder().setCode(TypeCode.BOOL).build(), + Type.newBuilder().setCode(TypeCode.INT64).build(), + Type.newBuilder().setCode(TypeCode.FLOAT64).build(), + dialect == Dialect.POSTGRESQL + ? Type.newBuilder() + .setCode(TypeCode.NUMERIC) + .setTypeAnnotation(TypeAnnotationCode.PG_NUMERIC) + .build() + : Type.newBuilder().setCode(TypeCode.NUMERIC).build(), + Type.newBuilder().setCode(TypeCode.STRING).build(), + dialect == Dialect.POSTGRESQL + ? Type.newBuilder() + .setCode(TypeCode.JSON) + .setTypeAnnotation(TypeAnnotationCode.PG_JSONB) + .build() + : Type.newBuilder().setCode(TypeCode.JSON).build(), + Type.newBuilder().setCode(TypeCode.BYTES).build(), + Type.newBuilder().setCode(TypeCode.DATE).build(), + Type.newBuilder().setCode(TypeCode.TIMESTAMP).build(), + Type.newBuilder() + .setCode(TypeCode.ARRAY) + .setArrayElementType(Type.newBuilder().setCode(TypeCode.BOOL)) + .build(), + Type.newBuilder() + .setCode(TypeCode.ARRAY) + .setArrayElementType(Type.newBuilder().setCode(TypeCode.INT64)) + .build(), + Type.newBuilder() + .setCode(TypeCode.ARRAY) + .setArrayElementType(Type.newBuilder().setCode(TypeCode.FLOAT64)) + .build(), + Type.newBuilder() + .setCode(TypeCode.ARRAY) + .setArrayElementType( + dialect == Dialect.POSTGRESQL + ? Type.newBuilder() + .setCode(TypeCode.NUMERIC) + .setTypeAnnotation(TypeAnnotationCode.PG_NUMERIC) + : Type.newBuilder().setCode(TypeCode.NUMERIC)) + .build(), + Type.newBuilder() + .setCode(TypeCode.ARRAY) + .setArrayElementType(Type.newBuilder().setCode(TypeCode.STRING)) + .build(), + Type.newBuilder() + .setCode(TypeCode.ARRAY) + .setArrayElementType( + dialect == Dialect.POSTGRESQL + ? Type.newBuilder() + .setCode(TypeCode.JSON) + .setTypeAnnotation(TypeAnnotationCode.PG_JSONB) + : Type.newBuilder().setCode(TypeCode.JSON)) + .build(), + Type.newBuilder() + .setCode(TypeCode.ARRAY) + .setArrayElementType(Type.newBuilder().setCode(TypeCode.BYTES)) + .build(), + Type.newBuilder() + .setCode(TypeCode.ARRAY) + .setArrayElementType(Type.newBuilder().setCode(TypeCode.DATE)) + .build(), + Type.newBuilder() + .setCode(TypeCode.ARRAY) + .setArrayElementType(Type.newBuilder().setCode(TypeCode.TIMESTAMP)) + .build())); + + appendProtoTypes(types, dialect); + Type[] typeArray = new Type[types.size()]; + typeArray = types.toArray(typeArray); + return typeArray; + } + + /** To append Proto & Enum types * */ + private static void appendProtoTypes(List types, Dialect dialect) { + if (dialect == Dialect.GOOGLE_STANDARD_SQL) { + types.add(Type.newBuilder().setCode(TypeCode.PROTO).setProtoTypeFqn("testProto").build()); + types.add(Type.newBuilder().setCode(TypeCode.ENUM).setProtoTypeFqn("testEnum").build()); + types.add( + Type.newBuilder() + .setCode(TypeCode.ARRAY) + .setArrayElementType( + Type.newBuilder() + .setCode(TypeCode.PROTO) + .setProtoTypeFqn(SingerInfo.getDescriptor().getFullName())) + .build()); + types.add( + Type.newBuilder() + .setCode(TypeCode.ARRAY) + .setArrayElementType( + Type.newBuilder() + .setCode(TypeCode.ENUM) + .setProtoTypeFqn(Genre.getDescriptor().getFullName())) + .build()); + } } private static ResultSetMetadata generateMetadata(Type[] types) { @@ -171,6 +206,7 @@ private void setRandomValue(Value.Builder builder, Type type) { break; case STRING: case BYTES: + case PROTO: byte[] bytes = new byte[random.nextInt(200)]; random.nextBytes(bytes); builder.setStringValue(BaseEncoding.base64().encode(bytes)); @@ -199,6 +235,7 @@ private void setRandomValue(Value.Builder builder, Type type) { } break; case INT64: + case ENUM: builder.setStringValue(String.valueOf(random.nextLong())); break; case TIMESTAMP: diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/ReadWriteTransactionTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/ReadWriteTransactionTest.java index aae85bcec62..1fc8d1cb790 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/ReadWriteTransactionTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/ReadWriteTransactionTest.java @@ -40,6 +40,8 @@ import com.google.cloud.spanner.ReadContext.QueryAnalyzeMode; import com.google.cloud.spanner.ResultSet; import com.google.cloud.spanner.ResultSets; +import com.google.cloud.spanner.SingerProto.Genre; +import com.google.cloud.spanner.SingerProto.SingerInfo; import com.google.cloud.spanner.SpannerException; import com.google.cloud.spanner.SpannerExceptionFactory; import com.google.cloud.spanner.Statement; @@ -52,6 +54,7 @@ import com.google.cloud.spanner.Value; import com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement; import com.google.cloud.spanner.connection.AbstractStatementParser.StatementType; +import com.google.protobuf.ProtocolMessageEnum; import com.google.rpc.RetryInfo; import com.google.spanner.v1.ResultSetStats; import io.grpc.Metadata; @@ -499,13 +502,25 @@ public void testChecksumResultSet() { "[{\"color\":\"red\",\"value\":\"#f00\"},{\"color\":\"green\",\"value\":\"#0f0\"},{\"color\":\"blue\",\"value\":\"#00f\"},{\"color\":\"cyan\",\"value\":\"#0ff\"},{\"color\":\"magenta\",\"value\":\"#f0f\"},{\"color\":\"yellow\",\"value\":\"#ff0\"},{\"color\":\"black\",\"value\":\"#000\"}]"; String emptyArrayJson = "[]"; String simpleJson = "{\"color\":\"red\",\"value\":\"#f00\"}"; + SingerInfo protoMessageVal = + SingerInfo.newBuilder() + .setSingerId(111) + .setNationality("COUNTRY1") + .setGenre(Genre.FOLK) + .build(); + ProtocolMessageEnum protoEnumVal = Genre.ROCK; ResultSet delegate1 = ResultSets.forRows( Type.struct( StructField.of("ID", Type.int64()), StructField.of("NAME", Type.string()), StructField.of("AMOUNT", Type.numeric()), - StructField.of("JSON", Type.json())), + StructField.of("JSON", Type.json()), + StructField.of( + "PROTO", Type.proto(protoMessageVal.getDescriptorForType().getFullName())), + StructField.of( + "PROTOENUM", + Type.protoEnum(protoEnumVal.getDescriptorForType().getFullName()))), Arrays.asList( Struct.newBuilder() .set("ID") @@ -516,6 +531,10 @@ public void testChecksumResultSet() { .to(BigDecimal.valueOf(550, 2)) .set("JSON") .to(Value.json(simpleJson)) + .set("PROTO") + .to(protoMessageVal) + .set("PROTOENUM") + .to(protoEnumVal) .build(), Struct.newBuilder() .set("ID") @@ -526,6 +545,10 @@ public void testChecksumResultSet() { .to(BigDecimal.valueOf(750, 2)) .set("JSON") .to(Value.json(arrayJson)) + .set("PROTO") + .to(protoMessageVal) + .set("PROTOENUM") + .to(Genre.JAZZ) .build())); ChecksumResultSet rs1 = transaction.createChecksumResultSet(delegate1, parsedStatement, AnalyzeMode.NONE); @@ -535,7 +558,12 @@ public void testChecksumResultSet() { StructField.of("ID", Type.int64()), StructField.of("NAME", Type.string()), StructField.of("AMOUNT", Type.numeric()), - StructField.of("JSON", Type.json())), + StructField.of("JSON", Type.json()), + StructField.of( + "PROTO", Type.proto(protoMessageVal.getDescriptorForType().getFullName())), + StructField.of( + "PROTOENUM", + Type.protoEnum(protoEnumVal.getDescriptorForType().getFullName()))), Arrays.asList( Struct.newBuilder() .set("ID") @@ -546,6 +574,10 @@ public void testChecksumResultSet() { .to(new BigDecimal("5.50")) .set("JSON") .to(Value.json(simpleJson)) + .set("PROTO") + .to(protoMessageVal) + .set("PROTOENUM") + .to(protoEnumVal) .build(), Struct.newBuilder() .set("ID") @@ -556,6 +588,10 @@ public void testChecksumResultSet() { .to(new BigDecimal("7.50")) .set("JSON") .to(Value.json(arrayJson)) + .set("PROTO") + .to(protoMessageVal) + .set("PROTOENUM") + .to(Genre.JAZZ) .build())); ChecksumResultSet rs2 = transaction.createChecksumResultSet(delegate2, parsedStatement, AnalyzeMode.NONE); @@ -566,7 +602,12 @@ public void testChecksumResultSet() { StructField.of("ID", Type.int64()), StructField.of("NAME", Type.string()), StructField.of("AMOUNT", Type.numeric()), - StructField.of("JSON", Type.json())), + StructField.of("JSON", Type.json()), + StructField.of( + "PROTO", Type.proto(protoMessageVal.getDescriptorForType().getFullName())), + StructField.of( + "PROTOENUM", + Type.protoEnum(protoEnumVal.getDescriptorForType().getFullName()))), Arrays.asList( Struct.newBuilder() .set("ID") @@ -577,6 +618,10 @@ public void testChecksumResultSet() { .to(new BigDecimal("7.50")) .set("JSON") .to(Value.json(arrayJson)) + .set("PROTO") + .to(protoMessageVal) + .set("PROTOENUM") + .to(Genre.JAZZ) .build(), Struct.newBuilder() .set("ID") @@ -587,6 +632,10 @@ public void testChecksumResultSet() { .to(new BigDecimal("5.50")) .set("JSON") .to(Value.json(simpleJson)) + .set("PROTO") + .to(protoMessageVal) + .set("PROTOENUM") + .to(protoEnumVal) .build())); ChecksumResultSet rs3 = transaction.createChecksumResultSet(delegate3, parsedStatement, AnalyzeMode.NONE); @@ -598,7 +647,12 @@ public void testChecksumResultSet() { StructField.of("ID", Type.int64()), StructField.of("NAME", Type.string()), StructField.of("AMOUNT", Type.numeric()), - StructField.of("JSON", Type.json())), + StructField.of("JSON", Type.json()), + StructField.of( + "PROTO", Type.proto(protoMessageVal.getDescriptorForType().getFullName())), + StructField.of( + "PROTOENUM", + Type.protoEnum(protoEnumVal.getDescriptorForType().getFullName()))), Arrays.asList( Struct.newBuilder() .set("ID") @@ -609,6 +663,10 @@ public void testChecksumResultSet() { .to(new BigDecimal("5.50")) .set("JSON") .to(Value.json(simpleJson)) + .set("PROTO") + .to(protoMessageVal) + .set("PROTOENUM") + .to(protoEnumVal) .build(), Struct.newBuilder() .set("ID") @@ -619,6 +677,10 @@ public void testChecksumResultSet() { .to(new BigDecimal("7.50")) .set("JSON") .to(Value.json(arrayJson)) + .set("PROTO") + .to(protoMessageVal) + .set("PROTOENUM") + .to(Genre.JAZZ) .build(), Struct.newBuilder() .set("ID") @@ -629,6 +691,10 @@ public void testChecksumResultSet() { .to(new BigDecimal("9.99")) .set("JSON") .to(Value.json(emptyArrayJson)) + .set("PROTO") + .to(null, SingerInfo.getDescriptor()) + .set("PROTOENUM") + .to(Genre.POP) .build())); ChecksumResultSet rs4 = transaction.createChecksumResultSet(delegate4, parsedStatement, AnalyzeMode.NONE); diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/ReplaceableForwardingResultSetTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/ReplaceableForwardingResultSetTest.java index 3f69c2171e4..bbb34675147 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/ReplaceableForwardingResultSetTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/ReplaceableForwardingResultSetTest.java @@ -26,16 +26,21 @@ import com.google.cloud.spanner.ResultSet; import com.google.cloud.spanner.ResultSets; +import com.google.cloud.spanner.SingerProto.Genre; +import com.google.cloud.spanner.SingerProto.SingerInfo; import com.google.cloud.spanner.SpannerException; import com.google.cloud.spanner.Struct; import com.google.cloud.spanner.Type; import com.google.cloud.spanner.Type.StructField; +import com.google.protobuf.AbstractMessage; +import com.google.protobuf.ProtocolMessageEnum; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.function.Function; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -164,7 +169,7 @@ private void callMethods( boolean exception = false; int numberOfParameters = method.getParameterTypes().length; Class firstParameterType = null; - if (numberOfParameters == 1) { + if (numberOfParameters >= 1) { firstParameterType = method.getParameterTypes()[0]; } try { @@ -181,8 +186,32 @@ private void callMethods( fail("unknown parameter type"); } break; + case 2: + Class secondParameterType = method.getParameterTypes()[1]; + Object firstArgument = null, secondArgument = null; + + if (firstParameterType == String.class) { + firstArgument = "test"; + } else if (firstParameterType == int.class) { + firstArgument = 0; + } + + if (secondParameterType == Function.class) { + Function lambdaFunction = + (val) -> Genre.forNumber(val.intValue()); + secondArgument = lambdaFunction; + } else if (secondParameterType == AbstractMessage.class) { + secondArgument = SingerInfo.getDefaultInstance(); + } + + if (firstArgument != null && secondArgument != null) { + method.invoke(subject, firstArgument, secondArgument); + } else { + fail("unknown parameter type"); + } + break; default: - fail("method with more than 1 parameter is unknown"); + fail("method with more than 2 parameters is unknown"); } } catch (InvocationTargetException e) { if (e.getCause().getClass().equals(expectedException)) { @@ -296,6 +325,25 @@ public void testValidMethodCall() throws IllegalArgumentException { subject.getJsonList("test2"); verify(delegate).getJsonList("test2"); + subject.getProtoMessage(0, SingerInfo.getDefaultInstance()); + verify(delegate).getProtoMessage(0, SingerInfo.getDefaultInstance()); + subject.getProtoMessage("test0", SingerInfo.getDefaultInstance()); + verify(delegate).getProtoMessage("test0", SingerInfo.getDefaultInstance()); + subject.getProtoMessageList(0, SingerInfo.getDefaultInstance()); + verify(delegate).getProtoMessageList(0, SingerInfo.getDefaultInstance()); + subject.getProtoMessageList("test0", SingerInfo.getDefaultInstance()); + verify(delegate).getProtoMessageList("test0", SingerInfo.getDefaultInstance()); + + Function lambdaFunction = Genre::forNumber; + subject.getProtoEnum(0, lambdaFunction); + verify(delegate).getProtoEnum(0, lambdaFunction); + subject.getProtoEnum("test0", lambdaFunction); + verify(delegate).getProtoEnum("test0", lambdaFunction); + subject.getProtoEnumList(0, lambdaFunction); + verify(delegate).getProtoEnumList(0, lambdaFunction); + subject.getProtoEnumList("test0", lambdaFunction); + verify(delegate).getProtoEnumList("test0", lambdaFunction); + subject.getStructList(0); subject.getStructList("test0"); diff --git a/google-cloud-spanner/src/test/resources/com/google/cloud/spanner/singer.proto b/google-cloud-spanner/src/test/resources/com/google/cloud/spanner/singer.proto new file mode 100644 index 00000000000..b62b48ed67f --- /dev/null +++ b/google-cloud-spanner/src/test/resources/com/google/cloud/spanner/singer.proto @@ -0,0 +1,21 @@ +syntax = "proto2"; + +package spanner.examples.music; + +option java_package = "com.google.cloud.spanner"; +option java_outer_classname = "SingerProto"; +option java_multiple_files = false; + +message SingerInfo { + optional int64 singer_id = 1; + optional string birth_date = 2; + optional string nationality = 3; + optional Genre genre = 4; +} + +enum Genre { + POP = 0; + JAZZ = 1; + FOLK = 2; + ROCK = 3; +} diff --git a/proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/Type.java b/proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/Type.java index 7657be926d2..52ab5b34cc9 100644 --- a/proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/Type.java +++ b/proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/Type.java @@ -41,6 +41,7 @@ private Type(com.google.protobuf.GeneratedMessageV3.Builder builder) { private Type() { code_ = 0; typeAnnotation_ = 0; + protoTypeFqn_ = ""; } @java.lang.Override @@ -54,6 +55,96 @@ public final com.google.protobuf.UnknownFieldSet getUnknownFields() { return this.unknownFields; } + private Type( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + this(); + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.protobuf.UnknownFieldSet.newBuilder(); + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 8: + { + int rawValue = input.readEnum(); + + code_ = rawValue; + break; + } + case 18: + { + com.google.spanner.v1.Type.Builder subBuilder = null; + if (arrayElementType_ != null) { + subBuilder = arrayElementType_.toBuilder(); + } + arrayElementType_ = + input.readMessage(com.google.spanner.v1.Type.parser(), extensionRegistry); + if (subBuilder != null) { + subBuilder.mergeFrom(arrayElementType_); + arrayElementType_ = subBuilder.buildPartial(); + } + + break; + } + case 26: + { + com.google.spanner.v1.StructType.Builder subBuilder = null; + if (structType_ != null) { + subBuilder = structType_.toBuilder(); + } + structType_ = + input.readMessage(com.google.spanner.v1.StructType.parser(), extensionRegistry); + if (subBuilder != null) { + subBuilder.mergeFrom(structType_); + structType_ = subBuilder.buildPartial(); + } + + break; + } + case 32: + { + int rawValue = input.readEnum(); + + typeAnnotation_ = rawValue; + break; + } + case 42: + { + java.lang.String s = input.readStringRequireUtf8(); + + protoTypeFqn_ = s; + break; + } + default: + { + if (!parseUnknownField(input, unknownFields, extensionRegistry, tag)) { + done = true; + } + break; + } + } + } + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(this); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(this); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e).setUnfinishedMessage(this); + } finally { + this.unknownFields = unknownFields.build(); + makeExtensionsImmutable(); + } + } + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { return com.google.spanner.v1.TypeProto.internal_static_google_spanner_v1_Type_descriptor; } @@ -249,6 +340,43 @@ public com.google.spanner.v1.TypeAnnotationCode getTypeAnnotation() { return result == null ? com.google.spanner.v1.TypeAnnotationCode.UNRECOGNIZED : result; } + public static final int PROTO_TYPE_FQN_FIELD_NUMBER = 5; + private volatile java.lang.Object protoTypeFqn_; + /** + * string proto_type_fqn = 5; + * + * @return The protoTypeFqn. + */ + @java.lang.Override + public java.lang.String getProtoTypeFqn() { + java.lang.Object ref = protoTypeFqn_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + protoTypeFqn_ = s; + return s; + } + } + /** + * string proto_type_fqn = 5; + * + * @return The bytes for protoTypeFqn. + */ + @java.lang.Override + public com.google.protobuf.ByteString getProtoTypeFqnBytes() { + java.lang.Object ref = protoTypeFqn_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + protoTypeFqn_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + private byte memoizedIsInitialized = -1; @java.lang.Override @@ -276,7 +404,10 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io != com.google.spanner.v1.TypeAnnotationCode.TYPE_ANNOTATION_CODE_UNSPECIFIED.getNumber()) { output.writeEnum(4, typeAnnotation_); } - getUnknownFields().writeTo(output); + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(protoTypeFqn_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 5, protoTypeFqn_); + } + unknownFields.writeTo(output); } @java.lang.Override @@ -298,7 +429,10 @@ public int getSerializedSize() { != com.google.spanner.v1.TypeAnnotationCode.TYPE_ANNOTATION_CODE_UNSPECIFIED.getNumber()) { size += com.google.protobuf.CodedOutputStream.computeEnumSize(4, typeAnnotation_); } - size += getUnknownFields().getSerializedSize(); + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(protoTypeFqn_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(5, protoTypeFqn_); + } + size += unknownFields.getSerializedSize(); memoizedSize = size; return size; } @@ -323,7 +457,8 @@ public boolean equals(final java.lang.Object obj) { if (!getStructType().equals(other.getStructType())) return false; } if (typeAnnotation_ != other.typeAnnotation_) return false; - if (!getUnknownFields().equals(other.getUnknownFields())) return false; + if (!getProtoTypeFqn().equals(other.getProtoTypeFqn())) return false; + if (!unknownFields.equals(other.unknownFields)) return false; return true; } @@ -346,7 +481,9 @@ public int hashCode() { } hash = (37 * hash) + TYPE_ANNOTATION_FIELD_NUMBER; hash = (53 * hash) + typeAnnotation_; - hash = (29 * hash) + getUnknownFields().hashCode(); + hash = (37 * hash) + PROTO_TYPE_FQN_FIELD_NUMBER; + hash = (53 * hash) + getProtoTypeFqn().hashCode(); + hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; } @@ -473,10 +610,17 @@ public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { } // Construct using com.google.spanner.v1.Type.newBuilder() - private Builder() {} + private Builder() { + maybeForceBuilderInitialization(); + } private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { super(parent); + maybeForceBuilderInitialization(); + } + + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders) {} } @java.lang.Override @@ -498,6 +642,8 @@ public Builder clear() { } typeAnnotation_ = 0; + protoTypeFqn_ = ""; + return this; } @@ -535,6 +681,7 @@ public com.google.spanner.v1.Type buildPartial() { result.structType_ = structTypeBuilder_.build(); } result.typeAnnotation_ = typeAnnotation_; + result.protoTypeFqn_ = protoTypeFqn_; onBuilt(); return result; } @@ -596,7 +743,11 @@ public Builder mergeFrom(com.google.spanner.v1.Type other) { if (other.typeAnnotation_ != 0) { setTypeAnnotationValue(other.getTypeAnnotationValue()); } - this.mergeUnknownFields(other.getUnknownFields()); + if (!other.getProtoTypeFqn().isEmpty()) { + protoTypeFqn_ = other.protoTypeFqn_; + onChanged(); + } + this.mergeUnknownFields(other.unknownFields); onChanged(); return this; } @@ -611,56 +762,17 @@ public Builder mergeFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } + com.google.spanner.v1.Type parsedMessage = null; try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - case 8: - { - code_ = input.readEnum(); - - break; - } // case 8 - case 18: - { - input.readMessage( - getArrayElementTypeFieldBuilder().getBuilder(), extensionRegistry); - - break; - } // case 18 - case 26: - { - input.readMessage(getStructTypeFieldBuilder().getBuilder(), extensionRegistry); - - break; - } // case 26 - case 32: - { - typeAnnotation_ = input.readEnum(); - - break; - } // case 32 - default: - { - if (!super.parseUnknownField(input, extensionRegistry, tag)) { - done = true; // was an endgroup tag - } - break; - } // default: - } // switch (tag) - } // while (!done) + parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); } catch (com.google.protobuf.InvalidProtocolBufferException e) { + parsedMessage = (com.google.spanner.v1.Type) e.getUnfinishedMessage(); throw e.unwrapIOException(); } finally { - onChanged(); - } // finally + if (parsedMessage != null) { + mergeFrom(parsedMessage); + } + } return this; } @@ -1258,6 +1370,82 @@ public Builder clearTypeAnnotation() { return this; } + private java.lang.Object protoTypeFqn_ = ""; + /** + * string proto_type_fqn = 5; + * + * @return The protoTypeFqn. + */ + public java.lang.String getProtoTypeFqn() { + java.lang.Object ref = protoTypeFqn_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + protoTypeFqn_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * string proto_type_fqn = 5; + * + * @return The bytes for protoTypeFqn. + */ + public com.google.protobuf.ByteString getProtoTypeFqnBytes() { + java.lang.Object ref = protoTypeFqn_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + protoTypeFqn_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string proto_type_fqn = 5; + * + * @param value The protoTypeFqn to set. + * @return This builder for chaining. + */ + public Builder setProtoTypeFqn(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + protoTypeFqn_ = value; + onChanged(); + return this; + } + /** + * string proto_type_fqn = 5; + * + * @return This builder for chaining. + */ + public Builder clearProtoTypeFqn() { + + protoTypeFqn_ = getDefaultInstance().getProtoTypeFqn(); + onChanged(); + return this; + } + /** + * string proto_type_fqn = 5; + * + * @param value The bytes for protoTypeFqn to set. + * @return This builder for chaining. + */ + public Builder setProtoTypeFqnBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + protoTypeFqn_ = value; + onChanged(); + return this; + } + @java.lang.Override public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { return super.setUnknownFields(unknownFields); @@ -1290,18 +1478,7 @@ public Type parsePartialFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { - Builder builder = newBuilder(); - try { - builder.mergeFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(builder.buildPartial()); - } catch (com.google.protobuf.UninitializedMessageException e) { - throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException(e) - .setUnfinishedMessage(builder.buildPartial()); - } - return builder.buildPartial(); + return new Type(input, extensionRegistry); } }; diff --git a/proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/TypeCode.java b/proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/TypeCode.java index 4b6561e9def..7702f2257b4 100644 --- a/proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/TypeCode.java +++ b/proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/TypeCode.java @@ -177,6 +177,10 @@ public enum TypeCode implements com.google.protobuf.ProtocolMessageEnum { * JSON = 11; */ JSON(11), + /** PROTO = 13; */ + PROTO(13), + /** ENUM = 14; */ + ENUM(14), UNRECOGNIZED(-1), ; @@ -324,6 +328,10 @@ public enum TypeCode implements com.google.protobuf.ProtocolMessageEnum { * JSON = 11; */ public static final int JSON_VALUE = 11; + /** PROTO = 13; */ + public static final int PROTO_VALUE = 13; + /** ENUM = 14; */ + public static final int ENUM_VALUE = 14; public final int getNumber() { if (this == UNRECOGNIZED) { @@ -373,6 +381,10 @@ public static TypeCode forNumber(int value) { return NUMERIC; case 11: return JSON; + case 13: + return PROTO; + case 14: + return ENUM; default: return null; } diff --git a/proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/TypeOrBuilder.java b/proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/TypeOrBuilder.java index 4c78a470d6d..0c705016caf 100644 --- a/proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/TypeOrBuilder.java +++ b/proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/TypeOrBuilder.java @@ -158,4 +158,17 @@ public interface TypeOrBuilder * @return The typeAnnotation. */ com.google.spanner.v1.TypeAnnotationCode getTypeAnnotation(); + + /** + * string proto_type_fqn = 5; + * + * @return The protoTypeFqn. + */ + java.lang.String getProtoTypeFqn(); + /** + * string proto_type_fqn = 5; + * + * @return The bytes for protoTypeFqn. + */ + com.google.protobuf.ByteString getProtoTypeFqnBytes(); } diff --git a/proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/TypeProto.java b/proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/TypeProto.java index ebca4e75d38..63aa67d3fee 100644 --- a/proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/TypeProto.java +++ b/proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/TypeProto.java @@ -50,27 +50,28 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { java.lang.String[] descriptorData = { "\n\034google/spanner/v1/type.proto\022\021google.s" + "panner.v1\032\037google/api/field_behavior.pro" - + "to\"\337\001\n\004Type\022.\n\004code\030\001 \001(\0162\033.google.spann" + + "to\"\367\001\n\004Type\022.\n\004code\030\001 \001(\0162\033.google.spann" + "er.v1.TypeCodeB\003\340A\002\0223\n\022array_element_typ" + "e\030\002 \001(\0132\027.google.spanner.v1.Type\0222\n\013stru" + "ct_type\030\003 \001(\0132\035.google.spanner.v1.Struct" + "Type\022>\n\017type_annotation\030\004 \001(\0162%.google.s" - + "panner.v1.TypeAnnotationCode\"\177\n\nStructTy" - + "pe\0223\n\006fields\030\001 \003(\0132#.google.spanner.v1.S" - + "tructType.Field\032<\n\005Field\022\014\n\004name\030\001 \001(\t\022%" - + "\n\004type\030\002 \001(\0132\027.google.spanner.v1.Type*\245\001" - + "\n\010TypeCode\022\031\n\025TYPE_CODE_UNSPECIFIED\020\000\022\010\n" - + "\004BOOL\020\001\022\t\n\005INT64\020\002\022\013\n\007FLOAT64\020\003\022\r\n\tTIMES" - + "TAMP\020\004\022\010\n\004DATE\020\005\022\n\n\006STRING\020\006\022\t\n\005BYTES\020\007\022" - + "\t\n\005ARRAY\020\010\022\n\n\006STRUCT\020\t\022\013\n\007NUMERIC\020\n\022\010\n\004J" - + "SON\020\013*X\n\022TypeAnnotationCode\022$\n TYPE_ANNO" - + "TATION_CODE_UNSPECIFIED\020\000\022\016\n\nPG_NUMERIC\020" - + "\002\022\014\n\010PG_JSONB\020\003B\257\001\n\025com.google.spanner.v" - + "1B\tTypeProtoP\001Z8google.golang.org/genpro" - + "to/googleapis/spanner/v1;spanner\252\002\027Googl" - + "e.Cloud.Spanner.V1\312\002\027Google\\Cloud\\Spanne" - + "r\\V1\352\002\032Google::Cloud::Spanner::V1b\006proto" - + "3" + + "panner.v1.TypeAnnotationCode\022\026\n\016proto_ty" + + "pe_fqn\030\005 \001(\t\"\177\n\nStructType\0223\n\006fields\030\001 \003" + + "(\0132#.google.spanner.v1.StructType.Field\032" + + "<\n\005Field\022\014\n\004name\030\001 \001(\t\022%\n\004type\030\002 \001(\0132\027.g" + + "oogle.spanner.v1.Type*\272\001\n\010TypeCode\022\031\n\025TY" + + "PE_CODE_UNSPECIFIED\020\000\022\010\n\004BOOL\020\001\022\t\n\005INT64" + + "\020\002\022\013\n\007FLOAT64\020\003\022\r\n\tTIMESTAMP\020\004\022\010\n\004DATE\020\005" + + "\022\n\n\006STRING\020\006\022\t\n\005BYTES\020\007\022\t\n\005ARRAY\020\010\022\n\n\006ST" + + "RUCT\020\t\022\013\n\007NUMERIC\020\n\022\010\n\004JSON\020\013\022\t\n\005PROTO\020\r" + + "\022\010\n\004ENUM\020\016*X\n\022TypeAnnotationCode\022$\n TYPE" + + "_ANNOTATION_CODE_UNSPECIFIED\020\000\022\016\n\nPG_NUM" + + "ERIC\020\002\022\014\n\010PG_JSONB\020\003B\257\001\n\025com.google.span" + + "ner.v1B\tTypeProtoP\001Z8google.golang.org/g" + + "enproto/googleapis/spanner/v1;spanner\252\002\027" + + "Google.Cloud.Spanner.V1\312\002\027Google\\Cloud\\S" + + "panner\\V1\352\002\032Google::Cloud::Spanner::V1b\006" + + "proto3" }; descriptor = com.google.protobuf.Descriptors.FileDescriptor.internalBuildGeneratedFileFrom( @@ -83,7 +84,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_spanner_v1_Type_descriptor, new java.lang.String[] { - "Code", "ArrayElementType", "StructType", "TypeAnnotation", + "Code", "ArrayElementType", "StructType", "TypeAnnotation", "ProtoTypeFqn", }); internal_static_google_spanner_v1_StructType_descriptor = getDescriptor().getMessageTypes().get(1); diff --git a/proto-google-cloud-spanner-v1/src/main/proto/google/spanner/v1/type.proto b/proto-google-cloud-spanner-v1/src/main/proto/google/spanner/v1/type.proto index 712ec187fcc..0f2cd64ebad 100644 --- a/proto-google-cloud-spanner-v1/src/main/proto/google/spanner/v1/type.proto +++ b/proto-google-cloud-spanner-v1/src/main/proto/google/spanner/v1/type.proto @@ -47,6 +47,11 @@ message Type { // typically is not needed to process the content of a value (it doesn't // affect serialization) and clients can ignore it on the read path. TypeAnnotationCode type_annotation = 4; + + // If [code][] == [PROTO][TypeCode.PROTO] or [code][] == + // [ENUM][TypeCode.ENUM], then `proto_type_fqn` is the fully qualified name of + // the proto type representing the proto/enum definition. + string proto_type_fqn = 5; } // `StructType` defines the fields of a [STRUCT][google.spanner.v1.TypeCode.STRUCT] type. @@ -145,6 +150,13 @@ enum TypeCode { // preserved. // - JSON array elements will have their order preserved. JSON = 11; + + // Encoded as a base64-encoded `string`, as described in RFC 4648, + // section 4. + PROTO = 13; + + // Encoded as `string`, in decimal format. + ENUM = 14; } // `TypeAnnotationCode` is used as a part of [Type][google.spanner.v1.Type] to From 1fb6e9411561b4594266f004d699d3f8da16e356 Mon Sep 17 00:00:00 2001 From: Gaurav Purohit Date: Thu, 5 Jan 2023 15:14:11 +0530 Subject: [PATCH 02/27] samples: Adding samples for updating & querying Proto messages & enums (#2211) * samples: Adding samples for updating & querying Proto messages & enums * style: linting * style: linting * docs: Adding function and class doc --- .../spanner/QueryProtoColumnSample.java | 78 + .../java/com/example/spanner/SingerProto.java | 1271 +++++++++++++++++ .../spanner/UpdateProtoColumnSample.java | 83 ++ 3 files changed, 1432 insertions(+) create mode 100644 samples/snippets/src/main/java/com/example/spanner/QueryProtoColumnSample.java create mode 100644 samples/snippets/src/main/java/com/example/spanner/SingerProto.java create mode 100644 samples/snippets/src/main/java/com/example/spanner/UpdateProtoColumnSample.java diff --git a/samples/snippets/src/main/java/com/example/spanner/QueryProtoColumnSample.java b/samples/snippets/src/main/java/com/example/spanner/QueryProtoColumnSample.java new file mode 100644 index 00000000000..d5001cc6ddc --- /dev/null +++ b/samples/snippets/src/main/java/com/example/spanner/QueryProtoColumnSample.java @@ -0,0 +1,78 @@ +/* + * Copyright 2022 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.example.spanner; + +import com.example.spanner.SingerProto.Genre; +import com.example.spanner.SingerProto.SingerInfo; +import com.google.cloud.spanner.DatabaseClient; +import com.google.cloud.spanner.DatabaseId; +import com.google.cloud.spanner.ResultSet; +import com.google.cloud.spanner.Spanner; +import com.google.cloud.spanner.SpannerOptions; +import com.google.cloud.spanner.Statement; + +/** + * To query Proto column including messages and enums and array of them. + */ +public class QueryProtoColumnSample { + + static void queryProtoColumn() { + // TODO(developer): Replace these variables before running the sample. + String projectId = "my-project"; + String instanceId = "my-instance"; + String databaseId = "my-database"; + + try (Spanner spanner = + SpannerOptions.newBuilder().setProjectId(projectId).build().getService()) { + DatabaseClient client = + spanner.getDatabaseClient(DatabaseId.of(projectId, instanceId, databaseId)); + queryProtoColumn(client); + } + } + + /** + * Method to query Singer Table using DQL. + * + * Assuming a table Singer with columns with following DDL: + * CREATE TABLE Singer ( + * singer_id INT64 NOT NULL, + * singer_info spanner.examples.music.SingerInfo, + * genre spanner.examples.music.Genre, + * singer_info_list ARRAY, + * genre_list ARRAY, + * ) PRIMARY KEY (singer_id); + */ + static void queryProtoColumn(DatabaseClient client) { + Statement statement = + Statement.newBuilder( + "SELECT singer_id, singer_info, genre, singer_info_list, genre_list\n" + + "FROM Singer") + .build(); + + try (ResultSet resultSet = client.singleUse().executeQuery(statement)) { + while (resultSet.next()) { + System.out.printf( + "singer_id: %s, singer_info: %s , genre: %s, " + + "singer_info_list: %s, genre_list: %s%n ", + resultSet.getLong("singer_id"), + resultSet.getProtoMessage("singer_info", SingerInfo.getDefaultInstance()), + resultSet.getProtoEnum("genre", Genre::forNumber), + resultSet.getProtoMessageList("singer_info_list", SingerInfo.getDefaultInstance()), + resultSet.getProtoEnumList("genre_list", Genre::forNumber)); + } + } + } +} diff --git a/samples/snippets/src/main/java/com/example/spanner/SingerProto.java b/samples/snippets/src/main/java/com/example/spanner/SingerProto.java new file mode 100644 index 00000000000..93f2bfaa8b8 --- /dev/null +++ b/samples/snippets/src/main/java/com/example/spanner/SingerProto.java @@ -0,0 +1,1271 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: src/test/resources/com/google/cloud/spanner/singer.proto +package com.example.spanner; + +public final class SingerProto { + + private static final com.google.protobuf.Descriptors.Descriptor + internal_static_spanner_examples_music_SingerInfo_descriptor; + private static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_spanner_examples_music_SingerInfo_fieldAccessorTable; + private static com.google.protobuf.Descriptors.FileDescriptor descriptor; + + static { + java.lang.String[] descriptorData = { + "\n\014singer.proto\022\026spanner.examples.music\"v" + + "\n\nSingerInfo\022\021\n\tsinger_id\030\001 \001(\003\022\022\n\nbirth" + + "_date\030\002 \001(\t\022\023\n\013nationality\030\003 \001(\t\022,\n\005genr" + + "e\030\004 \001(\0162\035.spanner.examples.music.Genre*." + + "\n\005Genre\022\007\n\003POP\020\000\022\010\n\004JAZZ\020\001\022\010\n\004FOLK\020\002\022\010\n\004" + + "ROCK\020\003B)\n\030com.example.spannerB\013Sing" + + "erProtoP\000" + }; + descriptor = + com.google.protobuf.Descriptors.FileDescriptor.internalBuildGeneratedFileFrom( + descriptorData, new com.google.protobuf.Descriptors.FileDescriptor[]{}); + internal_static_spanner_examples_music_SingerInfo_descriptor = + getDescriptor().getMessageTypes().get(0); + internal_static_spanner_examples_music_SingerInfo_fieldAccessorTable = + new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_spanner_examples_music_SingerInfo_descriptor, + new java.lang.String[]{ + "SingerId", "BirthDate", "Nationality", "Genre", + }); + } + + private SingerProto() { + } + + public static void registerAllExtensions(com.google.protobuf.ExtensionRegistryLite registry) { + } + + public static void registerAllExtensions(com.google.protobuf.ExtensionRegistry registry) { + registerAllExtensions((com.google.protobuf.ExtensionRegistryLite) registry); + } + + public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { + return descriptor; + } + + /** + * Protobuf enum {@code spanner.examples.music.Genre} + */ + public enum Genre implements com.google.protobuf.ProtocolMessageEnum { + /** + * POP = 0; + */ + POP(0), + /** + * JAZZ = 1; + */ + JAZZ(1), + /** + * FOLK = 2; + */ + FOLK(2), + /** + * ROCK = 3; + */ + ROCK(3), + ; + + /** + * POP = 0; + */ + public static final int POP_VALUE = 0; + /** + * JAZZ = 1; + */ + public static final int JAZZ_VALUE = 1; + /** + * FOLK = 2; + */ + public static final int FOLK_VALUE = 2; + /** + * ROCK = 3; + */ + public static final int ROCK_VALUE = 3; + private static final com.google.protobuf.Internal.EnumLiteMap internalValueMap = + new com.google.protobuf.Internal.EnumLiteMap() { + public Genre findValueByNumber(int number) { + return Genre.forNumber(number); + } + }; + private static final Genre[] VALUES = values(); + private final int value; + + private Genre(int value) { + this.value = value; + } + + /** + * @param value The numeric wire value of the corresponding enum entry. + * @return The enum associated with the given numeric wire value. + * @deprecated Use {@link #forNumber(int)} instead. + */ + @java.lang.Deprecated + public static Genre valueOf(int value) { + return forNumber(value); + } + + /** + * @param value The numeric wire value of the corresponding enum entry. + * @return The enum associated with the given numeric wire value. + */ + public static Genre forNumber(int value) { + switch (value) { + case 0: + return POP; + case 1: + return JAZZ; + case 2: + return FOLK; + case 3: + return ROCK; + default: + return null; + } + } + + public static com.google.protobuf.Internal.EnumLiteMap internalGetValueMap() { + return internalValueMap; + } + + public static final com.google.protobuf.Descriptors.EnumDescriptor getDescriptor() { + return com.example.spanner.SingerProto.getDescriptor().getEnumTypes().get(0); + } + + public static Genre valueOf(com.google.protobuf.Descriptors.EnumValueDescriptor desc) { + if (desc.getType() != getDescriptor()) { + throw new java.lang.IllegalArgumentException("EnumValueDescriptor is not for this type."); + } + return VALUES[desc.getIndex()]; + } + + public final int getNumber() { + return value; + } + + public final com.google.protobuf.Descriptors.EnumValueDescriptor getValueDescriptor() { + return getDescriptor().getValues().get(ordinal()); + } + + public final com.google.protobuf.Descriptors.EnumDescriptor getDescriptorForType() { + return getDescriptor(); + } + + // @@protoc_insertion_point(enum_scope:spanner.examples.music.Genre) + } + + public interface SingerInfoOrBuilder + extends + // @@protoc_insertion_point(interface_extends:spanner.examples.music.SingerInfo) + com.google.protobuf.MessageOrBuilder { + + /** + * optional int64 singer_id = 1; + * + * @return Whether the singerId field is set. + */ + boolean hasSingerId(); + + /** + * optional int64 singer_id = 1; + * + * @return The singerId. + */ + long getSingerId(); + + /** + * optional string birth_date = 2; + * + * @return Whether the birthDate field is set. + */ + boolean hasBirthDate(); + + /** + * optional string birth_date = 2; + * + * @return The birthDate. + */ + java.lang.String getBirthDate(); + + /** + * optional string birth_date = 2; + * + * @return The bytes for birthDate. + */ + com.google.protobuf.ByteString getBirthDateBytes(); + + /** + * optional string nationality = 3; + * + * @return Whether the nationality field is set. + */ + boolean hasNationality(); + + /** + * optional string nationality = 3; + * + * @return The nationality. + */ + java.lang.String getNationality(); + + /** + * optional string nationality = 3; + * + * @return The bytes for nationality. + */ + com.google.protobuf.ByteString getNationalityBytes(); + + /** + * optional .spanner.examples.music.Genre genre = 4; + * + * @return Whether the genre field is set. + */ + boolean hasGenre(); + + /** + * optional .spanner.examples.music.Genre genre = 4; + * + * @return The genre. + */ + com.example.spanner.SingerProto.Genre getGenre(); + } + + /** + * Protobuf type {@code spanner.examples.music.SingerInfo} + */ + public static final class SingerInfo extends com.google.protobuf.GeneratedMessageV3 + implements + // @@protoc_insertion_point(message_implements:spanner.examples.music.SingerInfo) + SingerInfoOrBuilder { + + public static final int SINGER_ID_FIELD_NUMBER = 1; + public static final int BIRTH_DATE_FIELD_NUMBER = 2; + public static final int NATIONALITY_FIELD_NUMBER = 3; + public static final int GENRE_FIELD_NUMBER = 4; + @java.lang.Deprecated + public static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + @java.lang.Override + public SingerInfo parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return new SingerInfo(input, extensionRegistry); + } + }; + private static final long serialVersionUID = 0L; + // @@protoc_insertion_point(class_scope:spanner.examples.music.SingerInfo) + private static final com.example.spanner.SingerProto.SingerInfo DEFAULT_INSTANCE; + + static { + DEFAULT_INSTANCE = new com.example.spanner.SingerProto.SingerInfo(); + } + + private int bitField0_; + private long singerId_; + private volatile java.lang.Object birthDate_; + private volatile java.lang.Object nationality_; + private int genre_; + private byte memoizedIsInitialized = -1; + // Use SingerInfo.newBuilder() to construct. + private SingerInfo(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + + private SingerInfo() { + birthDate_ = ""; + nationality_ = ""; + genre_ = 0; + } + + private SingerInfo( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + this(); + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + int mutable_bitField0_ = 0; + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.protobuf.UnknownFieldSet.newBuilder(); + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 8: { + bitField0_ |= 0x00000001; + singerId_ = input.readInt64(); + break; + } + case 18: { + com.google.protobuf.ByteString bs = input.readBytes(); + bitField0_ |= 0x00000002; + birthDate_ = bs; + break; + } + case 26: { + com.google.protobuf.ByteString bs = input.readBytes(); + bitField0_ |= 0x00000004; + nationality_ = bs; + break; + } + case 32: { + int rawValue = input.readEnum(); + @SuppressWarnings("deprecation") + com.example.spanner.SingerProto.Genre value = + com.example.spanner.SingerProto.Genre.valueOf(rawValue); + if (value == null) { + unknownFields.mergeVarintField(4, rawValue); + } else { + bitField0_ |= 0x00000008; + genre_ = rawValue; + } + break; + } + default: { + if (!parseUnknownField(input, unknownFields, extensionRegistry, tag)) { + done = true; + } + break; + } + } + } + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(this); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e).setUnfinishedMessage(this); + } finally { + this.unknownFields = unknownFields.build(); + makeExtensionsImmutable(); + } + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.example.spanner.SingerProto + .internal_static_spanner_examples_music_SingerInfo_descriptor; + } + + public static com.example.spanner.SingerProto.SingerInfo parseFrom(java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.example.spanner.SingerProto.SingerInfo parseFrom( + java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.example.spanner.SingerProto.SingerInfo parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.example.spanner.SingerProto.SingerInfo parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.example.spanner.SingerProto.SingerInfo parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.example.spanner.SingerProto.SingerInfo parseFrom( + byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.example.spanner.SingerProto.SingerInfo parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.example.spanner.SingerProto.SingerInfo parseFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.example.spanner.SingerProto.SingerInfo parseDelimitedFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); + } + + public static com.example.spanner.SingerProto.SingerInfo parseDelimitedFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.example.spanner.SingerProto.SingerInfo parseFrom( + com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.example.spanner.SingerProto.SingerInfo parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder(com.example.spanner.SingerProto.SingerInfo prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + public static com.example.spanner.SingerProto.SingerInfo getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance(UnusedPrivateParameter unused) { + return new SingerInfo(); + } + + @java.lang.Override + public final com.google.protobuf.UnknownFieldSet getUnknownFields() { + return this.unknownFields; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.example.spanner.SingerProto + .internal_static_spanner_examples_music_SingerInfo_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.example.spanner.SingerProto.SingerInfo.class, + com.example.spanner.SingerProto.SingerInfo.Builder.class); + } + + /** + * optional int64 singer_id = 1; + * + * @return Whether the singerId field is set. + */ + @java.lang.Override + public boolean hasSingerId() { + return ((bitField0_ & 0x00000001) != 0); + } + + /** + * optional int64 singer_id = 1; + * + * @return The singerId. + */ + @java.lang.Override + public long getSingerId() { + return singerId_; + } + + /** + * optional string birth_date = 2; + * + * @return Whether the birthDate field is set. + */ + @java.lang.Override + public boolean hasBirthDate() { + return ((bitField0_ & 0x00000002) != 0); + } + + /** + * optional string birth_date = 2; + * + * @return The birthDate. + */ + @java.lang.Override + public java.lang.String getBirthDate() { + java.lang.Object ref = birthDate_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + birthDate_ = s; + } + return s; + } + } + + /** + * optional string birth_date = 2; + * + * @return The bytes for birthDate. + */ + @java.lang.Override + public com.google.protobuf.ByteString getBirthDateBytes() { + java.lang.Object ref = birthDate_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + birthDate_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + /** + * optional string nationality = 3; + * + * @return Whether the nationality field is set. + */ + @java.lang.Override + public boolean hasNationality() { + return ((bitField0_ & 0x00000004) != 0); + } + + /** + * optional string nationality = 3; + * + * @return The nationality. + */ + @java.lang.Override + public java.lang.String getNationality() { + java.lang.Object ref = nationality_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + nationality_ = s; + } + return s; + } + } + + /** + * optional string nationality = 3; + * + * @return The bytes for nationality. + */ + @java.lang.Override + public com.google.protobuf.ByteString getNationalityBytes() { + java.lang.Object ref = nationality_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + nationality_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + /** + * optional .spanner.examples.music.Genre genre = 4; + * + * @return Whether the genre field is set. + */ + @java.lang.Override + public boolean hasGenre() { + return ((bitField0_ & 0x00000008) != 0); + } + + /** + * optional .spanner.examples.music.Genre genre = 4; + * + * @return The genre. + */ + @java.lang.Override + public com.example.spanner.SingerProto.Genre getGenre() { + @SuppressWarnings("deprecation") + com.example.spanner.SingerProto.Genre result = + com.example.spanner.SingerProto.Genre.valueOf(genre_); + return result == null ? com.example.spanner.SingerProto.Genre.POP : result; + } + + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) { + return true; + } + if (isInitialized == 0) { + return false; + } + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + if (((bitField0_ & 0x00000001) != 0)) { + output.writeInt64(1, singerId_); + } + if (((bitField0_ & 0x00000002) != 0)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 2, birthDate_); + } + if (((bitField0_ & 0x00000004) != 0)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 3, nationality_); + } + if (((bitField0_ & 0x00000008) != 0)) { + output.writeEnum(4, genre_); + } + unknownFields.writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) { + return size; + } + + size = 0; + if (((bitField0_ & 0x00000001) != 0)) { + size += com.google.protobuf.CodedOutputStream.computeInt64Size(1, singerId_); + } + if (((bitField0_ & 0x00000002) != 0)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, birthDate_); + } + if (((bitField0_ & 0x00000004) != 0)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, nationality_); + } + if (((bitField0_ & 0x00000008) != 0)) { + size += com.google.protobuf.CodedOutputStream.computeEnumSize(4, genre_); + } + size += unknownFields.getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof com.example.spanner.SingerProto.SingerInfo)) { + return super.equals(obj); + } + com.example.spanner.SingerProto.SingerInfo other = + (com.example.spanner.SingerProto.SingerInfo) obj; + + if (hasSingerId() != other.hasSingerId()) { + return false; + } + if (hasSingerId()) { + if (getSingerId() != other.getSingerId()) { + return false; + } + } + if (hasBirthDate() != other.hasBirthDate()) { + return false; + } + if (hasBirthDate()) { + if (!getBirthDate().equals(other.getBirthDate())) { + return false; + } + } + if (hasNationality() != other.hasNationality()) { + return false; + } + if (hasNationality()) { + if (!getNationality().equals(other.getNationality())) { + return false; + } + } + if (hasGenre() != other.hasGenre()) { + return false; + } + if (hasGenre()) { + if (genre_ != other.genre_) { + return false; + } + } + if (!unknownFields.equals(other.unknownFields)) { + return false; + } + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + if (hasSingerId()) { + hash = (37 * hash) + SINGER_ID_FIELD_NUMBER; + hash = (53 * hash) + com.google.protobuf.Internal.hashLong(getSingerId()); + } + if (hasBirthDate()) { + hash = (37 * hash) + BIRTH_DATE_FIELD_NUMBER; + hash = (53 * hash) + getBirthDate().hashCode(); + } + if (hasNationality()) { + hash = (37 * hash) + NATIONALITY_FIELD_NUMBER; + hash = (53 * hash) + getNationality().hashCode(); + } + if (hasGenre()) { + hash = (37 * hash) + GENRE_FIELD_NUMBER; + hash = (53 * hash) + genre_; + } + hash = (29 * hash) + unknownFields.hashCode(); + memoizedHashCode = hash; + return hash; + } + + @java.lang.Override + public Builder newBuilderForType() { + return newBuilder(); + } + + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public com.example.spanner.SingerProto.SingerInfo getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + + /** + * Protobuf type {@code spanner.examples.music.SingerInfo} + */ + public static final class Builder + extends com.google.protobuf.GeneratedMessageV3.Builder + implements + // @@protoc_insertion_point(builder_implements:spanner.examples.music.SingerInfo) + com.example.spanner.SingerProto.SingerInfoOrBuilder { + + private int bitField0_; + private long singerId_; + private java.lang.Object birthDate_ = ""; + private java.lang.Object nationality_ = ""; + private int genre_ = 0; + + // Construct using com.example.spanner.SingerProto.SingerInfo.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.example.spanner.SingerProto + .internal_static_spanner_examples_music_SingerInfo_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.example.spanner.SingerProto + .internal_static_spanner_examples_music_SingerInfo_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.example.spanner.SingerProto.SingerInfo.class, + com.example.spanner.SingerProto.SingerInfo.Builder.class); + } + + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders) { + } + } + + @java.lang.Override + public Builder clear() { + super.clear(); + singerId_ = 0L; + bitField0_ = (bitField0_ & ~0x00000001); + birthDate_ = ""; + bitField0_ = (bitField0_ & ~0x00000002); + nationality_ = ""; + bitField0_ = (bitField0_ & ~0x00000004); + genre_ = 0; + bitField0_ = (bitField0_ & ~0x00000008); + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return com.example.spanner.SingerProto + .internal_static_spanner_examples_music_SingerInfo_descriptor; + } + + @java.lang.Override + public com.example.spanner.SingerProto.SingerInfo getDefaultInstanceForType() { + return com.example.spanner.SingerProto.SingerInfo.getDefaultInstance(); + } + + @java.lang.Override + public com.example.spanner.SingerProto.SingerInfo build() { + com.example.spanner.SingerProto.SingerInfo result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public com.example.spanner.SingerProto.SingerInfo buildPartial() { + com.example.spanner.SingerProto.SingerInfo result = + new com.example.spanner.SingerProto.SingerInfo(this); + int from_bitField0_ = bitField0_; + int to_bitField0_ = 0; + if (((from_bitField0_ & 0x00000001) != 0)) { + result.singerId_ = singerId_; + to_bitField0_ |= 0x00000001; + } + if (((from_bitField0_ & 0x00000002) != 0)) { + to_bitField0_ |= 0x00000002; + } + result.birthDate_ = birthDate_; + if (((from_bitField0_ & 0x00000004) != 0)) { + to_bitField0_ |= 0x00000004; + } + result.nationality_ = nationality_; + if (((from_bitField0_ & 0x00000008) != 0)) { + to_bitField0_ |= 0x00000008; + } + result.genre_ = genre_; + result.bitField0_ = to_bitField0_; + onBuilt(); + return result; + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.setField(field, value); + } + + @java.lang.Override + public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + + @java.lang.Override + public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + int index, + java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.addRepeatedField(field, value); + } + + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.example.spanner.SingerProto.SingerInfo) { + return mergeFrom((com.example.spanner.SingerProto.SingerInfo) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.example.spanner.SingerProto.SingerInfo other) { + if (other == com.example.spanner.SingerProto.SingerInfo.getDefaultInstance()) { + return this; + } + if (other.hasSingerId()) { + setSingerId(other.getSingerId()); + } + if (other.hasBirthDate()) { + bitField0_ |= 0x00000002; + birthDate_ = other.birthDate_; + onChanged(); + } + if (other.hasNationality()) { + bitField0_ |= 0x00000004; + nationality_ = other.nationality_; + onChanged(); + } + if (other.hasGenre()) { + setGenre(other.getGenre()); + } + this.mergeUnknownFields(other.unknownFields); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + com.example.spanner.SingerProto.SingerInfo parsedMessage = null; + try { + parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + parsedMessage = (com.example.spanner.SingerProto.SingerInfo) e.getUnfinishedMessage(); + throw e.unwrapIOException(); + } finally { + if (parsedMessage != null) { + mergeFrom(parsedMessage); + } + } + return this; + } + + /** + * optional int64 singer_id = 1; + * + * @return Whether the singerId field is set. + */ + @java.lang.Override + public boolean hasSingerId() { + return ((bitField0_ & 0x00000001) != 0); + } + + /** + * optional int64 singer_id = 1; + * + * @return The singerId. + */ + @java.lang.Override + public long getSingerId() { + return singerId_; + } + + /** + * optional int64 singer_id = 1; + * + * @param value The singerId to set. + * @return This builder for chaining. + */ + public Builder setSingerId(long value) { + bitField0_ |= 0x00000001; + singerId_ = value; + onChanged(); + return this; + } + + /** + * optional int64 singer_id = 1; + * + * @return This builder for chaining. + */ + public Builder clearSingerId() { + bitField0_ = (bitField0_ & ~0x00000001); + singerId_ = 0L; + onChanged(); + return this; + } + + /** + * optional string birth_date = 2; + * + * @return Whether the birthDate field is set. + */ + public boolean hasBirthDate() { + return ((bitField0_ & 0x00000002) != 0); + } + + /** + * optional string birth_date = 2; + * + * @return The birthDate. + */ + public java.lang.String getBirthDate() { + java.lang.Object ref = birthDate_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + birthDate_ = s; + } + return s; + } else { + return (java.lang.String) ref; + } + } + + /** + * optional string birth_date = 2; + * + * @param value The birthDate to set. + * @return This builder for chaining. + */ + public Builder setBirthDate(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000002; + birthDate_ = value; + onChanged(); + return this; + } + + /** + * optional string birth_date = 2; + * + * @return The bytes for birthDate. + */ + public com.google.protobuf.ByteString getBirthDateBytes() { + java.lang.Object ref = birthDate_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + birthDate_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + /** + * optional string birth_date = 2; + * + * @param value The bytes for birthDate to set. + * @return This builder for chaining. + */ + public Builder setBirthDateBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000002; + birthDate_ = value; + onChanged(); + return this; + } + + /** + * optional string birth_date = 2; + * + * @return This builder for chaining. + */ + public Builder clearBirthDate() { + bitField0_ = (bitField0_ & ~0x00000002); + birthDate_ = getDefaultInstance().getBirthDate(); + onChanged(); + return this; + } + + /** + * optional string nationality = 3; + * + * @return Whether the nationality field is set. + */ + public boolean hasNationality() { + return ((bitField0_ & 0x00000004) != 0); + } + + /** + * optional string nationality = 3; + * + * @return The nationality. + */ + public java.lang.String getNationality() { + java.lang.Object ref = nationality_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + nationality_ = s; + } + return s; + } else { + return (java.lang.String) ref; + } + } + + /** + * optional string nationality = 3; + * + * @param value The nationality to set. + * @return This builder for chaining. + */ + public Builder setNationality(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000004; + nationality_ = value; + onChanged(); + return this; + } + + /** + * optional string nationality = 3; + * + * @return The bytes for nationality. + */ + public com.google.protobuf.ByteString getNationalityBytes() { + java.lang.Object ref = nationality_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + nationality_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + /** + * optional string nationality = 3; + * + * @param value The bytes for nationality to set. + * @return This builder for chaining. + */ + public Builder setNationalityBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000004; + nationality_ = value; + onChanged(); + return this; + } + + /** + * optional string nationality = 3; + * + * @return This builder for chaining. + */ + public Builder clearNationality() { + bitField0_ = (bitField0_ & ~0x00000004); + nationality_ = getDefaultInstance().getNationality(); + onChanged(); + return this; + } + + /** + * optional .spanner.examples.music.Genre genre = 4; + * + * @return Whether the genre field is set. + */ + @java.lang.Override + public boolean hasGenre() { + return ((bitField0_ & 0x00000008) != 0); + } + + /** + * optional .spanner.examples.music.Genre genre = 4; + * + * @return The genre. + */ + @java.lang.Override + public com.example.spanner.SingerProto.Genre getGenre() { + @SuppressWarnings("deprecation") + com.example.spanner.SingerProto.Genre result = + com.example.spanner.SingerProto.Genre.valueOf(genre_); + return result == null ? com.example.spanner.SingerProto.Genre.POP : result; + } + + /** + * optional .spanner.examples.music.Genre genre = 4; + * + * @param value The genre to set. + * @return This builder for chaining. + */ + public Builder setGenre(com.example.spanner.SingerProto.Genre value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000008; + genre_ = value.getNumber(); + onChanged(); + return this; + } + + /** + * optional .spanner.examples.music.Genre genre = 4; + * + * @return This builder for chaining. + */ + public Builder clearGenre() { + bitField0_ = (bitField0_ & ~0x00000008); + genre_ = 0; + onChanged(); + return this; + } + + @java.lang.Override + public final Builder setUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + // @@protoc_insertion_point(builder_scope:spanner.examples.music.SingerInfo) + } + } + + // @@protoc_insertion_point(outer_class_scope) +} diff --git a/samples/snippets/src/main/java/com/example/spanner/UpdateProtoColumnSample.java b/samples/snippets/src/main/java/com/example/spanner/UpdateProtoColumnSample.java new file mode 100644 index 00000000000..e2c97264575 --- /dev/null +++ b/samples/snippets/src/main/java/com/example/spanner/UpdateProtoColumnSample.java @@ -0,0 +1,83 @@ +/* + * Copyright 2022 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.example.spanner; + +import com.example.spanner.SingerProto.Genre; +import com.example.spanner.SingerProto.SingerInfo; +import com.google.cloud.spanner.DatabaseClient; +import com.google.cloud.spanner.DatabaseId; +import com.google.cloud.spanner.Mutation; +import com.google.cloud.spanner.Spanner; +import com.google.cloud.spanner.SpannerOptions; +import com.google.common.collect.ImmutableList; +import java.util.Arrays; + +/** + * To insert data into Proto column including messages and enums and array of them. + */ +public class UpdateProtoColumnSample { + + static void updateProtoData() { + // TODO(developer): Replace these variables before running the sample. + String projectId = "my-project"; + String instanceId = "my-instance"; + String databaseId = "my-database"; + + try (Spanner spanner = + SpannerOptions.newBuilder().setProjectId(projectId).build().getService()) { + DatabaseClient client = + spanner.getDatabaseClient(DatabaseId.of(projectId, instanceId, databaseId)); + updateProtoData(client); + } + } + + /** + * Method to update Singer Table using mutations. + * + * Assuming a table Singer with columns with following DDL: + * CREATE TABLE Singer ( + * singer_id INT64 NOT NULL, + * singer_info spanner.examples.music.SingerInfo, + * genre spanner.examples.music.Genre, + * singer_info_list ARRAY, + * genre_list ARRAY, + * ) PRIMARY KEY (singer_id); + */ + static void updateProtoData(DatabaseClient client) { + SingerInfo singerInfo = + SingerInfo.newBuilder().setSingerId(11).setNationality("Country1").build(); + + client.write( + ImmutableList.of( + Mutation.newInsertOrUpdateBuilder("Singer") + .set("singer_id") + .to(32) + .set("singer_info") + .to(singerInfo) + .set("genre") + .to(Genre.JAZZ) + .set("singer_info_list") + .toProtoMessageArray( + Arrays.asList(singerInfo, null, SingerInfo.getDefaultInstance()), + SingerInfo.getDescriptor()) + .set("genre_list") + .toProtoEnumArray( + Arrays.asList(Genre.FOLK, null, Genre.ROCK), Genre.getDescriptor()) + .build())); + + System.out.println("Singer data successfully updated"); + } +} From 6c97b99c227c177352fcce970fac8aa7f838cdae Mon Sep 17 00:00:00 2001 From: Gaurav Purohit Date: Thu, 5 Jan 2023 15:14:26 +0530 Subject: [PATCH 03/27] test: Proto Column Integration tests (#2212) * test: Adding Integration tests for Proto Messages & Enums * test: Adding additional test for Parameterized Queries, Primary Keys & Invalid Wire type errors. * style: Formatting * style: Formatting * test: Updating instance and db name * test: Adding inter compatability check while writing data --- .../cloud/spanner/it/ITProtoColumnTest.java | 355 ++++++++++++++++++ 1 file changed, 355 insertions(+) create mode 100644 google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITProtoColumnTest.java diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITProtoColumnTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITProtoColumnTest.java new file mode 100644 index 00000000000..7d689612284 --- /dev/null +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITProtoColumnTest.java @@ -0,0 +1,355 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.spanner.it; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThrows; +import static org.junit.Assume.assumeFalse; + +import com.google.cloud.ByteArray; +import com.google.cloud.spanner.DatabaseClient; +import com.google.cloud.spanner.DatabaseId; +import com.google.cloud.spanner.Key; +import com.google.cloud.spanner.KeySet; +import com.google.cloud.spanner.Mutation; +import com.google.cloud.spanner.ParallelIntegrationTest; +import com.google.cloud.spanner.ResultSet; +import com.google.cloud.spanner.SingerProto.Genre; +import com.google.cloud.spanner.SingerProto.SingerInfo; +import com.google.cloud.spanner.Spanner; +import com.google.cloud.spanner.SpannerException; +import com.google.cloud.spanner.SpannerOptions; +import com.google.cloud.spanner.Statement; +import com.google.cloud.spanner.testing.EmulatorSpannerHelper; +import com.google.common.collect.ImmutableList; +import com.google.protobuf.AbstractMessage; +import com.google.protobuf.InvalidProtocolBufferException.InvalidWireTypeException; +import com.google.protobuf.ProtocolMessageEnum; +import com.google.spanner.admin.database.v1.Backup; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import org.junit.After; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** Integrations Tests to test Proto Columns & Enums */ +@Category(ParallelIntegrationTest.class) +@RunWith(JUnit4.class) +public class ITProtoColumnTest { + private static String projectId; + private static String instanceId; + private static String databaseId; + private static DatabaseClient databaseClient; + + @BeforeClass + public static void beforeClass() throws Exception { + assumeFalse( + "Proto Column is not supported in the emulator", EmulatorSpannerHelper.isUsingEmulator()); + // ToDo: Update project, instance and database parameter before GA + projectId = "span-cloud-testing"; + databaseId = "int_test_proto_column_db"; + instanceId = "integration-test-proto-column"; + + Spanner spanner = + SpannerOptions.newBuilder() + .setHost("https://staging-wrenchworks.sandbox.googleapis.com") + .setProjectId(projectId) + .build() + .getService(); + + databaseClient = spanner.getDatabaseClient(DatabaseId.of(projectId, instanceId, databaseId)); + } + + @After + public void after() throws Exception { + databaseClient.write(ImmutableList.of(Mutation.delete("Types", KeySet.all()))); + databaseClient.write(ImmutableList.of(Mutation.delete("Singers", KeySet.all()))); + } + + /** + * Test to check updates and read queries on Proto column and Enums and their arrays. Test also + * checks for compatability between following types: 1. Proto Messages & Bytes 2. Proto Enums & + * Int64 + * + *

Table `Types` was created through gcloud using following DDL: + * ************************************** CREATE TABLE Types ( RowID INT64 NOT NULL, Int64a INT64, + * Bytes BYTES(MAX), Int64Array ARRAY, BytesArray ARRAY, ProtoMessage + * spanner.examples.music.SingerInfo, ProtoEnum spanner.examples.music.Genre, ProtoMessageArray + * ARRAY, ProtoEnumArray ARRAY, ) + * PRIMARY KEY (RowID); ************************************** + */ + @Test + public void testProtoUpdateAndRead() { + assumeFalse( + "Proto Column is not supported in the emulator", EmulatorSpannerHelper.isUsingEmulator()); + SingerInfo singerInfo = + SingerInfo.newBuilder().setSingerId(11).setNationality("Country1").build(); + ByteArray singerInfoBytes = ByteArray.copyFrom(singerInfo.toByteArray()); + + Genre genre = Genre.JAZZ; + long genreConst = genre.getNumber(); + + List singerInfoList = + Arrays.asList(singerInfo, null, SingerInfo.getDefaultInstance()); + List singerInfoBytesList = + Arrays.asList( + singerInfoBytes, + null, + ByteArray.copyFrom(SingerInfo.getDefaultInstance().toByteArray())); + + List enumList = Arrays.asList(Genre.FOLK, null, Genre.ROCK); + List enumConstList = + Arrays.asList((long) Genre.FOLK_VALUE, null, (long) Genre.ROCK_VALUE); + + // Inserting two rows with same data except rowID as it's used as PK. + databaseClient.write( + ImmutableList.of( + Mutation.newInsertOrUpdateBuilder("Types") + .set("RowID") + .to(11) + .set("Int64a") + .to(genreConst) + .set("Bytes") + .to(singerInfoBytes) + .set("Int64Array") + .toInt64Array(enumConstList) + .set("BytesArray") + .toBytesArray(singerInfoBytesList) + .set("ProtoMessage") + .to(singerInfo) + .set("ProtoEnum") + .to(genre) + .set("ProtoMessageArray") + .toProtoMessageArray(singerInfoList, SingerInfo.getDescriptor()) + .set("ProtoEnumArray") + .toProtoEnumArray(enumList, Genre.getDescriptor()) + .build(), + //Inter Compatability check between ProtoMessages/Bytes and Int64/Enum. + Mutation.newInsertOrUpdateBuilder("Types") + .set("RowID") + .to(12) + .set("Int64a") + .to(genre) + .set("Bytes") + .to(singerInfo) + .set("Int64Array") + .toProtoEnumArray(enumList, Genre.getDescriptor()) + .set("BytesArray") + .toProtoMessageArray(singerInfoList, SingerInfo.getDescriptor()) + .set("ProtoMessage") + .to(singerInfoBytes) + .set("ProtoEnum") + .to(genreConst) + .set("ProtoMessageArray") + .toBytesArray(singerInfoBytesList) + .set("ProtoEnumArray") + .toInt64Array(enumConstList) + .build())); + + try (ResultSet resultSet = + databaseClient.singleUse().executeQuery(Statement.of("SELECT * FROM " + "Types"))) { + + for(int i=0;i<2;i++) { + resultSet.next(); + assertEquals(11 + i, resultSet.getLong("RowID")); + assertEquals(genreConst, resultSet.getLong("Int64a")); + assertEquals(singerInfoBytes, resultSet.getBytes("Bytes")); + assertEquals(enumConstList, resultSet.getLongList("Int64Array")); + assertEquals(singerInfoBytesList, resultSet.getBytesList("BytesArray")); + assertEquals( + singerInfo, resultSet.getProtoMessage("ProtoMessage", SingerInfo.getDefaultInstance())); + assertEquals(genre, resultSet.getProtoEnum("ProtoEnum", Genre::forNumber)); + assertEquals( + singerInfoList, + resultSet.getProtoMessageList("ProtoMessageArray", SingerInfo.getDefaultInstance())); + assertEquals(enumList, resultSet.getProtoEnumList("ProtoEnumArray", Genre::forNumber)); + + // Check compatability between Proto Messages & Bytes + assertEquals(singerInfoBytes, resultSet.getBytes("ProtoMessage")); + assertEquals(singerInfo, resultSet.getProtoMessage("Bytes", SingerInfo.getDefaultInstance())); + + assertEquals(singerInfoBytesList, resultSet.getBytesList("ProtoMessageArray")); + assertEquals( + singerInfoList, + resultSet.getProtoMessageList("BytesArray", SingerInfo.getDefaultInstance())); + + // Check compatability between Proto Enum & Int64 + assertEquals(genreConst, resultSet.getLong("ProtoEnum")); + assertEquals(genre, resultSet.getProtoEnum("Int64a", Genre::forNumber)); + + assertEquals(enumConstList, resultSet.getLongList("ProtoEnumArray")); + assertEquals(enumList, resultSet.getProtoEnumList("Int64Array", Genre::forNumber)); + } + } + } + + /** + * Test to check Parameterized Queries, Primary Keys and Indexes. + * + *

Table `Singers` and Index `SingerByNationalityAndGenre` for Proto column integration tests + * is created through gcloud using following DDL: + * + *

************************************** CREATE TABLE Singers ( SingerId INT64 NOT NULL, + * FirstName STRING(1024), LastName STRING(1024), SingerInfo spanner.examples.music.SingerInfo, + * SingerGenre spanner.examples.music.Genre, SingerNationality STRING(1024) AS + * (SingerInfo.nationality) STORED, ) PRIMARY KEY (SingerNationality, SingerGenre); + * + *

CREATE INDEX SingerByNationalityAndGenre ON Singers(SingerNationality, SingerGenre) STORING + * (SingerId, FirstName, LastName); ************************************** + */ + @Test + public void testProtoColumnsDMLParameterizedQueriesAndPKIndexes() { + assumeFalse( + "Proto Column is not supported in the emulator", EmulatorSpannerHelper.isUsingEmulator()); + + SingerInfo singerInfo1 = + SingerInfo.newBuilder().setSingerId(11).setNationality("Country1").build(); + Genre genre1 = Genre.FOLK; + + SingerInfo singerInfo2 = + SingerInfo.newBuilder().setSingerId(11).setNationality("Country2").build(); + Genre genre2 = Genre.JAZZ; + + databaseClient + .readWriteTransaction() + .run( + transaction -> { + Statement statement1 = + Statement.newBuilder( + "INSERT INTO Singers (SingerId, FirstName, LastName, SingerInfo, SingerGenre) VALUES (11, \"FirstName1\", \"LastName1\", @singerInfo, @singerGenre)") + .bind("singerInfo") + .to(singerInfo1) + .bind("singerGenre") + .to(genre1) + .build(); + + Statement statement2 = + Statement.newBuilder( + "INSERT INTO Singers (SingerId, FirstName, LastName, SingerInfo, SingerGenre) VALUES (22, \"FirstName2\", \"LastName2\", @singerInfo, @singerGenre)") + .bind("singerInfo") + .to(singerInfo2) + .bind("singerGenre") + .to(genre2) + .build(); + + transaction.batchUpdate(Arrays.asList(statement1, statement2)); + return null; + }); + + // Read all rows based on Proto Message field and Proto Enum Primary key column values + ResultSet resultSet1 = + databaseClient + .singleUse() + .read( + "Singers", + KeySet.newBuilder() + .addKey(Key.of("Country1", Genre.FOLK)) + .addKey(Key.of("Country2", Genre.JAZZ)) + .build(), + Arrays.asList("SingerId", "FirstName", "LastName", "SingerInfo", "SingerGenre")); + + resultSet1.next(); + assertEquals(11, resultSet1.getLong("SingerId")); + assertEquals("FirstName1", resultSet1.getString("FirstName")); + assertEquals("LastName1", resultSet1.getString("LastName")); + assertEquals( + singerInfo1, resultSet1.getProtoMessage("SingerInfo", SingerInfo.getDefaultInstance())); + assertEquals(genre1, resultSet1.getProtoEnum("SingerGenre", Genre::forNumber)); + + resultSet1.next(); + assertEquals(22, resultSet1.getLong("SingerId")); + assertEquals("FirstName2", resultSet1.getString("FirstName")); + assertEquals("LastName2", resultSet1.getString("LastName")); + assertEquals( + singerInfo2, resultSet1.getProtoMessage("SingerInfo", SingerInfo.getDefaultInstance())); + assertEquals(genre2, resultSet1.getProtoEnum("SingerGenre", Genre::forNumber)); + + // Read rows using Index on Proto Message field and Proto Enum column + ResultSet resultSet2 = + databaseClient + .singleUse() + .readUsingIndex( + "Singers", + "SingerByNationalityAndGenre", + KeySet.singleKey(Key.of("Country2", Genre.JAZZ)), + Arrays.asList("SingerId", "FirstName", "LastName")); + resultSet2.next(); + assertEquals(22, resultSet2.getLong("SingerId")); + assertEquals("FirstName2", resultSet2.getString("FirstName")); + assertEquals("LastName2", resultSet2.getString("LastName")); + + // Filter using Parameterized DQL + ResultSet resultSet3 = + databaseClient + .singleUse() + .executeQuery( + Statement.newBuilder( + "SELECT SingerId, SingerInfo, SingerGenre FROM " + + "Singers WHERE SingerInfo.Nationality=@country AND SingerGenre=@genre") + .bind("country") + .to("Country2") + .bind("genre") + .to(Genre.JAZZ) + .build()); + + resultSet3.next(); + assertEquals(22, resultSet1.getLong("SingerId")); + assertEquals( + singerInfo2, resultSet1.getProtoMessage("SingerInfo", SingerInfo.getDefaultInstance())); + assertEquals(genre2, resultSet1.getProtoEnum("SingerGenre", Genre::forNumber)); + } + + /** + * Test the exception in case Invalid protocol message object is provided while deserializing the + * data. + */ + @Test + public void testProtoMessageDeserializationError() { + assumeFalse( + "Proto Column is not supported in the emulator", EmulatorSpannerHelper.isUsingEmulator()); + + SingerInfo singerInfo = + SingerInfo.newBuilder().setSingerId(11).setNationality("Country1").build(); + + databaseClient.write( + ImmutableList.of( + Mutation.newInsertOrUpdateBuilder("Types") + .set("RowID") + .to(11) + .set("ProtoMessage") + .to(singerInfo) + .build())); + + ResultSet resultSet = + databaseClient + .singleUse() + .read("Types", KeySet.all(), Collections.singletonList("ProtoMessage")); + resultSet.next(); + + SpannerException e = + assertThrows( + SpannerException.class, + () -> resultSet.getProtoMessage("ProtoMessage", Backup.getDefaultInstance())); + + // Underlying cause is InvalidWireTypeException + assertEquals(InvalidWireTypeException.class, e.getCause().getClass()); + } +} From 53397e665527edb26bee82b6800c1475dfb303fb Mon Sep 17 00:00:00 2001 From: Gaurav Purohit Date: Thu, 5 Jan 2023 16:06:03 +0530 Subject: [PATCH 04/27] Configured jitpack.yml to use OpenJDK 11 (#2218) Co-authored-by: Pavol Juhos --- jitpack.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 jitpack.yml diff --git a/jitpack.yml b/jitpack.yml new file mode 100644 index 00000000000..46c85291995 --- /dev/null +++ b/jitpack.yml @@ -0,0 +1,2 @@ +jdk: + - openjdk11 \ No newline at end of file From 2f8eb427f3f71a5c95dcf957a8031e1a659f675d Mon Sep 17 00:00:00 2001 From: Sri Harsha CH <57220027+harshachinta@users.noreply.github.com> Date: Wed, 15 Mar 2023 21:45:21 +0530 Subject: [PATCH 05/27] feat: add support for Proto Columns DDL (#2277) * feat: add code changes and tests for Proto columns DDL support * feat: add auto generated code * feat: code changes and tests for Proto columns DDL support * feat: add descriptors file * feat: code refactoring * feat: Integration tests and code refactoring * feat: code refactoring * feat: unit tests and clirr differences * feat: lint changes * feat: code refactor * feat: code refactoring * feat: code refactoring * feat: code refactoring * feat: add java docs to new methods * feat: lint formatting * feat: lint formatting changes * feat: lint formatting * feat: lint formatting * feat: test exception cases * feat: code refactoring * feat: add java docs and refactoring * feat: add java docs * feat: java docs refactor * feat: remove overload method setProtoDescriptors that accepts file path as input to avoid unexpected issues * feat: remove updateDdl method overload to update proto descriptor --- README.md | 6 +- .../clirr-ignored-differences.xml | 51 +++ .../cloud/spanner/DatabaseAdminClient.java | 54 ++- .../spanner/DatabaseAdminClientImpl.java | 19 +- .../google/cloud/spanner/DatabaseInfo.java | 66 ++- .../database/v1/DatabaseAdminClient.java | 6 + .../cloud/spanner/spi/v1/GapicSpannerRpc.java | 33 +- .../cloud/spanner/spi/v1/SpannerRpc.java | 9 +- .../spanner/DatabaseAdminClientImplTest.java | 26 +- .../google/cloud/spanner/DatabaseTest.java | 58 +++ .../v1/DatabaseAdminClientHttpJsonTest.java | 10 +- .../database/v1/DatabaseAdminClientTest.java | 10 +- .../cloud/spanner/it/ITProtoColumnTest.java | 180 +++++--- .../com/google/cloud/spanner/descriptors.pb | Bin 0 -> 251 bytes .../database/v1/CreateDatabaseRequest.java | 151 +++++++ .../v1/CreateDatabaseRequestOrBuilder.java | 27 ++ .../database/v1/GetDatabaseDdlResponse.java | 111 +++++ .../v1/GetDatabaseDdlResponseOrBuilder.java | 17 + .../v1/SpannerDatabaseAdminProto.java | 395 +++++++++--------- .../database/v1/UpdateDatabaseDdlRequest.java | 171 ++++++++ .../v1/UpdateDatabaseDdlRequestOrBuilder.java | 32 ++ .../database/v1/spanner_database_admin.proto | 46 ++ 22 files changed, 1185 insertions(+), 293 deletions(-) create mode 100644 google-cloud-spanner/src/test/resources/com/google/cloud/spanner/descriptors.pb diff --git a/README.md b/README.md index baac29f6974..86dbd0f39c0 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ If you are using Maven without BOM, add this to your dependencies: If you are using Gradle 5.x or later, add this to your dependencies: ```Groovy -implementation platform('com.google.cloud:libraries-bom:26.2.0') +implementation platform('com.google.cloud:libraries-bom:26.3.0') implementation 'com.google.cloud:google-cloud-spanner' ``` @@ -261,6 +261,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-spanner/tree/ | Create Backup With Encryption Key | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/CreateBackupWithEncryptionKey.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/CreateBackupWithEncryptionKey.java) | | Create Database With Default Leader Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/CreateDatabaseWithDefaultLeaderSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/CreateDatabaseWithDefaultLeaderSample.java) | | Create Database With Encryption Key | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/CreateDatabaseWithEncryptionKey.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/CreateDatabaseWithEncryptionKey.java) | +| Create Database With Proto Descriptor | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/CreateDatabaseWithProtoDescriptor.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/CreateDatabaseWithProtoDescriptor.java) | | Create Database With Version Retention Period Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/CreateDatabaseWithVersionRetentionPeriodSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/CreateDatabaseWithVersionRetentionPeriodSample.java) | | Create Instance Config Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/CreateInstanceConfigSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/CreateInstanceConfigSample.java) | | Create Instance Example | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/CreateInstanceExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/CreateInstanceExample.java) | @@ -290,12 +291,14 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-spanner/tree/ | Pg Spanner Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/PgSpannerSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/PgSpannerSample.java) | | Pg Update Using Dml Returning Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/PgUpdateUsingDmlReturningSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/PgUpdateUsingDmlReturningSample.java) | | Query Information Schema Database Options Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/QueryInformationSchemaDatabaseOptionsSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/QueryInformationSchemaDatabaseOptionsSample.java) | +| Query Proto Column Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/QueryProtoColumnSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/QueryProtoColumnSample.java) | | Query With Json Parameter Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/QueryWithJsonParameterSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/QueryWithJsonParameterSample.java) | | Query With Jsonb Parameter Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/QueryWithJsonbParameterSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/QueryWithJsonbParameterSample.java) | | Query With Numeric Parameter Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/QueryWithNumericParameterSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/QueryWithNumericParameterSample.java) | | Quickstart Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/QuickstartSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/QuickstartSample.java) | | Read Data With Database Role | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/ReadDataWithDatabaseRole.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/ReadDataWithDatabaseRole.java) | | Restore Backup With Encryption Key | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/RestoreBackupWithEncryptionKey.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/RestoreBackupWithEncryptionKey.java) | +| Singer Proto | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/SingerProto.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/SingerProto.java) | | Spanner Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/SpannerSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/SpannerSample.java) | | Statement Timeout Example | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/StatementTimeoutExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/StatementTimeoutExample.java) | | Tag Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/TagSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/TagSample.java) | @@ -305,6 +308,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-spanner/tree/ | Update Json Data Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/UpdateJsonDataSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/UpdateJsonDataSample.java) | | Update Jsonb Data Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/UpdateJsonbDataSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/UpdateJsonbDataSample.java) | | Update Numeric Data Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/UpdateNumericDataSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/UpdateNumericDataSample.java) | +| Update Proto Column Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/UpdateProtoColumnSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/UpdateProtoColumnSample.java) | | Update Using Dml Returning Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/UpdateUsingDmlReturningSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/UpdateUsingDmlReturningSample.java) | diff --git a/google-cloud-spanner/clirr-ignored-differences.xml b/google-cloud-spanner/clirr-ignored-differences.xml index 8e4710354e3..9950d9f62b3 100644 --- a/google-cloud-spanner/clirr-ignored-differences.xml +++ b/google-cloud-spanner/clirr-ignored-differences.xml @@ -262,4 +262,55 @@ com/google/cloud/spanner/connection/Connection com.google.cloud.spanner.ResultSet analyzeUpdateStatement(com.google.cloud.spanner.Statement, com.google.cloud.spanner.ReadContext$QueryAnalyzeMode, com.google.cloud.spanner.Options$UpdateOption[]) + + 7012 + com/google/cloud/spanner/DatabaseAdminClient + com.google.spanner.admin.database.v1.GetDatabaseDdlResponse getDatabaseDdlResponse(java.lang.String, java.lang.String) + + + 7012 + com/google/cloud/spanner/DatabaseAdminClient + com.google.api.gax.longrunning.OperationFuture updateDatabaseDdl(com.google.cloud.spanner.Database, java.lang.Iterable, java.lang.String) + + + 7013 + com/google/cloud/spanner/DatabaseInfo$Builder + com.google.cloud.spanner.DatabaseInfo$Builder setProtoDescriptors(byte[]) + + + 7013 + com/google/cloud/spanner/DatabaseInfo$Builder + com.google.cloud.spanner.DatabaseInfo$Builder setProtoDescriptors(java.io.InputStream) + + + 7013 + com/google/cloud/spanner/DatabaseInfo$Builder + com.google.cloud.spanner.DatabaseInfo$Builder setProtoDescriptors(java.lang.String) + + + 7006 + com/google/cloud/spanner/spi/v1/GapicSpannerRpc + java.util.List getDatabaseDdl(java.lang.String) + java.util.List + com.google.spanner.admin.database.v1.GetDatabaseDdlResponse + + + 7005 + com/google/cloud/spanner/spi/v1/GapicSpannerRpc + com.google.api.gax.longrunning.OperationFuture updateDatabaseDdl(java.lang.String, java.lang.Iterable, java.lang.String) + com.google.api.gax.longrunning.OperationFuture updateDatabaseDdl(com.google.cloud.spanner.Database, java.lang.Iterable, java.lang.String) + + + 7006 + com/google/cloud/spanner/spi/v1/SpannerRpc + java.util.List getDatabaseDdl(java.lang.String) + java.util.List + com.google.spanner.admin.database.v1.GetDatabaseDdlResponse + + + 7005 + com/google/cloud/spanner/spi/v1/SpannerRpc + com.google.api.gax.longrunning.OperationFuture updateDatabaseDdl(java.lang.String, java.lang.Iterable, java.lang.String) + com.google.api.gax.longrunning.OperationFuture updateDatabaseDdl(com.google.cloud.spanner.Database, java.lang.Iterable, java.lang.String) + diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseAdminClient.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseAdminClient.java index 1363118e3aa..e4c27ff4ef0 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseAdminClient.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseAdminClient.java @@ -26,6 +26,7 @@ import com.google.spanner.admin.database.v1.CreateBackupMetadata; import com.google.spanner.admin.database.v1.CreateDatabaseMetadata; import com.google.spanner.admin.database.v1.CreateDatabaseRequest; +import com.google.spanner.admin.database.v1.GetDatabaseDdlResponse; import com.google.spanner.admin.database.v1.RestoreDatabaseMetadata; import com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata; import java.util.List; @@ -382,7 +383,8 @@ OperationFuture restoreDatabase(Restore resto * *

If an operation already exists with the given operation id, the operation will be resumed * and the returned future will complete when the original operation finishes. See more - * information in {@link com.google.cloud.spanner.spi.v1.GapicSpannerRpc#updateDatabaseDdl(String, + * information in {@link + * com.google.cloud.spanner.spi.v1.GapicSpannerRpc#updateDatabaseDdl(com.google.cloud.spanner.Database, * Iterable, String)} * *

Example to update the database DDL. @@ -407,6 +409,39 @@ OperationFuture updateDatabaseDdl( @Nullable String operationId) throws SpannerException; + /** + * Updates a database in a Cloud Spanner instance. Any proto descriptors that have been set for + * the {@link Database} instance will be included in the {@link UpdateDatabaseDdlRequest}. + * + *

If an operation already exists with the given operation id, the operation will be resumed + * and the returned future will complete when the original operation finishes. See more + * information in {@link + * com.google.cloud.spanner.spi.v1.GapicSpannerRpc#updateDatabaseDdl(com.google.cloud.spanner.Database, + * Iterable, String)} + * + *

Example to update the database DDL with proto descriptors. + * + *

{@code
+   * Database dbInfo =
+   *         dbClient
+   *            .newDatabaseBuilder(DatabaseId.of("my_project_id", "my_instance_id", "my_database_id"))
+   *            .setProtoDescriptors("com/google/cloud/spanner/descriptors.pb")
+   *            .build();
+   * dbAdminClient.updateDatabaseDdl(dbInfo,
+   *     Arrays.asList("ALTER TABLE Albums ADD COLUMN MarketingBudget INT64"),
+   *     null).waitFor();
+   * }
+ * + * @param database Database object to set configuration options such as proto_descriptors. + * @param statements DDL statements to run while updating the database. + * @param operationId Operation id assigned to this operation. If null, system will autogenerate + * one. This must be unique within a database abd must be a valid identifier + * [a-zA-Z][a-zA-Z0-9_]*. + */ + OperationFuture updateDatabaseDdl( + Database database, Iterable statements, @Nullable String operationId) + throws SpannerException; + /** * Drops a Cloud Spanner database. * @@ -434,6 +469,23 @@ OperationFuture updateDatabaseDdl( */ List getDatabaseDdl(String instanceId, String databaseId); + /** + * Returns the GetDatabaseDdlResponse object of a Cloud Spanner database. + * + *

Example to get GetDatabaseDdlResponse object of a Cloud Spanner database. + * + *

{@code
+   * String instanceId = my_instance_id;
+   * String databaseId = my_database_id;
+   * GetDatabaseDdlResponse response = dbAdminClient.getDatabaseDdl(instanceId, databaseId);
+   * }
+ * + * @param instanceId the id of the instance where the database was created. + * @param databaseId the id of the database. + * @return GetDatabaseDdlResponse object + */ + GetDatabaseDdlResponse getDatabaseDdlResponse(String instanceId, String databaseId); + /** * Returns the list of Cloud Spanner database in the given instance. * diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseAdminClientImpl.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseAdminClientImpl.java index 73ece214c3a..125aa74cad1 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseAdminClientImpl.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseAdminClientImpl.java @@ -422,10 +422,20 @@ public OperationFuture updateDatabaseDdl( final Iterable statements, @Nullable String operationId) throws SpannerException { - final String dbName = getDatabaseName(instanceId, databaseId); + + return updateDatabaseDdl( + newDatabaseBuilder(DatabaseId.of(projectId, instanceId, databaseId)).build(), + statements, + operationId); + } + + @Override + public OperationFuture updateDatabaseDdl( + Database database, final Iterable statements, @Nullable String operationId) + throws SpannerException { final String opId = operationId != null ? operationId : randomOperationId(); OperationFuture rawOperationFuture = - rpc.updateDatabaseDdl(dbName, statements, opId); + rpc.updateDatabaseDdl(database, statements, opId); return new OperationFutureImpl<>( rawOperationFuture.getPollingFuture(), rawOperationFuture.getInitialFuture(), @@ -447,6 +457,11 @@ public void dropDatabase(String instanceId, String databaseId) throws SpannerExc @Override public List getDatabaseDdl(String instanceId, String databaseId) { + return getDatabaseDdlResponse(instanceId, databaseId).getStatementsList(); + } + + @Override + public GetDatabaseDdlResponse getDatabaseDdlResponse(String instanceId, String databaseId) { String dbName = getDatabaseName(instanceId, databaseId); return rpc.getDatabaseDdl(dbName); } diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseInfo.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseInfo.java index 565517e3419..b992b23b0dc 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseInfo.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseInfo.java @@ -19,7 +19,11 @@ import com.google.cloud.Timestamp; import com.google.cloud.spanner.encryption.CustomerManagedEncryption; import com.google.common.base.Preconditions; +import com.google.protobuf.ByteString; +import java.io.IOException; +import java.io.InputStream; import java.util.Objects; +import javax.annotation.Nonnull; import javax.annotation.Nullable; /** Represents a Cloud Spanner database. */ @@ -58,6 +62,34 @@ public Builder setDialect(Dialect dialect) { throw new UnsupportedOperationException("Unimplemented"); } + /** + * Optional for creating a new database. + * + *

It is used by CREATE/ALTER PROTO BUNDLE statements which are part of DDL statements. + * Contains a protobuf-serialized [google.protobuf.FileDescriptorSet]. To generate a proto + * descriptors file run {@code protoc --include_imports + * --descriptor_set_out=DESCRIPTOR_OUTPUT_LOCATION LOCATION-OF-PROTO-FILES} + * + * @param protoDescriptors The proto descriptors input as byte[] to be used for the database. + * @return {@link Builder} + */ + public abstract Builder setProtoDescriptors(@Nonnull byte[] protoDescriptors); + + /** + * Optional for creating a new database. + * + *

It is used by CREATE/ALTER PROTO BUNDLE statements which are part of DDL statements. + * Contains a protobuf-serialized [google.protobuf.FileDescriptorSet]. To generate a proto + * descriptors file run {@code protoc --include_imports + * --descriptor_set_out=DESCRIPTOR_OUTPUT_LOCATION LOCATION-OF-PROTO-FILES} + * + * @param inputStream The proto descriptors input as InputStream to be used for the database. + * @return {@link Builder} + * @throws IOException if there is a problem reading the underlying stream. + */ + public abstract Builder setProtoDescriptors(@Nonnull InputStream inputStream) + throws IOException; + abstract Builder setProto(com.google.spanner.admin.database.v1.Database proto); /** Builds the database from this builder. */ @@ -74,6 +106,7 @@ abstract static class BuilderImpl extends Builder { private CustomerManagedEncryption encryptionConfig; private String defaultLeader; private Dialect dialect = Dialect.GOOGLE_STANDARD_SQL; + private ByteString protoDescriptors; private com.google.spanner.admin.database.v1.Database proto; BuilderImpl(DatabaseId id) { @@ -90,6 +123,7 @@ abstract static class BuilderImpl extends Builder { this.encryptionConfig = other.encryptionConfig; this.defaultLeader = other.defaultLeader; this.dialect = other.dialect; + this.protoDescriptors = other.protoDescriptors; this.proto = other.proto; } @@ -141,6 +175,20 @@ public Builder setDialect(Dialect dialect) { return this; } + @Override + public Builder setProtoDescriptors(@Nonnull byte[] protoDescriptors) { + Preconditions.checkNotNull(protoDescriptors); + this.protoDescriptors = ByteString.copyFrom(protoDescriptors); + return this; + } + + @Override + public Builder setProtoDescriptors(@Nonnull InputStream inputStream) throws IOException { + Preconditions.checkNotNull(inputStream); + this.protoDescriptors = ByteString.readFrom(inputStream); + return this; + } + @Override Builder setProto(@Nullable com.google.spanner.admin.database.v1.Database proto) { this.proto = proto; @@ -169,6 +217,7 @@ public enum State { private final CustomerManagedEncryption encryptionConfig; private final String defaultLeader; private final Dialect dialect; + private final ByteString protoDescriptors; private final com.google.spanner.admin.database.v1.Database proto; public DatabaseInfo(DatabaseId id, State state) { @@ -181,6 +230,7 @@ public DatabaseInfo(DatabaseId id, State state) { this.encryptionConfig = null; this.defaultLeader = null; this.dialect = null; + this.protoDescriptors = null; this.proto = null; } @@ -194,6 +244,7 @@ public DatabaseInfo(DatabaseId id, State state) { this.encryptionConfig = builder.encryptionConfig; this.defaultLeader = builder.defaultLeader; this.dialect = builder.dialect; + this.protoDescriptors = builder.protoDescriptors; this.proto = builder.proto; } @@ -262,6 +313,10 @@ public Timestamp getEarliestVersionTime() { return dialect; } + public ByteString getProtoDescriptors() { + return protoDescriptors; + } + /** Returns the raw proto instance that was used to construct this {@link Database}. */ public @Nullable com.google.spanner.admin.database.v1.Database getProto() { return proto; @@ -284,7 +339,8 @@ public boolean equals(Object o) { && Objects.equals(earliestVersionTime, that.earliestVersionTime) && Objects.equals(encryptionConfig, that.encryptionConfig) && Objects.equals(defaultLeader, that.defaultLeader) - && Objects.equals(dialect, that.dialect); + && Objects.equals(dialect, that.dialect) + && Objects.equals(protoDescriptors, that.protoDescriptors); } @Override @@ -298,13 +354,14 @@ public int hashCode() { earliestVersionTime, encryptionConfig, defaultLeader, - dialect); + dialect, + protoDescriptors); } @Override public String toString() { return String.format( - "Database[%s, %s, %s, %s, %s, %s, %s, %s, %s]", + "Database[%s, %s, %s, %s, %s, %s, %s, %s, %s, %s]", id.getName(), state, createTime, @@ -313,6 +370,7 @@ public String toString() { earliestVersionTime, encryptionConfig, defaultLeader, - dialect); + dialect, + protoDescriptors); } } diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/DatabaseAdminClient.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/DatabaseAdminClient.java index d625748b5e8..6325f020c89 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/DatabaseAdminClient.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/DatabaseAdminClient.java @@ -525,6 +525,7 @@ public final OperationFuture createDatabaseAsy * .addAllExtraStatements(new ArrayList()) * .setEncryptionConfig(EncryptionConfig.newBuilder().build()) * .setDatabaseDialect(DatabaseDialect.forNumber(0)) + * .setProtoDescriptors(ByteString.EMPTY) * .build(); * Database response = databaseAdminClient.createDatabaseAsync(request).get(); * } @@ -564,6 +565,7 @@ public final OperationFuture createDatabaseAsy * .addAllExtraStatements(new ArrayList()) * .setEncryptionConfig(EncryptionConfig.newBuilder().build()) * .setDatabaseDialect(DatabaseDialect.forNumber(0)) + * .setProtoDescriptors(ByteString.EMPTY) * .build(); * OperationFuture future = * databaseAdminClient.createDatabaseOperationCallable().futureCall(request); @@ -603,6 +605,7 @@ public final OperationFuture createDatabaseAsy * .addAllExtraStatements(new ArrayList()) * .setEncryptionConfig(EncryptionConfig.newBuilder().build()) * .setDatabaseDialect(DatabaseDialect.forNumber(0)) + * .setProtoDescriptors(ByteString.EMPTY) * .build(); * ApiFuture future = * databaseAdminClient.createDatabaseCallable().futureCall(request); @@ -827,6 +830,7 @@ public final OperationFuture updateDatabaseDdl * .setDatabase(DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]").toString()) * .addAllStatements(new ArrayList()) * .setOperationId("operationId129704162") + * .setProtoDescriptors(ByteString.EMPTY) * .build(); * databaseAdminClient.updateDatabaseDdlAsync(request).get(); * } @@ -864,6 +868,7 @@ public final OperationFuture updateDatabaseDdl * .setDatabase(DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]").toString()) * .addAllStatements(new ArrayList()) * .setOperationId("operationId129704162") + * .setProtoDescriptors(ByteString.EMPTY) * .build(); * OperationFuture future = * databaseAdminClient.updateDatabaseDdlOperationCallable().futureCall(request); @@ -901,6 +906,7 @@ public final OperationFuture updateDatabaseDdl * .setDatabase(DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]").toString()) * .addAllStatements(new ArrayList()) * .setOperationId("operationId129704162") + * .setProtoDescriptors(ByteString.EMPTY) * .build(); * ApiFuture future = * databaseAdminClient.updateDatabaseDdlCallable().futureCall(request); diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java index 7f325665542..9ccad743034 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java @@ -117,6 +117,7 @@ import com.google.spanner.admin.database.v1.DropDatabaseRequest; import com.google.spanner.admin.database.v1.GetBackupRequest; import com.google.spanner.admin.database.v1.GetDatabaseDdlRequest; +import com.google.spanner.admin.database.v1.GetDatabaseDdlResponse; import com.google.spanner.admin.database.v1.GetDatabaseRequest; import com.google.spanner.admin.database.v1.ListBackupOperationsRequest; import com.google.spanner.admin.database.v1.ListBackupOperationsResponse; @@ -1190,8 +1191,10 @@ public OperationFuture createDatabase( if (databaseInfo.getDialect() != null) { requestBuilder.setDatabaseDialect(databaseInfo.getDialect().toProto()); } + if (databaseInfo.getProtoDescriptors() != null) { + requestBuilder.setProtoDescriptors(databaseInfo.getProtoDescriptors()); + } final CreateDatabaseRequest request = requestBuilder.build(); - OperationFutureCallable callable = new OperationFutureCallable<>( databaseAdminStub.createDatabaseOperationCallable(), @@ -1246,19 +1249,27 @@ public OperationFuture createDatabase( */ @Override public OperationFuture updateDatabaseDdl( - final String databaseName, + com.google.cloud.spanner.Database databaseInfo, final Iterable updateDatabaseStatements, @Nullable final String updateId) throws SpannerException { acquireAdministrativeRequestsRateLimiter(); - final UpdateDatabaseDdlRequest request = + Preconditions.checkNotNull(databaseInfo.getId()); + UpdateDatabaseDdlRequest.Builder requestBuilder = UpdateDatabaseDdlRequest.newBuilder() - .setDatabase(databaseName) + .setDatabase(databaseInfo.getId().getName()) .addAllStatements(updateDatabaseStatements) - .setOperationId(MoreObjects.firstNonNull(updateId, "")) - .build(); + .setOperationId(MoreObjects.firstNonNull(updateId, "")); + if (databaseInfo.getProtoDescriptors() != null) { + requestBuilder.setProtoDescriptors(databaseInfo.getProtoDescriptors()); + } + final UpdateDatabaseDdlRequest request = requestBuilder.build(); final GrpcCallContext context = - newCallContext(null, databaseName, request, DatabaseAdminGrpc.getUpdateDatabaseDdlMethod()); + newCallContext( + null, + databaseInfo.getId().getName(), + request, + DatabaseAdminGrpc.getUpdateDatabaseDdlMethod()); final OperationCallable callable = databaseAdminStub.updateDatabaseDdlOperationCallable(); @@ -1280,7 +1291,7 @@ public OperationFuture updateDatabaseDdl( if (t instanceof AlreadyExistsException) { String operationName = OPERATION_NAME_TEMPLATE.instantiate( - "database", databaseName, "operation", updateId); + "database", databaseInfo.getId().getName(), "operation", updateId); return callable.resumeFutureCall(operationName, context); } } @@ -1316,7 +1327,7 @@ public Database getDatabase(String databaseName) throws SpannerException { } @Override - public List getDatabaseDdl(String databaseName) throws SpannerException { + public GetDatabaseDdlResponse getDatabaseDdl(String databaseName) throws SpannerException { acquireAdministrativeRequestsRateLimiter(); final GetDatabaseDdlRequest request = GetDatabaseDdlRequest.newBuilder().setDatabase(databaseName).build(); @@ -1324,9 +1335,7 @@ public List getDatabaseDdl(String databaseName) throws SpannerException final GrpcCallContext context = newCallContext(null, databaseName, request, DatabaseAdminGrpc.getGetDatabaseDdlMethod()); return runWithRetryOnAdministrativeRequestsExceeded( - () -> - get(databaseAdminStub.getDatabaseDdlCallable().futureCall(request, context)) - .getStatementsList()); + () -> get(databaseAdminStub.getDatabaseDdlCallable().futureCall(request, context))); } @Override diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/SpannerRpc.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/SpannerRpc.java index 2f68b9c1df2..e566057929d 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/SpannerRpc.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/SpannerRpc.java @@ -40,6 +40,7 @@ import com.google.spanner.admin.database.v1.CreateDatabaseMetadata; import com.google.spanner.admin.database.v1.Database; import com.google.spanner.admin.database.v1.DatabaseRole; +import com.google.spanner.admin.database.v1.GetDatabaseDdlResponse; import com.google.spanner.admin.database.v1.RestoreDatabaseMetadata; import com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata; import com.google.spanner.admin.instance.v1.CreateInstanceConfigMetadata; @@ -148,7 +149,6 @@ interface ResultStreamConsumer { /** Handle for cancellation of a streaming read or query call. */ interface StreamingCall { - /** * Requests more messages from the stream. We disable the auto flow control mechanism in grpc, * so we need to request messages ourself. This gives us more control over how much buffer we @@ -225,14 +225,17 @@ OperationFuture createDatabase( throws SpannerException; OperationFuture updateDatabaseDdl( - String databaseName, Iterable updateDatabaseStatements, @Nullable String updateId) + com.google.cloud.spanner.Database database, + Iterable updateDatabaseStatements, + @Nullable String updateId) throws SpannerException; void dropDatabase(String databaseName) throws SpannerException; Database getDatabase(String databaseName) throws SpannerException; - List getDatabaseDdl(String databaseName) throws SpannerException; + GetDatabaseDdlResponse getDatabaseDdl(String databaseName) throws SpannerException; + /** Lists the backups in the specified instance. */ Paginated listBackups( String instanceName, int pageSize, @Nullable String filter, @Nullable String pageToken) diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseAdminClientImplTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseAdminClientImplTest.java index 0255f6c1668..8a9144b0be6 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseAdminClientImplTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseAdminClientImplTest.java @@ -51,6 +51,7 @@ import com.google.spanner.admin.database.v1.DatabaseDialect; import com.google.spanner.admin.database.v1.DatabaseRole; import com.google.spanner.admin.database.v1.EncryptionInfo; +import com.google.spanner.admin.database.v1.GetDatabaseDdlResponse; import com.google.spanner.admin.database.v1.RestoreDatabaseMetadata; import com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata; import java.util.ArrayList; @@ -222,7 +223,9 @@ public void updateDatabaseDdl() throws Exception { OperationFuture rawOperationFuture = OperationFutureUtil.immediateOperationFuture( opName, Empty.getDefaultInstance(), UpdateDatabaseDdlMetadata.getDefaultInstance()); - when(rpc.updateDatabaseDdl(DB_NAME, ddl, opId)).thenReturn(rawOperationFuture); + when(rpc.updateDatabaseDdl( + client.newDatabaseBuilder(DatabaseId.of(DB_NAME)).build(), ddl, opId)) + .thenReturn(rawOperationFuture); OperationFuture op = client.updateDatabaseDdl(INSTANCE_ID, DB_ID, ddl, opId); assertThat(op.isDone()).isTrue(); @@ -240,7 +243,9 @@ public void updateDatabaseDdlOpAlreadyExists() throws Exception { UpdateDatabaseDdlMetadata.getDefaultInstance()); String newOpId = "newop"; - when(rpc.updateDatabaseDdl(DB_NAME, ddl, newOpId)).thenReturn(originalOp); + when(rpc.updateDatabaseDdl( + client.newDatabaseBuilder(DatabaseId.of(DB_NAME)).build(), ddl, newOpId)) + .thenReturn(originalOp); OperationFuture op = client.updateDatabaseDdl(INSTANCE_ID, DB_ID, ddl, newOpId); assertThat(op.getName()).isEqualTo(originalOpName); @@ -255,10 +260,25 @@ public void dropDatabase() { @Test public void getDatabaseDdl() { List ddl = ImmutableList.of("CREATE TABLE mytable()"); - when(rpc.getDatabaseDdl(DB_NAME)).thenReturn(ddl); + when(rpc.getDatabaseDdl(DB_NAME)) + .thenReturn(GetDatabaseDdlResponse.newBuilder().addAllStatements(ddl).build()); assertThat(client.getDatabaseDdl(INSTANCE_ID, DB_ID)).isEqualTo(ddl); } + @Test + public void getDatabaseDdlResponse() { + List ddl = ImmutableList.of("CREATE TABLE mytable()"); + when(rpc.getDatabaseDdl(DB_NAME)) + .thenReturn( + GetDatabaseDdlResponse.newBuilder() + .addAllStatements(ddl) + .setProtoDescriptors(ByteString.EMPTY) + .build()); + GetDatabaseDdlResponse response = client.getDatabaseDdlResponse(INSTANCE_ID, DB_ID); + assertThat(response.getStatementsList()).isEqualTo(ddl); + assertThat(response.getProtoDescriptors()).isEqualTo(ByteString.EMPTY); + } + @Test public void listDatabases() { String pageToken = "token"; diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseTest.java index 1eb2794c8ee..ad799485a1b 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseTest.java @@ -19,6 +19,7 @@ import static com.google.cloud.spanner.DatabaseInfo.State.CREATING; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThrows; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -30,10 +31,14 @@ import com.google.cloud.Timestamp; import com.google.cloud.spanner.DatabaseInfo.State; import com.google.cloud.spanner.encryption.EncryptionConfigs; +import com.google.common.io.ByteStreams; +import com.google.protobuf.ByteString; import com.google.rpc.Code; import com.google.rpc.Status; import com.google.spanner.admin.database.v1.DatabaseDialect; import com.google.spanner.admin.database.v1.EncryptionInfo; +import java.io.IOException; +import java.io.InputStream; import java.util.Collections; import java.util.List; import org.junit.Before; @@ -66,6 +71,10 @@ public class DatabaseTest { .build()); private static final String DEFAULT_LEADER = "default-leader"; private static final DatabaseDialect DEFAULT_DIALECT = DatabaseDialect.GOOGLE_STANDARD_SQL; + private static ByteString protoDescriptors; + private static byte[] protoDescriptorsByteArray; + private static final String PROTO_DESCRIPTORS_RESOURCE_PATH = + "com/google/cloud/spanner/descriptors.pb"; @Mock DatabaseAdminClient dbClient; @@ -79,6 +88,15 @@ public void setUp() { .thenAnswer( invocation -> new Database.Builder(dbClient, (DatabaseId) invocation.getArguments()[0])); + try { + InputStream protoDescriptorsInputStream = + getClass().getClassLoader().getResourceAsStream(PROTO_DESCRIPTORS_RESOURCE_PATH); + assertNotNull(protoDescriptorsInputStream); + protoDescriptorsByteArray = ByteStreams.toByteArray(protoDescriptorsInputStream); + protoDescriptors = ByteString.copyFrom(protoDescriptorsByteArray); + } catch (IOException e) { + e.printStackTrace(); + } } @Test @@ -178,6 +196,46 @@ public void testBuildWithDatabaseDialect() { assertEquals(Dialect.GOOGLE_STANDARD_SQL, database.getDialect()); } + @Test + public void testBuildWithProtoDescriptorsFromInputStream() throws IOException { + InputStream in = + getClass().getClassLoader().getResourceAsStream(PROTO_DESCRIPTORS_RESOURCE_PATH); + assertNotNull(in); + final Database database = + dbClient + .newDatabaseBuilder(DatabaseId.of("my-project", "my-instance", "my-database")) + .setProtoDescriptors(in) + .build(); + + assertEquals(protoDescriptors, database.getProtoDescriptors()); + } + + @Test + public void testBuildWithProtoDescriptorsFromByteArray() { + final Database database = + dbClient + .newDatabaseBuilder(DatabaseId.of("my-project", "my-instance", "my-database")) + .setProtoDescriptors(protoDescriptorsByteArray) + .build(); + + assertEquals(protoDescriptors, database.getProtoDescriptors()); + } + + @Test + public void testBuildWithProtoDescriptorsThrowsException() throws IOException { + InputStream in = + getClass().getClassLoader().getResourceAsStream(PROTO_DESCRIPTORS_RESOURCE_PATH); + in.close(); + // case1: Test one of the IOException case, where InputStream is closed before read + assertThrows( + IOException.class, + () -> + dbClient + .newDatabaseBuilder(DatabaseId.of("my-project", "my-instance", "my-database")) + .setProtoDescriptors(in) + .build()); + } + @Test public void getIAMPolicy() { Database database = diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/admin/database/v1/DatabaseAdminClientHttpJsonTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/admin/database/v1/DatabaseAdminClientHttpJsonTest.java index 31e6d9d97fb..1cbcb3d6d83 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/admin/database/v1/DatabaseAdminClientHttpJsonTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/admin/database/v1/DatabaseAdminClientHttpJsonTest.java @@ -607,7 +607,10 @@ public void dropDatabaseExceptionTest2() throws Exception { @Test public void getDatabaseDdlTest() throws Exception { GetDatabaseDdlResponse expectedResponse = - GetDatabaseDdlResponse.newBuilder().addAllStatements(new ArrayList()).build(); + GetDatabaseDdlResponse.newBuilder() + .addAllStatements(new ArrayList()) + .setProtoDescriptors(ByteString.EMPTY) + .build(); mockService.addResponse(expectedResponse); DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]"); @@ -649,7 +652,10 @@ public void getDatabaseDdlExceptionTest() throws Exception { @Test public void getDatabaseDdlTest2() throws Exception { GetDatabaseDdlResponse expectedResponse = - GetDatabaseDdlResponse.newBuilder().addAllStatements(new ArrayList()).build(); + GetDatabaseDdlResponse.newBuilder() + .addAllStatements(new ArrayList()) + .setProtoDescriptors(ByteString.EMPTY) + .build(); mockService.addResponse(expectedResponse); String database = "projects/project-3102/instances/instance-3102/databases/database-3102"; diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/admin/database/v1/DatabaseAdminClientTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/admin/database/v1/DatabaseAdminClientTest.java index 51c780c9829..bbea144499f 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/admin/database/v1/DatabaseAdminClientTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/admin/database/v1/DatabaseAdminClientTest.java @@ -586,7 +586,10 @@ public void dropDatabaseExceptionTest2() throws Exception { @Test public void getDatabaseDdlTest() throws Exception { GetDatabaseDdlResponse expectedResponse = - GetDatabaseDdlResponse.newBuilder().addAllStatements(new ArrayList()).build(); + GetDatabaseDdlResponse.newBuilder() + .addAllStatements(new ArrayList()) + .setProtoDescriptors(ByteString.EMPTY) + .build(); mockDatabaseAdmin.addResponse(expectedResponse); DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]"); @@ -622,7 +625,10 @@ public void getDatabaseDdlExceptionTest() throws Exception { @Test public void getDatabaseDdlTest2() throws Exception { GetDatabaseDdlResponse expectedResponse = - GetDatabaseDdlResponse.newBuilder().addAllStatements(new ArrayList()).build(); + GetDatabaseDdlResponse.newBuilder() + .addAllStatements(new ArrayList()) + .setProtoDescriptors(ByteString.EMPTY) + .build(); mockDatabaseAdmin.addResponse(expectedResponse); String database = "database1789464955"; diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITProtoColumnTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITProtoColumnTest.java index 7d689612284..cbe00c1db4d 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITProtoColumnTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITProtoColumnTest.java @@ -21,8 +21,11 @@ import static org.junit.Assume.assumeFalse; import com.google.cloud.ByteArray; +import com.google.cloud.spanner.Database; +import com.google.cloud.spanner.DatabaseAdminClient; import com.google.cloud.spanner.DatabaseClient; import com.google.cloud.spanner.DatabaseId; +import com.google.cloud.spanner.IntegrationTestEnv; import com.google.cloud.spanner.Key; import com.google.cloud.spanner.KeySet; import com.google.cloud.spanner.Mutation; @@ -30,52 +33,112 @@ import com.google.cloud.spanner.ResultSet; import com.google.cloud.spanner.SingerProto.Genre; import com.google.cloud.spanner.SingerProto.SingerInfo; -import com.google.cloud.spanner.Spanner; import com.google.cloud.spanner.SpannerException; -import com.google.cloud.spanner.SpannerOptions; import com.google.cloud.spanner.Statement; import com.google.cloud.spanner.testing.EmulatorSpannerHelper; +import com.google.cloud.spanner.testing.RemoteSpannerHelper; import com.google.common.collect.ImmutableList; import com.google.protobuf.AbstractMessage; import com.google.protobuf.InvalidProtocolBufferException.InvalidWireTypeException; import com.google.protobuf.ProtocolMessageEnum; import com.google.spanner.admin.database.v1.Backup; +import java.io.InputStream; import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.concurrent.TimeUnit; import org.junit.After; +import org.junit.AfterClass; import org.junit.BeforeClass; +import org.junit.ClassRule; import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -/** Integrations Tests to test Proto Columns & Enums */ +// Integration Tests to test DDL, DML and DQL for Proto Columns & Enums +// TODO(harsha): Check session leak warning @Category(ParallelIntegrationTest.class) @RunWith(JUnit4.class) public class ITProtoColumnTest { - private static String projectId; - private static String instanceId; - private static String databaseId; + + @ClassRule public static IntegrationTestEnv env = new IntegrationTestEnv(); + private static DatabaseId databaseID; + private static DatabaseAdminClient dbAdminClient; private static DatabaseClient databaseClient; @BeforeClass - public static void beforeClass() throws Exception { - assumeFalse( - "Proto Column is not supported in the emulator", EmulatorSpannerHelper.isUsingEmulator()); - // ToDo: Update project, instance and database parameter before GA - projectId = "span-cloud-testing"; - databaseId = "int_test_proto_column_db"; - instanceId = "integration-test-proto-column"; - - Spanner spanner = - SpannerOptions.newBuilder() - .setHost("https://staging-wrenchworks.sandbox.googleapis.com") - .setProjectId(projectId) - .build() - .getService(); - - databaseClient = spanner.getDatabaseClient(DatabaseId.of(projectId, instanceId, databaseId)); + public static void setUpDatabase() throws Exception { + RemoteSpannerHelper testHelper = env.getTestHelper(); + databaseID = DatabaseId.of(testHelper.getInstanceId(), testHelper.getUniqueDatabaseId()); + dbAdminClient = testHelper.getClient().getDatabaseAdminClient(); + createDatabase(); + databaseClient = testHelper.getClient().getDatabaseClient(databaseID); + } + + public static void createDatabase() throws Exception { + InputStream in = + ITProtoColumnTest.class + .getClassLoader() + .getResourceAsStream("com/google/cloud/spanner/descriptors.pb"); + final Database databaseToCreate = + dbAdminClient.newDatabaseBuilder(databaseID).setProtoDescriptors(in).build(); + final Database createdDatabase = + dbAdminClient + .createDatabase( + databaseToCreate, + Arrays.asList( + "CREATE PROTO BUNDLE (" + + "spanner.examples.music.SingerInfo," + + "spanner.examples.music.Genre," + + ")", + "CREATE TABLE Singers (" + + " SingerId INT64 NOT NULL," + + " FirstName STRING(1024)," + + " LastName STRING(1024)," + + " SingerInfo spanner.examples.music.SingerInfo," + + " SingerGenre spanner.examples.music.Genre," + + " SingerNationality STRING(1024) AS (SingerInfo.nationality) STORED," + + " ) PRIMARY KEY (SingerNationality, SingerGenre)", + "CREATE TABLE Types (" + + " RowID INT64 NOT NULL," + + " Int64a INT64," + + " Bytes BYTES(MAX)," + + " Int64Array ARRAY," + + " BytesArray ARRAY," + + " ProtoMessage spanner.examples.music.SingerInfo," + + " ProtoEnum spanner.examples.music.Genre," + + " ProtoMessageArray ARRAY," + + " ProtoEnumArray ARRAY," + + " ) PRIMARY KEY (RowID)", + "CREATE INDEX SingerByNationalityAndGenre ON Singers(SingerNationality, SingerGenre)" + + " STORING (SingerId, FirstName, LastName)")) + .get(5, TimeUnit.MINUTES); + + assertEquals(databaseID.getDatabase(), createdDatabase.getId().getDatabase()); + + // TODO(harsha): Check with backend team as this is not working for generated columns yet. + // GetDatabaseDdlResponse response = + // dbAdminClient.getDatabaseDdlResponse(databaseID.getInstanceId().getInstance(), + // databaseID.getDatabase()); + // assertNotNull(response.getProtoDescriptors()); + in.close(); + } + + @AfterClass + public static void afterClass() throws Exception { + try { + dbAdminClient.dropDatabase( + databaseID.getInstanceId().getInstance(), databaseID.getDatabase()); + } catch (Exception e) { + System.err.println( + "Failed to drop database " + + dbAdminClient + .getDatabase(databaseID.getInstanceId().getInstance(), databaseID.getDatabase()) + .getId() + + ", skipping...: " + + e.getMessage()); + } } @After @@ -85,23 +148,16 @@ public void after() throws Exception { } /** - * Test to check updates and read queries on Proto column and Enums and their arrays. Test also - * checks for compatability between following types: 1. Proto Messages & Bytes 2. Proto Enums & - * Int64 - * - *

Table `Types` was created through gcloud using following DDL: - * ************************************** CREATE TABLE Types ( RowID INT64 NOT NULL, Int64a INT64, - * Bytes BYTES(MAX), Int64Array ARRAY, BytesArray ARRAY, ProtoMessage - * spanner.examples.music.SingerInfo, ProtoEnum spanner.examples.music.Genre, ProtoMessageArray - * ARRAY, ProtoEnumArray ARRAY, ) - * PRIMARY KEY (RowID); ************************************** + * Test to check data update and read queries on Proto Messages, Proto Enums and their arrays. + * Test also checks for compatability between following types: 1. Proto Messages & Bytes 2. Proto + * Enums & Int64 */ @Test - public void testProtoUpdateAndRead() { + public void testProtoColumnsUpdateAndRead() { assumeFalse( "Proto Column is not supported in the emulator", EmulatorSpannerHelper.isUsingEmulator()); SingerInfo singerInfo = - SingerInfo.newBuilder().setSingerId(11).setNationality("Country1").build(); + SingerInfo.newBuilder().setSingerId(1).setNationality("Country1").build(); ByteArray singerInfoBytes = ByteArray.copyFrom(singerInfo.toByteArray()); Genre genre = Genre.JAZZ; @@ -124,7 +180,7 @@ public void testProtoUpdateAndRead() { ImmutableList.of( Mutation.newInsertOrUpdateBuilder("Types") .set("RowID") - .to(11) + .to(1) .set("Int64a") .to(genreConst) .set("Bytes") @@ -142,10 +198,10 @@ public void testProtoUpdateAndRead() { .set("ProtoEnumArray") .toProtoEnumArray(enumList, Genre.getDescriptor()) .build(), - //Inter Compatability check between ProtoMessages/Bytes and Int64/Enum. + // Inter Compatability check between ProtoMessages/Bytes and Int64/Enum. Mutation.newInsertOrUpdateBuilder("Types") .set("RowID") - .to(12) + .to(2) .set("Int64a") .to(genre) .set("Bytes") @@ -167,9 +223,9 @@ public void testProtoUpdateAndRead() { try (ResultSet resultSet = databaseClient.singleUse().executeQuery(Statement.of("SELECT * FROM " + "Types"))) { - for(int i=0;i<2;i++) { + for (int i = 0; i < 2; i++) { resultSet.next(); - assertEquals(11 + i, resultSet.getLong("RowID")); + assertEquals(i + 1, resultSet.getLong("RowID")); assertEquals(genreConst, resultSet.getLong("Int64a")); assertEquals(singerInfoBytes, resultSet.getBytes("Bytes")); assertEquals(enumConstList, resultSet.getLongList("Int64Array")); @@ -184,7 +240,8 @@ public void testProtoUpdateAndRead() { // Check compatability between Proto Messages & Bytes assertEquals(singerInfoBytes, resultSet.getBytes("ProtoMessage")); - assertEquals(singerInfo, resultSet.getProtoMessage("Bytes", SingerInfo.getDefaultInstance())); + assertEquals( + singerInfo, resultSet.getProtoMessage("Bytes", SingerInfo.getDefaultInstance())); assertEquals(singerInfoBytesList, resultSet.getBytesList("ProtoMessageArray")); assertEquals( @@ -201,31 +258,18 @@ public void testProtoUpdateAndRead() { } } - /** - * Test to check Parameterized Queries, Primary Keys and Indexes. - * - *

Table `Singers` and Index `SingerByNationalityAndGenre` for Proto column integration tests - * is created through gcloud using following DDL: - * - *

************************************** CREATE TABLE Singers ( SingerId INT64 NOT NULL, - * FirstName STRING(1024), LastName STRING(1024), SingerInfo spanner.examples.music.SingerInfo, - * SingerGenre spanner.examples.music.Genre, SingerNationality STRING(1024) AS - * (SingerInfo.nationality) STORED, ) PRIMARY KEY (SingerNationality, SingerGenre); - * - *

CREATE INDEX SingerByNationalityAndGenre ON Singers(SingerNationality, SingerGenre) STORING - * (SingerId, FirstName, LastName); ************************************** - */ + // Test to check Parameterized Queries, Primary Keys and Indexes. @Test - public void testProtoColumnsDMLParameterizedQueriesAndPKIndexes() { + public void testProtoColumnsDMLParameterizedQueriesPKAndIndexes() { assumeFalse( "Proto Column is not supported in the emulator", EmulatorSpannerHelper.isUsingEmulator()); SingerInfo singerInfo1 = - SingerInfo.newBuilder().setSingerId(11).setNationality("Country1").build(); + SingerInfo.newBuilder().setSingerId(1).setNationality("Country1").build(); Genre genre1 = Genre.FOLK; SingerInfo singerInfo2 = - SingerInfo.newBuilder().setSingerId(11).setNationality("Country2").build(); + SingerInfo.newBuilder().setSingerId(2).setNationality("Country2").build(); Genre genre2 = Genre.JAZZ; databaseClient @@ -234,7 +278,7 @@ public void testProtoColumnsDMLParameterizedQueriesAndPKIndexes() { transaction -> { Statement statement1 = Statement.newBuilder( - "INSERT INTO Singers (SingerId, FirstName, LastName, SingerInfo, SingerGenre) VALUES (11, \"FirstName1\", \"LastName1\", @singerInfo, @singerGenre)") + "INSERT INTO Singers (SingerId, FirstName, LastName, SingerInfo, SingerGenre) VALUES (1, \"FirstName1\", \"LastName1\", @singerInfo, @singerGenre)") .bind("singerInfo") .to(singerInfo1) .bind("singerGenre") @@ -243,7 +287,7 @@ public void testProtoColumnsDMLParameterizedQueriesAndPKIndexes() { Statement statement2 = Statement.newBuilder( - "INSERT INTO Singers (SingerId, FirstName, LastName, SingerInfo, SingerGenre) VALUES (22, \"FirstName2\", \"LastName2\", @singerInfo, @singerGenre)") + "INSERT INTO Singers (SingerId, FirstName, LastName, SingerInfo, SingerGenre) VALUES (2, \"FirstName2\", \"LastName2\", @singerInfo, @singerGenre)") .bind("singerInfo") .to(singerInfo2) .bind("singerGenre") @@ -267,7 +311,7 @@ public void testProtoColumnsDMLParameterizedQueriesAndPKIndexes() { Arrays.asList("SingerId", "FirstName", "LastName", "SingerInfo", "SingerGenre")); resultSet1.next(); - assertEquals(11, resultSet1.getLong("SingerId")); + assertEquals(1, resultSet1.getLong("SingerId")); assertEquals("FirstName1", resultSet1.getString("FirstName")); assertEquals("LastName1", resultSet1.getString("LastName")); assertEquals( @@ -275,7 +319,7 @@ public void testProtoColumnsDMLParameterizedQueriesAndPKIndexes() { assertEquals(genre1, resultSet1.getProtoEnum("SingerGenre", Genre::forNumber)); resultSet1.next(); - assertEquals(22, resultSet1.getLong("SingerId")); + assertEquals(2, resultSet1.getLong("SingerId")); assertEquals("FirstName2", resultSet1.getString("FirstName")); assertEquals("LastName2", resultSet1.getString("LastName")); assertEquals( @@ -292,7 +336,7 @@ public void testProtoColumnsDMLParameterizedQueriesAndPKIndexes() { KeySet.singleKey(Key.of("Country2", Genre.JAZZ)), Arrays.asList("SingerId", "FirstName", "LastName")); resultSet2.next(); - assertEquals(22, resultSet2.getLong("SingerId")); + assertEquals(2, resultSet2.getLong("SingerId")); assertEquals("FirstName2", resultSet2.getString("FirstName")); assertEquals("LastName2", resultSet2.getString("LastName")); @@ -311,29 +355,27 @@ public void testProtoColumnsDMLParameterizedQueriesAndPKIndexes() { .build()); resultSet3.next(); - assertEquals(22, resultSet1.getLong("SingerId")); + assertEquals(2, resultSet1.getLong("SingerId")); assertEquals( singerInfo2, resultSet1.getProtoMessage("SingerInfo", SingerInfo.getDefaultInstance())); assertEquals(genre2, resultSet1.getProtoEnum("SingerGenre", Genre::forNumber)); } - /** - * Test the exception in case Invalid protocol message object is provided while deserializing the - * data. - */ + // Test the exception in case Invalid protocol message object is provided while deserializing the + // data. @Test public void testProtoMessageDeserializationError() { assumeFalse( "Proto Column is not supported in the emulator", EmulatorSpannerHelper.isUsingEmulator()); SingerInfo singerInfo = - SingerInfo.newBuilder().setSingerId(11).setNationality("Country1").build(); + SingerInfo.newBuilder().setSingerId(1).setNationality("Country1").build(); databaseClient.write( ImmutableList.of( Mutation.newInsertOrUpdateBuilder("Types") .set("RowID") - .to(11) + .to(1) .set("ProtoMessage") .to(singerInfo) .build())); diff --git a/google-cloud-spanner/src/test/resources/com/google/cloud/spanner/descriptors.pb b/google-cloud-spanner/src/test/resources/com/google/cloud/spanner/descriptors.pb new file mode 100644 index 0000000000000000000000000000000000000000..3ebb79420b3ffd2ca3b3b57433a4a10bfa22b675 GIT binary patch literal 251 zcmd=3!N|o^oSB!NTBKJ{lwXoBBvxFIn3o6SrdA~87UZNB>*bafXC^DnXXN4v1}pT; zOUoCM=Hi5Ci_c7vU{qk#U=HGd2zaIl$#QWeWfqlW#HS>dq)IRWWjTX5!6Gg|0U-r0 z?!3g3%>2B>oXnC+31+Z7vXGE57i)TIUQwz93s8>FNLCNKqx9TCih>|&we+}H!F(Zh lF6IFL009Oe4lWii$EYX)Mi9%*-^W{k3B(HWclH)w1^^+RM@0Yt literal 0 HcmV?d00001 diff --git a/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/CreateDatabaseRequest.java b/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/CreateDatabaseRequest.java index 067490d01b5..2b2b510e56e 100644 --- a/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/CreateDatabaseRequest.java +++ b/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/CreateDatabaseRequest.java @@ -42,6 +42,7 @@ private CreateDatabaseRequest() { createStatement_ = ""; extraStatements_ = com.google.protobuf.LazyStringArrayList.EMPTY; databaseDialect_ = 0; + protoDescriptors_ = com.google.protobuf.ByteString.EMPTY; } @java.lang.Override @@ -358,6 +359,38 @@ public com.google.spanner.admin.database.v1.DatabaseDialect getDatabaseDialect() : result; } + public static final int PROTO_DESCRIPTORS_FIELD_NUMBER = 6; + private com.google.protobuf.ByteString protoDescriptors_; + /** + * + * + *

+   * Proto descriptors used by CREATE/ALTER PROTO BUNDLE statements in
+   * 'extra_statements' above.
+   * Contains a protobuf-serialized
+   * [google.protobuf.FileDescriptorSet](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto).
+   * To generate it, [install](https://grpc.io/docs/protoc-installation/) and
+   * run `protoc` with --include_imports and --descriptor_set_out. For example,
+   * to generate for moon/shot/app.proto, run
+   * """
+   * $protoc  --proto_path=/app_path --proto_path=/lib_path \
+   *          --include_imports \
+   *          --descriptor_set_out=descriptors.data \
+   *          moon/shot/app.proto
+   * """
+   * For more details, see protobuffer [self
+   * description](https://developers.google.com/protocol-buffers/docs/techniques#self-description).
+   * 
+ * + * bytes proto_descriptors = 6 [(.google.api.field_behavior) = OPTIONAL]; + * + * @return The protoDescriptors. + */ + @java.lang.Override + public com.google.protobuf.ByteString getProtoDescriptors() { + return protoDescriptors_; + } + private byte memoizedIsInitialized = -1; @java.lang.Override @@ -389,6 +422,9 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io .getNumber()) { output.writeEnum(5, databaseDialect_); } + if (!protoDescriptors_.isEmpty()) { + output.writeBytes(6, protoDescriptors_); + } getUnknownFields().writeTo(output); } @@ -420,6 +456,9 @@ public int getSerializedSize() { .getNumber()) { size += com.google.protobuf.CodedOutputStream.computeEnumSize(5, databaseDialect_); } + if (!protoDescriptors_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream.computeBytesSize(6, protoDescriptors_); + } size += getUnknownFields().getSerializedSize(); memoizedSize = size; return size; @@ -444,6 +483,7 @@ public boolean equals(final java.lang.Object obj) { if (!getEncryptionConfig().equals(other.getEncryptionConfig())) return false; } if (databaseDialect_ != other.databaseDialect_) return false; + if (!getProtoDescriptors().equals(other.getProtoDescriptors())) return false; if (!getUnknownFields().equals(other.getUnknownFields())) return false; return true; } @@ -469,6 +509,8 @@ public int hashCode() { } hash = (37 * hash) + DATABASE_DIALECT_FIELD_NUMBER; hash = (53 * hash) + databaseDialect_; + hash = (37 * hash) + PROTO_DESCRIPTORS_FIELD_NUMBER; + hash = (53 * hash) + getProtoDescriptors().hashCode(); hash = (29 * hash) + getUnknownFields().hashCode(); memoizedHashCode = hash; return hash; @@ -622,6 +664,8 @@ public Builder clear() { } databaseDialect_ = 0; + protoDescriptors_ = com.google.protobuf.ByteString.EMPTY; + return this; } @@ -663,6 +707,7 @@ public com.google.spanner.admin.database.v1.CreateDatabaseRequest buildPartial() result.encryptionConfig_ = encryptionConfigBuilder_.build(); } result.databaseDialect_ = databaseDialect_; + result.protoDescriptors_ = protoDescriptors_; onBuilt(); return result; } @@ -737,6 +782,9 @@ public Builder mergeFrom(com.google.spanner.admin.database.v1.CreateDatabaseRequ if (other.databaseDialect_ != 0) { setDatabaseDialectValue(other.getDatabaseDialectValue()); } + if (other.getProtoDescriptors() != com.google.protobuf.ByteString.EMPTY) { + setProtoDescriptors(other.getProtoDescriptors()); + } this.mergeUnknownFields(other.getUnknownFields()); onChanged(); return this; @@ -795,6 +843,12 @@ public Builder mergeFrom( break; } // case 40 + case 50: + { + protoDescriptors_ = input.readBytes(); + + break; + } // case 50 default: { if (!super.parseUnknownField(input, extensionRegistry, tag)) { @@ -1585,6 +1639,103 @@ public Builder clearDatabaseDialect() { return this; } + private com.google.protobuf.ByteString protoDescriptors_ = com.google.protobuf.ByteString.EMPTY; + /** + * + * + *
+     * Proto descriptors used by CREATE/ALTER PROTO BUNDLE statements in
+     * 'extra_statements' above.
+     * Contains a protobuf-serialized
+     * [google.protobuf.FileDescriptorSet](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto).
+     * To generate it, [install](https://grpc.io/docs/protoc-installation/) and
+     * run `protoc` with --include_imports and --descriptor_set_out. For example,
+     * to generate for moon/shot/app.proto, run
+     * """
+     * $protoc  --proto_path=/app_path --proto_path=/lib_path \
+     *          --include_imports \
+     *          --descriptor_set_out=descriptors.data \
+     *          moon/shot/app.proto
+     * """
+     * For more details, see protobuffer [self
+     * description](https://developers.google.com/protocol-buffers/docs/techniques#self-description).
+     * 
+ * + * bytes proto_descriptors = 6 [(.google.api.field_behavior) = OPTIONAL]; + * + * @return The protoDescriptors. + */ + @java.lang.Override + public com.google.protobuf.ByteString getProtoDescriptors() { + return protoDescriptors_; + } + /** + * + * + *
+     * Proto descriptors used by CREATE/ALTER PROTO BUNDLE statements in
+     * 'extra_statements' above.
+     * Contains a protobuf-serialized
+     * [google.protobuf.FileDescriptorSet](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto).
+     * To generate it, [install](https://grpc.io/docs/protoc-installation/) and
+     * run `protoc` with --include_imports and --descriptor_set_out. For example,
+     * to generate for moon/shot/app.proto, run
+     * """
+     * $protoc  --proto_path=/app_path --proto_path=/lib_path \
+     *          --include_imports \
+     *          --descriptor_set_out=descriptors.data \
+     *          moon/shot/app.proto
+     * """
+     * For more details, see protobuffer [self
+     * description](https://developers.google.com/protocol-buffers/docs/techniques#self-description).
+     * 
+ * + * bytes proto_descriptors = 6 [(.google.api.field_behavior) = OPTIONAL]; + * + * @param value The protoDescriptors to set. + * @return This builder for chaining. + */ + public Builder setProtoDescriptors(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + + protoDescriptors_ = value; + onChanged(); + return this; + } + /** + * + * + *
+     * Proto descriptors used by CREATE/ALTER PROTO BUNDLE statements in
+     * 'extra_statements' above.
+     * Contains a protobuf-serialized
+     * [google.protobuf.FileDescriptorSet](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto).
+     * To generate it, [install](https://grpc.io/docs/protoc-installation/) and
+     * run `protoc` with --include_imports and --descriptor_set_out. For example,
+     * to generate for moon/shot/app.proto, run
+     * """
+     * $protoc  --proto_path=/app_path --proto_path=/lib_path \
+     *          --include_imports \
+     *          --descriptor_set_out=descriptors.data \
+     *          moon/shot/app.proto
+     * """
+     * For more details, see protobuffer [self
+     * description](https://developers.google.com/protocol-buffers/docs/techniques#self-description).
+     * 
+ * + * bytes proto_descriptors = 6 [(.google.api.field_behavior) = OPTIONAL]; + * + * @return This builder for chaining. + */ + public Builder clearProtoDescriptors() { + + protoDescriptors_ = getDefaultInstance().getProtoDescriptors(); + onChanged(); + return this; + } + @java.lang.Override public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { return super.setUnknownFields(unknownFields); diff --git a/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/CreateDatabaseRequestOrBuilder.java b/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/CreateDatabaseRequestOrBuilder.java index 537e9c161fa..f9699e13d91 100644 --- a/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/CreateDatabaseRequestOrBuilder.java +++ b/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/CreateDatabaseRequestOrBuilder.java @@ -225,4 +225,31 @@ public interface CreateDatabaseRequestOrBuilder * @return The databaseDialect. */ com.google.spanner.admin.database.v1.DatabaseDialect getDatabaseDialect(); + + /** + * + * + *
+   * Proto descriptors used by CREATE/ALTER PROTO BUNDLE statements in
+   * 'extra_statements' above.
+   * Contains a protobuf-serialized
+   * [google.protobuf.FileDescriptorSet](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto).
+   * To generate it, [install](https://grpc.io/docs/protoc-installation/) and
+   * run `protoc` with --include_imports and --descriptor_set_out. For example,
+   * to generate for moon/shot/app.proto, run
+   * """
+   * $protoc  --proto_path=/app_path --proto_path=/lib_path \
+   *          --include_imports \
+   *          --descriptor_set_out=descriptors.data \
+   *          moon/shot/app.proto
+   * """
+   * For more details, see protobuffer [self
+   * description](https://developers.google.com/protocol-buffers/docs/techniques#self-description).
+   * 
+ * + * bytes proto_descriptors = 6 [(.google.api.field_behavior) = OPTIONAL]; + * + * @return The protoDescriptors. + */ + com.google.protobuf.ByteString getProtoDescriptors(); } diff --git a/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/GetDatabaseDdlResponse.java b/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/GetDatabaseDdlResponse.java index 39078a788f9..8a34b0f1df6 100644 --- a/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/GetDatabaseDdlResponse.java +++ b/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/GetDatabaseDdlResponse.java @@ -39,6 +39,7 @@ private GetDatabaseDdlResponse(com.google.protobuf.GeneratedMessageV3.Builder private GetDatabaseDdlResponse() { statements_ = com.google.protobuf.LazyStringArrayList.EMPTY; + protoDescriptors_ = com.google.protobuf.ByteString.EMPTY; } @java.lang.Override @@ -132,6 +133,28 @@ public com.google.protobuf.ByteString getStatementsBytes(int index) { return statements_.getByteString(index); } + public static final int PROTO_DESCRIPTORS_FIELD_NUMBER = 2; + private com.google.protobuf.ByteString protoDescriptors_; + /** + * + * + *
+   * Proto descriptors stored in the database.
+   * Contains a protobuf-serialized
+   * [google.protobuf.FileDescriptorSet](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto).
+   * For more details, see protobuffer [self
+   * description](https://developers.google.com/protocol-buffers/docs/techniques#self-description).
+   * 
+ * + * bytes proto_descriptors = 2; + * + * @return The protoDescriptors. + */ + @java.lang.Override + public com.google.protobuf.ByteString getProtoDescriptors() { + return protoDescriptors_; + } + private byte memoizedIsInitialized = -1; @java.lang.Override @@ -149,6 +172,9 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io for (int i = 0; i < statements_.size(); i++) { com.google.protobuf.GeneratedMessageV3.writeString(output, 1, statements_.getRaw(i)); } + if (!protoDescriptors_.isEmpty()) { + output.writeBytes(2, protoDescriptors_); + } getUnknownFields().writeTo(output); } @@ -166,6 +192,9 @@ public int getSerializedSize() { size += dataSize; size += 1 * getStatementsList().size(); } + if (!protoDescriptors_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream.computeBytesSize(2, protoDescriptors_); + } size += getUnknownFields().getSerializedSize(); memoizedSize = size; return size; @@ -183,6 +212,7 @@ public boolean equals(final java.lang.Object obj) { (com.google.spanner.admin.database.v1.GetDatabaseDdlResponse) obj; if (!getStatementsList().equals(other.getStatementsList())) return false; + if (!getProtoDescriptors().equals(other.getProtoDescriptors())) return false; if (!getUnknownFields().equals(other.getUnknownFields())) return false; return true; } @@ -198,6 +228,8 @@ public int hashCode() { hash = (37 * hash) + STATEMENTS_FIELD_NUMBER; hash = (53 * hash) + getStatementsList().hashCode(); } + hash = (37 * hash) + PROTO_DESCRIPTORS_FIELD_NUMBER; + hash = (53 * hash) + getProtoDescriptors().hashCode(); hash = (29 * hash) + getUnknownFields().hashCode(); memoizedHashCode = hash; return hash; @@ -339,6 +371,8 @@ public Builder clear() { super.clear(); statements_ = com.google.protobuf.LazyStringArrayList.EMPTY; bitField0_ = (bitField0_ & ~0x00000001); + protoDescriptors_ = com.google.protobuf.ByteString.EMPTY; + return this; } @@ -372,6 +406,7 @@ public com.google.spanner.admin.database.v1.GetDatabaseDdlResponse buildPartial( bitField0_ = (bitField0_ & ~0x00000001); } result.statements_ = statements_; + result.protoDescriptors_ = protoDescriptors_; onBuilt(); return result; } @@ -432,6 +467,9 @@ public Builder mergeFrom(com.google.spanner.admin.database.v1.GetDatabaseDdlResp } onChanged(); } + if (other.getProtoDescriptors() != com.google.protobuf.ByteString.EMPTY) { + setProtoDescriptors(other.getProtoDescriptors()); + } this.mergeUnknownFields(other.getUnknownFields()); onChanged(); return this; @@ -465,6 +503,12 @@ public Builder mergeFrom( statements_.add(s); break; } // case 10 + case 18: + { + protoDescriptors_ = input.readBytes(); + + break; + } // case 18 default: { if (!super.parseUnknownField(input, extensionRegistry, tag)) { @@ -661,6 +705,73 @@ public Builder addStatementsBytes(com.google.protobuf.ByteString value) { return this; } + private com.google.protobuf.ByteString protoDescriptors_ = com.google.protobuf.ByteString.EMPTY; + /** + * + * + *
+     * Proto descriptors stored in the database.
+     * Contains a protobuf-serialized
+     * [google.protobuf.FileDescriptorSet](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto).
+     * For more details, see protobuffer [self
+     * description](https://developers.google.com/protocol-buffers/docs/techniques#self-description).
+     * 
+ * + * bytes proto_descriptors = 2; + * + * @return The protoDescriptors. + */ + @java.lang.Override + public com.google.protobuf.ByteString getProtoDescriptors() { + return protoDescriptors_; + } + /** + * + * + *
+     * Proto descriptors stored in the database.
+     * Contains a protobuf-serialized
+     * [google.protobuf.FileDescriptorSet](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto).
+     * For more details, see protobuffer [self
+     * description](https://developers.google.com/protocol-buffers/docs/techniques#self-description).
+     * 
+ * + * bytes proto_descriptors = 2; + * + * @param value The protoDescriptors to set. + * @return This builder for chaining. + */ + public Builder setProtoDescriptors(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + + protoDescriptors_ = value; + onChanged(); + return this; + } + /** + * + * + *
+     * Proto descriptors stored in the database.
+     * Contains a protobuf-serialized
+     * [google.protobuf.FileDescriptorSet](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto).
+     * For more details, see protobuffer [self
+     * description](https://developers.google.com/protocol-buffers/docs/techniques#self-description).
+     * 
+ * + * bytes proto_descriptors = 2; + * + * @return This builder for chaining. + */ + public Builder clearProtoDescriptors() { + + protoDescriptors_ = getDefaultInstance().getProtoDescriptors(); + onChanged(); + return this; + } + @java.lang.Override public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { return super.setUnknownFields(unknownFields); diff --git a/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/GetDatabaseDdlResponseOrBuilder.java b/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/GetDatabaseDdlResponseOrBuilder.java index 28f7fb2cc5c..8f45b73c48c 100644 --- a/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/GetDatabaseDdlResponseOrBuilder.java +++ b/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/GetDatabaseDdlResponseOrBuilder.java @@ -77,4 +77,21 @@ public interface GetDatabaseDdlResponseOrBuilder * @return The bytes of the statements at the given index. */ com.google.protobuf.ByteString getStatementsBytes(int index); + + /** + * + * + *
+   * Proto descriptors stored in the database.
+   * Contains a protobuf-serialized
+   * [google.protobuf.FileDescriptorSet](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto).
+   * For more details, see protobuffer [self
+   * description](https://developers.google.com/protocol-buffers/docs/techniques#self-description).
+   * 
+ * + * bytes proto_descriptors = 2; + * + * @return The protoDescriptors. + */ + com.google.protobuf.ByteString getProtoDescriptors(); } diff --git a/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/SpannerDatabaseAdminProto.java b/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/SpannerDatabaseAdminProto.java index 9a4c1888ef2..8a0a0250c2f 100644 --- a/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/SpannerDatabaseAdminProto.java +++ b/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/SpannerDatabaseAdminProto.java @@ -161,7 +161,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { + "\030\003 \001(\005\022\022\n\npage_token\030\004 \001(\t\"o\n\025ListDataba" + "sesResponse\022=\n\tdatabases\030\001 \003(\0132*.google." + "spanner.admin.database.v1.Database\022\027\n\017ne" - + "xt_page_token\030\002 \001(\t\"\264\002\n\025CreateDatabaseRe" + + "xt_page_token\030\002 \001(\t\"\324\002\n\025CreateDatabaseRe" + "quest\0227\n\006parent\030\001 \001(\tB\'\340A\002\372A!\n\037spanner.g" + "oogleapis.com/Instance\022\035\n\020create_stateme" + "nt\030\002 \001(\tB\003\340A\002\022\035\n\020extra_statements\030\003 \003(\tB" @@ -169,198 +169,200 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { + ".spanner.admin.database.v1.EncryptionCon" + "figB\003\340A\001\022P\n\020database_dialect\030\005 \001(\01621.goo" + "gle.spanner.admin.database.v1.DatabaseDi" - + "alectB\003\340A\001\"P\n\026CreateDatabaseMetadata\0226\n\010" - + "database\030\001 \001(\tB$\372A!\n\037spanner.googleapis." - + "com/Database\"K\n\022GetDatabaseRequest\0225\n\004na" - + "me\030\001 \001(\tB\'\340A\002\372A!\n\037spanner.googleapis.com" - + "/Database\"\204\001\n\030UpdateDatabaseDdlRequest\0229" - + "\n\010database\030\001 \001(\tB\'\340A\002\372A!\n\037spanner.google" - + "apis.com/Database\022\027\n\nstatements\030\002 \003(\tB\003\340" - + "A\002\022\024\n\014operation_id\030\003 \001(\t\"\375\001\n\031UpdateDatab" - + "aseDdlMetadata\0226\n\010database\030\001 \001(\tB$\372A!\n\037s" - + "panner.googleapis.com/Database\022\022\n\nstatem" - + "ents\030\002 \003(\t\0225\n\021commit_timestamps\030\003 \003(\0132\032." - + "google.protobuf.Timestamp\022\026\n\tthrottled\030\004" - + " \001(\010B\003\340A\003\022E\n\010progress\030\005 \003(\01323.google.spa" - + "nner.admin.database.v1.OperationProgress" - + "\"P\n\023DropDatabaseRequest\0229\n\010database\030\001 \001(" - + "\tB\'\340A\002\372A!\n\037spanner.googleapis.com/Databa" - + "se\"R\n\025GetDatabaseDdlRequest\0229\n\010database\030" - + "\001 \001(\tB\'\340A\002\372A!\n\037spanner.googleapis.com/Da" - + "tabase\",\n\026GetDatabaseDdlResponse\022\022\n\nstat" - + "ements\030\001 \003(\t\"\217\001\n\035ListDatabaseOperationsR" - + "equest\0227\n\006parent\030\001 \001(\tB\'\340A\002\372A!\n\037spanner." - + "googleapis.com/Instance\022\016\n\006filter\030\002 \001(\t\022" - + "\021\n\tpage_size\030\003 \001(\005\022\022\n\npage_token\030\004 \001(\t\"l" - + "\n\036ListDatabaseOperationsResponse\0221\n\noper" - + "ations\030\001 \003(\0132\035.google.longrunning.Operat" - + "ion\022\027\n\017next_page_token\030\002 \001(\t\"\216\002\n\026Restore" - + "DatabaseRequest\0227\n\006parent\030\001 \001(\tB\'\340A\002\372A!\n" - + "\037spanner.googleapis.com/Instance\022\030\n\013data" - + "base_id\030\002 \001(\tB\003\340A\002\0224\n\006backup\030\003 \001(\tB\"\372A\037\n" - + "\035spanner.googleapis.com/BackupH\000\022a\n\021encr" - + "yption_config\030\004 \001(\0132A.google.spanner.adm" - + "in.database.v1.RestoreDatabaseEncryption" - + "ConfigB\003\340A\001B\010\n\006source\"\363\002\n\037RestoreDatabas" - + "eEncryptionConfig\022n\n\017encryption_type\030\001 \001" - + "(\0162P.google.spanner.admin.database.v1.Re" - + "storeDatabaseEncryptionConfig.Encryption" - + "TypeB\003\340A\002\022?\n\014kms_key_name\030\002 \001(\tB)\340A\001\372A#\n" - + "!cloudkms.googleapis.com/CryptoKey\"\236\001\n\016E" - + "ncryptionType\022\037\n\033ENCRYPTION_TYPE_UNSPECI" - + "FIED\020\000\022+\n\'USE_CONFIG_DEFAULT_OR_BACKUP_E" - + "NCRYPTION\020\001\022\035\n\031GOOGLE_DEFAULT_ENCRYPTION" - + "\020\002\022\037\n\033CUSTOMER_MANAGED_ENCRYPTION\020\003\"\215\003\n\027" - + "RestoreDatabaseMetadata\0222\n\004name\030\001 \001(\tB$\372" - + "A!\n\037spanner.googleapis.com/Database\022H\n\013s" - + "ource_type\030\002 \001(\01623.google.spanner.admin." - + "database.v1.RestoreSourceType\022C\n\013backup_" - + "info\030\003 \001(\0132,.google.spanner.admin.databa" - + "se.v1.BackupInfoH\000\022E\n\010progress\030\004 \001(\01323.g" - + "oogle.spanner.admin.database.v1.Operatio" - + "nProgress\022/\n\013cancel_time\030\005 \001(\0132\032.google." - + "protobuf.Timestamp\022(\n optimize_database_" - + "operation_name\030\006 \001(\tB\r\n\013source_info\"\235\001\n " - + "OptimizeRestoredDatabaseMetadata\0222\n\004name" + + "alectB\003\340A\001\022\036\n\021proto_descriptors\030\006 \001(\014B\003\340" + + "A\001\"P\n\026CreateDatabaseMetadata\0226\n\010database" + "\030\001 \001(\tB$\372A!\n\037spanner.googleapis.com/Data" - + "base\022E\n\010progress\030\002 \001(\01323.google.spanner." - + "admin.database.v1.OperationProgress\"\236\001\n\014" - + "DatabaseRole\022\021\n\004name\030\001 \001(\tB\003\340A\002:{\352Ax\n#sp" - + "anner.googleapis.com/DatabaseRole\022Qproje" - + "cts/{project}/instances/{instance}/datab" - + "ases/{database}/databaseRoles/{role}\"z\n\030" - + "ListDatabaseRolesRequest\0227\n\006parent\030\001 \001(\t" + + "base\"K\n\022GetDatabaseRequest\0225\n\004name\030\001 \001(\t" + "B\'\340A\002\372A!\n\037spanner.googleapis.com/Databas" - + "e\022\021\n\tpage_size\030\002 \001(\005\022\022\n\npage_token\030\003 \001(\t" - + "\"|\n\031ListDatabaseRolesResponse\022F\n\016databas" - + "e_roles\030\001 \003(\0132..google.spanner.admin.dat" - + "abase.v1.DatabaseRole\022\027\n\017next_page_token" - + "\030\002 \001(\t*5\n\021RestoreSourceType\022\024\n\020TYPE_UNSP" - + "ECIFIED\020\000\022\n\n\006BACKUP\020\0012\374#\n\rDatabaseAdmin\022" - + "\300\001\n\rListDatabases\0226.google.spanner.admin" - + ".database.v1.ListDatabasesRequest\0327.goog" - + "le.spanner.admin.database.v1.ListDatabas" - + "esResponse\">\202\323\344\223\002/\022-/v1/{parent=projects" - + "/*/instances/*}/databases\332A\006parent\022\244\002\n\016C" - + "reateDatabase\0227.google.spanner.admin.dat" - + "abase.v1.CreateDatabaseRequest\032\035.google." - + "longrunning.Operation\"\271\001\202\323\344\223\0022\"-/v1/{par" - + "ent=projects/*/instances/*}/databases:\001*" - + "\332A\027parent,create_statement\312Ad\n)google.sp" - + "anner.admin.database.v1.Database\0227google" - + ".spanner.admin.database.v1.CreateDatabas" - + "eMetadata\022\255\001\n\013GetDatabase\0224.google.spann" - + "er.admin.database.v1.GetDatabaseRequest\032" - + "*.google.spanner.admin.database.v1.Datab" - + "ase\"<\202\323\344\223\002/\022-/v1/{name=projects/*/instan" - + "ces/*/databases/*}\332A\004name\022\235\002\n\021UpdateData" - + "baseDdl\022:.google.spanner.admin.database." - + "v1.UpdateDatabaseDdlRequest\032\035.google.lon" - + "grunning.Operation\"\254\001\202\323\344\223\002:25/v1/{databa" - + "se=projects/*/instances/*/databases/*}/d" - + "dl:\001*\332A\023database,statements\312AS\n\025google.p" - + "rotobuf.Empty\022:google.spanner.admin.data" - + "base.v1.UpdateDatabaseDdlMetadata\022\243\001\n\014Dr" - + "opDatabase\0225.google.spanner.admin.databa" - + "se.v1.DropDatabaseRequest\032\026.google.proto" - + "buf.Empty\"D\202\323\344\223\0023*1/v1/{database=project" - + "s/*/instances/*/databases/*}\332A\010database\022" - + "\315\001\n\016GetDatabaseDdl\0227.google.spanner.admi" - + "n.database.v1.GetDatabaseDdlRequest\0328.go" - + "ogle.spanner.admin.database.v1.GetDataba" - + "seDdlResponse\"H\202\323\344\223\0027\0225/v1/{database=pro" - + "jects/*/instances/*/databases/*}/ddl\332A\010d" - + "atabase\022\353\001\n\014SetIamPolicy\022\".google.iam.v1" - + ".SetIamPolicyRequest\032\025.google.iam.v1.Pol" - + "icy\"\237\001\202\323\344\223\002\206\001\">/v1/{resource=projects/*/" - + "instances/*/databases/*}:setIamPolicy:\001*" - + "ZA\"/v1/{resource=projects/*/in" - + "stances/*/databases/*}:getIamPolicy:\001*ZA" - + "\".google.sp" - + "anner.admin.database.v1.ListBackupOperat" - + "ionsResponse\"E\202\323\344\223\0026\0224/v1/{parent=projec" - + "ts/*/instances/*}/backupOperations\332A\006par" - + "ent\022\334\001\n\021ListDatabaseRoles\022:.google.spann" - + "er.admin.database.v1.ListDatabaseRolesRe" - + "quest\032;.google.spanner.admin.database.v1" - + ".ListDatabaseRolesResponse\"N\202\323\344\223\002?\022=/v1/" - + "{parent=projects/*/instances/*/databases" - + "/*}/databaseRoles\332A\006parent\032x\312A\026spanner.g" - + "oogleapis.com\322A\\https://www.googleapis.c" - + "om/auth/cloud-platform,https://www.googl" - + "eapis.com/auth/spanner.adminB\332\002\n$com.goo" - + "gle.spanner.admin.database.v1B\031SpannerDa" - + "tabaseAdminProtoP\001ZHgoogle.golang.org/ge" - + "nproto/googleapis/spanner/admin/database" - + "/v1;database\252\002&Google.Cloud.Spanner.Admi" - + "n.Database.V1\312\002&Google\\Cloud\\Spanner\\Adm" - + "in\\Database\\V1\352\002+Google::Cloud::Spanner:" - + ":Admin::Database::V1\352AJ\n\037spanner.googlea" - + "pis.com/Instance\022\'projects/{project}/ins" - + "tances/{instance}b\006proto3" + + "e\"\244\001\n\030UpdateDatabaseDdlRequest\0229\n\010databa" + + "se\030\001 \001(\tB\'\340A\002\372A!\n\037spanner.googleapis.com" + + "/Database\022\027\n\nstatements\030\002 \003(\tB\003\340A\002\022\024\n\014op" + + "eration_id\030\003 \001(\t\022\036\n\021proto_descriptors\030\004 " + + "\001(\014B\003\340A\001\"\375\001\n\031UpdateDatabaseDdlMetadata\0226" + + "\n\010database\030\001 \001(\tB$\372A!\n\037spanner.googleapi" + + "s.com/Database\022\022\n\nstatements\030\002 \003(\t\0225\n\021co" + + "mmit_timestamps\030\003 \003(\0132\032.google.protobuf." + + "Timestamp\022\026\n\tthrottled\030\004 \001(\010B\003\340A\003\022E\n\010pro" + + "gress\030\005 \003(\01323.google.spanner.admin.datab" + + "ase.v1.OperationProgress\"P\n\023DropDatabase" + + "Request\0229\n\010database\030\001 \001(\tB\'\340A\002\372A!\n\037spann" + + "er.googleapis.com/Database\"R\n\025GetDatabas" + + "eDdlRequest\0229\n\010database\030\001 \001(\tB\'\340A\002\372A!\n\037s" + + "panner.googleapis.com/Database\"G\n\026GetDat" + + "abaseDdlResponse\022\022\n\nstatements\030\001 \003(\t\022\031\n\021" + + "proto_descriptors\030\002 \001(\014\"\217\001\n\035ListDatabase" + + "OperationsRequest\0227\n\006parent\030\001 \001(\tB\'\340A\002\372A" + + "!\n\037spanner.googleapis.com/Instance\022\016\n\006fi" + + "lter\030\002 \001(\t\022\021\n\tpage_size\030\003 \001(\005\022\022\n\npage_to" + + "ken\030\004 \001(\t\"l\n\036ListDatabaseOperationsRespo" + + "nse\0221\n\noperations\030\001 \003(\0132\035.google.longrun" + + "ning.Operation\022\027\n\017next_page_token\030\002 \001(\t\"" + + "\216\002\n\026RestoreDatabaseRequest\0227\n\006parent\030\001 \001" + + "(\tB\'\340A\002\372A!\n\037spanner.googleapis.com/Insta" + + "nce\022\030\n\013database_id\030\002 \001(\tB\003\340A\002\0224\n\006backup\030" + + "\003 \001(\tB\"\372A\037\n\035spanner.googleapis.com/Backu" + + "pH\000\022a\n\021encryption_config\030\004 \001(\0132A.google." + + "spanner.admin.database.v1.RestoreDatabas" + + "eEncryptionConfigB\003\340A\001B\010\n\006source\"\363\002\n\037Res" + + "toreDatabaseEncryptionConfig\022n\n\017encrypti" + + "on_type\030\001 \001(\0162P.google.spanner.admin.dat" + + "abase.v1.RestoreDatabaseEncryptionConfig" + + ".EncryptionTypeB\003\340A\002\022?\n\014kms_key_name\030\002 \001" + + "(\tB)\340A\001\372A#\n!cloudkms.googleapis.com/Cryp" + + "toKey\"\236\001\n\016EncryptionType\022\037\n\033ENCRYPTION_T" + + "YPE_UNSPECIFIED\020\000\022+\n\'USE_CONFIG_DEFAULT_" + + "OR_BACKUP_ENCRYPTION\020\001\022\035\n\031GOOGLE_DEFAULT" + + "_ENCRYPTION\020\002\022\037\n\033CUSTOMER_MANAGED_ENCRYP" + + "TION\020\003\"\215\003\n\027RestoreDatabaseMetadata\0222\n\004na" + + "me\030\001 \001(\tB$\372A!\n\037spanner.googleapis.com/Da" + + "tabase\022H\n\013source_type\030\002 \001(\01623.google.spa" + + "nner.admin.database.v1.RestoreSourceType" + + "\022C\n\013backup_info\030\003 \001(\0132,.google.spanner.a" + + "dmin.database.v1.BackupInfoH\000\022E\n\010progres" + + "s\030\004 \001(\01323.google.spanner.admin.database." + + "v1.OperationProgress\022/\n\013cancel_time\030\005 \001(" + + "\0132\032.google.protobuf.Timestamp\022(\n optimiz" + + "e_database_operation_name\030\006 \001(\tB\r\n\013sourc" + + "e_info\"\235\001\n OptimizeRestoredDatabaseMetad" + + "ata\0222\n\004name\030\001 \001(\tB$\372A!\n\037spanner.googleap" + + "is.com/Database\022E\n\010progress\030\002 \001(\01323.goog" + + "le.spanner.admin.database.v1.OperationPr" + + "ogress\"\236\001\n\014DatabaseRole\022\021\n\004name\030\001 \001(\tB\003\340" + + "A\002:{\352Ax\n#spanner.googleapis.com/Database" + + "Role\022Qprojects/{project}/instances/{inst" + + "ance}/databases/{database}/databaseRoles" + + "/{role}\"z\n\030ListDatabaseRolesRequest\0227\n\006p" + + "arent\030\001 \001(\tB\'\340A\002\372A!\n\037spanner.googleapis." + + "com/Database\022\021\n\tpage_size\030\002 \001(\005\022\022\n\npage_" + + "token\030\003 \001(\t\"|\n\031ListDatabaseRolesResponse" + + "\022F\n\016database_roles\030\001 \003(\0132..google.spanne" + + "r.admin.database.v1.DatabaseRole\022\027\n\017next" + + "_page_token\030\002 \001(\t*5\n\021RestoreSourceType\022\024" + + "\n\020TYPE_UNSPECIFIED\020\000\022\n\n\006BACKUP\020\0012\374#\n\rDat" + + "abaseAdmin\022\300\001\n\rListDatabases\0226.google.sp" + + "anner.admin.database.v1.ListDatabasesReq" + + "uest\0327.google.spanner.admin.database.v1." + + "ListDatabasesResponse\">\202\323\344\223\002/\022-/v1/{pare" + + "nt=projects/*/instances/*}/databases\332A\006p" + + "arent\022\244\002\n\016CreateDatabase\0227.google.spanne" + + "r.admin.database.v1.CreateDatabaseReques" + + "t\032\035.google.longrunning.Operation\"\271\001\202\323\344\223\002" + + "2\"-/v1/{parent=projects/*/instances/*}/d" + + "atabases:\001*\332A\027parent,create_statement\312Ad" + + "\n)google.spanner.admin.database.v1.Datab" + + "ase\0227google.spanner.admin.database.v1.Cr" + + "eateDatabaseMetadata\022\255\001\n\013GetDatabase\0224.g" + + "oogle.spanner.admin.database.v1.GetDatab" + + "aseRequest\032*.google.spanner.admin.databa" + + "se.v1.Database\"<\202\323\344\223\002/\022-/v1/{name=projec" + + "ts/*/instances/*/databases/*}\332A\004name\022\235\002\n" + + "\021UpdateDatabaseDdl\022:.google.spanner.admi" + + "n.database.v1.UpdateDatabaseDdlRequest\032\035" + + ".google.longrunning.Operation\"\254\001\202\323\344\223\002:25" + + "/v1/{database=projects/*/instances/*/dat" + + "abases/*}/ddl:\001*\332A\023database,statements\312A" + + "S\n\025google.protobuf.Empty\022:google.spanner" + + ".admin.database.v1.UpdateDatabaseDdlMeta" + + "data\022\243\001\n\014DropDatabase\0225.google.spanner.a" + + "dmin.database.v1.DropDatabaseRequest\032\026.g" + + "oogle.protobuf.Empty\"D\202\323\344\223\0023*1/v1/{datab" + + "ase=projects/*/instances/*/databases/*}\332" + + "A\010database\022\315\001\n\016GetDatabaseDdl\0227.google.s" + + "panner.admin.database.v1.GetDatabaseDdlR" + + "equest\0328.google.spanner.admin.database.v" + + "1.GetDatabaseDdlResponse\"H\202\323\344\223\0027\0225/v1/{d" + + "atabase=projects/*/instances/*/databases" + + "/*}/ddl\332A\010database\022\353\001\n\014SetIamPolicy\022\".go" + + "ogle.iam.v1.SetIamPolicyRequest\032\025.google" + + ".iam.v1.Policy\"\237\001\202\323\344\223\002\206\001\">/v1/{resource=" + + "projects/*/instances/*/databases/*}:setI" + + "amPolicy:\001*ZA\"/v1/{resource=pr" + + "ojects/*/instances/*/databases/*}:getIam" + + "Policy:\001*ZA\".google.spanner.admin.database.v1.ListB" + + "ackupOperationsResponse\"E\202\323\344\223\0026\0224/v1/{pa" + + "rent=projects/*/instances/*}/backupOpera" + + "tions\332A\006parent\022\334\001\n\021ListDatabaseRoles\022:.g" + + "oogle.spanner.admin.database.v1.ListData" + + "baseRolesRequest\032;.google.spanner.admin." + + "database.v1.ListDatabaseRolesResponse\"N\202" + + "\323\344\223\002?\022=/v1/{parent=projects/*/instances/" + + "*/databases/*}/databaseRoles\332A\006parent\032x\312" + + "A\026spanner.googleapis.com\322A\\https://www.g" + + "oogleapis.com/auth/cloud-platform,https:" + + "//www.googleapis.com/auth/spanner.adminB" + + "\332\002\n$com.google.spanner.admin.database.v1" + + "B\031SpannerDatabaseAdminProtoP\001ZHgoogle.go" + + "lang.org/genproto/googleapis/spanner/adm" + + "in/database/v1;database\252\002&Google.Cloud.S" + + "panner.Admin.Database.V1\312\002&Google\\Cloud\\" + + "Spanner\\Admin\\Database\\V1\352\002+Google::Clou" + + "d::Spanner::Admin::Database::V1\352AJ\n\037span" + + "ner.googleapis.com/Instance\022\'projects/{p" + + "roject}/instances/{instance}b\006proto3" }; descriptor = com.google.protobuf.Descriptors.FileDescriptor.internalBuildGeneratedFileFrom( @@ -425,7 +427,12 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_spanner_admin_database_v1_CreateDatabaseRequest_descriptor, new java.lang.String[] { - "Parent", "CreateStatement", "ExtraStatements", "EncryptionConfig", "DatabaseDialect", + "Parent", + "CreateStatement", + "ExtraStatements", + "EncryptionConfig", + "DatabaseDialect", + "ProtoDescriptors", }); internal_static_google_spanner_admin_database_v1_CreateDatabaseMetadata_descriptor = getDescriptor().getMessageTypes().get(5); @@ -449,7 +456,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_spanner_admin_database_v1_UpdateDatabaseDdlRequest_descriptor, new java.lang.String[] { - "Database", "Statements", "OperationId", + "Database", "Statements", "OperationId", "ProtoDescriptors", }); internal_static_google_spanner_admin_database_v1_UpdateDatabaseDdlMetadata_descriptor = getDescriptor().getMessageTypes().get(8); @@ -481,7 +488,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_spanner_admin_database_v1_GetDatabaseDdlResponse_descriptor, new java.lang.String[] { - "Statements", + "Statements", "ProtoDescriptors", }); internal_static_google_spanner_admin_database_v1_ListDatabaseOperationsRequest_descriptor = getDescriptor().getMessageTypes().get(12); diff --git a/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/UpdateDatabaseDdlRequest.java b/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/UpdateDatabaseDdlRequest.java index 3911178f357..b698ca808f4 100644 --- a/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/UpdateDatabaseDdlRequest.java +++ b/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/UpdateDatabaseDdlRequest.java @@ -55,6 +55,7 @@ private UpdateDatabaseDdlRequest() { database_ = ""; statements_ = com.google.protobuf.LazyStringArrayList.EMPTY; operationId_ = ""; + protoDescriptors_ = com.google.protobuf.ByteString.EMPTY; } @java.lang.Override @@ -278,6 +279,43 @@ public com.google.protobuf.ByteString getOperationIdBytes() { } } + public static final int PROTO_DESCRIPTORS_FIELD_NUMBER = 4; + private com.google.protobuf.ByteString protoDescriptors_; + /** + * + * + *
+   * Proto descriptors used by CREATE/ALTER PROTO BUNDLE statements.
+   * Contains a protobuf-serialized
+   * [google.protobuf.FileDescriptorSet](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto).
+   * To generate it, [install](https://grpc.io/docs/protoc-installation/) and
+   * run `protoc` with --include_imports and --descriptor_set_out. For example,
+   * to generate for moon/shot/app.proto, run
+   * """
+   * $protoc  --proto_path=/app_path --proto_path=/lib_path \
+   *          --include_imports \
+   *          --descriptor_set_out=descriptors.data \
+   *          moon/shot/app.proto
+   * """
+   * For more details, see protobuffer [self
+   * description](https://developers.google.com/protocol-buffers/docs/techniques#self-description).
+   * (--
+   * TODO(b/236424835) remove visibility check before launch.
+   * --)
+   * (-- api-linter: core::0134::request-unknown-fields=disabled
+   *     aip.dev/not-precedent: This Update*Request provides an alter action
+   *     rather than the usual entity field updating. --)
+   * 
+ * + * bytes proto_descriptors = 4 [(.google.api.field_behavior) = OPTIONAL]; + * + * @return The protoDescriptors. + */ + @java.lang.Override + public com.google.protobuf.ByteString getProtoDescriptors() { + return protoDescriptors_; + } + private byte memoizedIsInitialized = -1; @java.lang.Override @@ -301,6 +339,9 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(operationId_)) { com.google.protobuf.GeneratedMessageV3.writeString(output, 3, operationId_); } + if (!protoDescriptors_.isEmpty()) { + output.writeBytes(4, protoDescriptors_); + } getUnknownFields().writeTo(output); } @@ -324,6 +365,9 @@ public int getSerializedSize() { if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(operationId_)) { size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, operationId_); } + if (!protoDescriptors_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream.computeBytesSize(4, protoDescriptors_); + } size += getUnknownFields().getSerializedSize(); memoizedSize = size; return size; @@ -343,6 +387,7 @@ public boolean equals(final java.lang.Object obj) { if (!getDatabase().equals(other.getDatabase())) return false; if (!getStatementsList().equals(other.getStatementsList())) return false; if (!getOperationId().equals(other.getOperationId())) return false; + if (!getProtoDescriptors().equals(other.getProtoDescriptors())) return false; if (!getUnknownFields().equals(other.getUnknownFields())) return false; return true; } @@ -362,6 +407,8 @@ public int hashCode() { } hash = (37 * hash) + OPERATION_ID_FIELD_NUMBER; hash = (53 * hash) + getOperationId().hashCode(); + hash = (37 * hash) + PROTO_DESCRIPTORS_FIELD_NUMBER; + hash = (53 * hash) + getProtoDescriptors().hashCode(); hash = (29 * hash) + getUnknownFields().hashCode(); memoizedHashCode = hash; return hash; @@ -521,6 +568,8 @@ public Builder clear() { bitField0_ = (bitField0_ & ~0x00000001); operationId_ = ""; + protoDescriptors_ = com.google.protobuf.ByteString.EMPTY; + return this; } @@ -557,6 +606,7 @@ public com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest buildPartia } result.statements_ = statements_; result.operationId_ = operationId_; + result.protoDescriptors_ = protoDescriptors_; onBuilt(); return result; } @@ -626,6 +676,9 @@ public Builder mergeFrom(com.google.spanner.admin.database.v1.UpdateDatabaseDdlR operationId_ = other.operationId_; onChanged(); } + if (other.getProtoDescriptors() != com.google.protobuf.ByteString.EMPTY) { + setProtoDescriptors(other.getProtoDescriptors()); + } this.mergeUnknownFields(other.getUnknownFields()); onChanged(); return this; @@ -671,6 +724,12 @@ public Builder mergeFrom( break; } // case 26 + case 34: + { + protoDescriptors_ = input.readBytes(); + + break; + } // case 34 default: { if (!super.parseUnknownField(input, extensionRegistry, tag)) { @@ -1160,6 +1219,118 @@ public Builder setOperationIdBytes(com.google.protobuf.ByteString value) { return this; } + private com.google.protobuf.ByteString protoDescriptors_ = com.google.protobuf.ByteString.EMPTY; + /** + * + * + *
+     * Proto descriptors used by CREATE/ALTER PROTO BUNDLE statements.
+     * Contains a protobuf-serialized
+     * [google.protobuf.FileDescriptorSet](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto).
+     * To generate it, [install](https://grpc.io/docs/protoc-installation/) and
+     * run `protoc` with --include_imports and --descriptor_set_out. For example,
+     * to generate for moon/shot/app.proto, run
+     * """
+     * $protoc  --proto_path=/app_path --proto_path=/lib_path \
+     *          --include_imports \
+     *          --descriptor_set_out=descriptors.data \
+     *          moon/shot/app.proto
+     * """
+     * For more details, see protobuffer [self
+     * description](https://developers.google.com/protocol-buffers/docs/techniques#self-description).
+     * (--
+     * TODO(b/236424835) remove visibility check before launch.
+     * --)
+     * (-- api-linter: core::0134::request-unknown-fields=disabled
+     *     aip.dev/not-precedent: This Update*Request provides an alter action
+     *     rather than the usual entity field updating. --)
+     * 
+ * + * bytes proto_descriptors = 4 [(.google.api.field_behavior) = OPTIONAL]; + * + * @return The protoDescriptors. + */ + @java.lang.Override + public com.google.protobuf.ByteString getProtoDescriptors() { + return protoDescriptors_; + } + /** + * + * + *
+     * Proto descriptors used by CREATE/ALTER PROTO BUNDLE statements.
+     * Contains a protobuf-serialized
+     * [google.protobuf.FileDescriptorSet](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto).
+     * To generate it, [install](https://grpc.io/docs/protoc-installation/) and
+     * run `protoc` with --include_imports and --descriptor_set_out. For example,
+     * to generate for moon/shot/app.proto, run
+     * """
+     * $protoc  --proto_path=/app_path --proto_path=/lib_path \
+     *          --include_imports \
+     *          --descriptor_set_out=descriptors.data \
+     *          moon/shot/app.proto
+     * """
+     * For more details, see protobuffer [self
+     * description](https://developers.google.com/protocol-buffers/docs/techniques#self-description).
+     * (--
+     * TODO(b/236424835) remove visibility check before launch.
+     * --)
+     * (-- api-linter: core::0134::request-unknown-fields=disabled
+     *     aip.dev/not-precedent: This Update*Request provides an alter action
+     *     rather than the usual entity field updating. --)
+     * 
+ * + * bytes proto_descriptors = 4 [(.google.api.field_behavior) = OPTIONAL]; + * + * @param value The protoDescriptors to set. + * @return This builder for chaining. + */ + public Builder setProtoDescriptors(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + + protoDescriptors_ = value; + onChanged(); + return this; + } + /** + * + * + *
+     * Proto descriptors used by CREATE/ALTER PROTO BUNDLE statements.
+     * Contains a protobuf-serialized
+     * [google.protobuf.FileDescriptorSet](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto).
+     * To generate it, [install](https://grpc.io/docs/protoc-installation/) and
+     * run `protoc` with --include_imports and --descriptor_set_out. For example,
+     * to generate for moon/shot/app.proto, run
+     * """
+     * $protoc  --proto_path=/app_path --proto_path=/lib_path \
+     *          --include_imports \
+     *          --descriptor_set_out=descriptors.data \
+     *          moon/shot/app.proto
+     * """
+     * For more details, see protobuffer [self
+     * description](https://developers.google.com/protocol-buffers/docs/techniques#self-description).
+     * (--
+     * TODO(b/236424835) remove visibility check before launch.
+     * --)
+     * (-- api-linter: core::0134::request-unknown-fields=disabled
+     *     aip.dev/not-precedent: This Update*Request provides an alter action
+     *     rather than the usual entity field updating. --)
+     * 
+ * + * bytes proto_descriptors = 4 [(.google.api.field_behavior) = OPTIONAL]; + * + * @return This builder for chaining. + */ + public Builder clearProtoDescriptors() { + + protoDescriptors_ = getDefaultInstance().getProtoDescriptors(); + onChanged(); + return this; + } + @java.lang.Override public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { return super.setUnknownFields(unknownFields); diff --git a/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/UpdateDatabaseDdlRequestOrBuilder.java b/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/UpdateDatabaseDdlRequestOrBuilder.java index cad7c3a28a2..ba445dc1a18 100644 --- a/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/UpdateDatabaseDdlRequestOrBuilder.java +++ b/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/UpdateDatabaseDdlRequestOrBuilder.java @@ -159,4 +159,36 @@ public interface UpdateDatabaseDdlRequestOrBuilder * @return The bytes for operationId. */ com.google.protobuf.ByteString getOperationIdBytes(); + + /** + * + * + *
+   * Proto descriptors used by CREATE/ALTER PROTO BUNDLE statements.
+   * Contains a protobuf-serialized
+   * [google.protobuf.FileDescriptorSet](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto).
+   * To generate it, [install](https://grpc.io/docs/protoc-installation/) and
+   * run `protoc` with --include_imports and --descriptor_set_out. For example,
+   * to generate for moon/shot/app.proto, run
+   * """
+   * $protoc  --proto_path=/app_path --proto_path=/lib_path \
+   *          --include_imports \
+   *          --descriptor_set_out=descriptors.data \
+   *          moon/shot/app.proto
+   * """
+   * For more details, see protobuffer [self
+   * description](https://developers.google.com/protocol-buffers/docs/techniques#self-description).
+   * (--
+   * TODO(b/236424835) remove visibility check before launch.
+   * --)
+   * (-- api-linter: core::0134::request-unknown-fields=disabled
+   *     aip.dev/not-precedent: This Update*Request provides an alter action
+   *     rather than the usual entity field updating. --)
+   * 
+ * + * bytes proto_descriptors = 4 [(.google.api.field_behavior) = OPTIONAL]; + * + * @return The protoDescriptors. + */ + com.google.protobuf.ByteString getProtoDescriptors(); } diff --git a/proto-google-cloud-spanner-admin-database-v1/src/main/proto/google/spanner/admin/database/v1/spanner_database_admin.proto b/proto-google-cloud-spanner-admin-database-v1/src/main/proto/google/spanner/admin/database/v1/spanner_database_admin.proto index 91489ae4b45..f27617c4f09 100644 --- a/proto-google-cloud-spanner-admin-database-v1/src/main/proto/google/spanner/admin/database/v1/spanner_database_admin.proto +++ b/proto-google-cloud-spanner-admin-database-v1/src/main/proto/google/spanner/admin/database/v1/spanner_database_admin.proto @@ -514,6 +514,23 @@ message CreateDatabaseRequest { // Optional. The dialect of the Cloud Spanner Database. DatabaseDialect database_dialect = 5 [(google.api.field_behavior) = OPTIONAL]; + + // Proto descriptors used by CREATE/ALTER PROTO BUNDLE statements in + // 'extra_statements' above. + // Contains a protobuf-serialized + // [google.protobuf.FileDescriptorSet](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto). + // To generate it, [install](https://grpc.io/docs/protoc-installation/) and + // run `protoc` with --include_imports and --descriptor_set_out. For example, + // to generate for moon/shot/app.proto, run + // """ + // $protoc --proto_path=/app_path --proto_path=/lib_path \ + // --include_imports \ + // --descriptor_set_out=descriptors.data \ + // moon/shot/app.proto + // """ + // For more details, see protobuffer [self + // description](https://developers.google.com/protocol-buffers/docs/techniques#self-description). + bytes proto_descriptors = 6 [(google.api.field_behavior) = OPTIONAL]; } // Metadata type for the operation returned by @@ -585,6 +602,28 @@ message UpdateDatabaseDdlRequest { // [UpdateDatabaseDdl][google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabaseDdl] returns // `ALREADY_EXISTS`. string operation_id = 3; + + // Proto descriptors used by CREATE/ALTER PROTO BUNDLE statements. + // Contains a protobuf-serialized + // [google.protobuf.FileDescriptorSet](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto). + // To generate it, [install](https://grpc.io/docs/protoc-installation/) and + // run `protoc` with --include_imports and --descriptor_set_out. For example, + // to generate for moon/shot/app.proto, run + // """ + // $protoc --proto_path=/app_path --proto_path=/lib_path \ + // --include_imports \ + // --descriptor_set_out=descriptors.data \ + // moon/shot/app.proto + // """ + // For more details, see protobuffer [self + // description](https://developers.google.com/protocol-buffers/docs/techniques#self-description). + // (-- + // TODO(b/236424835) remove visibility check before launch. + // --) + // (-- api-linter: core::0134::request-unknown-fields=disabled + // aip.dev/not-precedent: This Update*Request provides an alter action + // rather than the usual entity field updating. --) + bytes proto_descriptors = 4 [(google.api.field_behavior) = OPTIONAL]; } // Metadata type for the operation returned by @@ -649,6 +688,13 @@ message GetDatabaseDdlResponse { // A list of formatted DDL statements defining the schema of the database // specified in the request. repeated string statements = 1; + + // Proto descriptors stored in the database. + // Contains a protobuf-serialized + // [google.protobuf.FileDescriptorSet](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto). + // For more details, see protobuffer [self + // description](https://developers.google.com/protocol-buffers/docs/techniques#self-description). + bytes proto_descriptors = 2; } // The request for From 9513753579bef679592cc038f2478d6cdcac29b5 Mon Sep 17 00:00:00 2001 From: Sri Harsha CH Date: Thu, 8 Jun 2023 18:03:11 +0000 Subject: [PATCH 06/27] teat: update pom file to run tests on cloud-devel region temporarily to validate main branch update --- google-cloud-spanner/pom.xml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/google-cloud-spanner/pom.xml b/google-cloud-spanner/pom.xml index 8ca79d2eb58..b6bc5dedcc6 100644 --- a/google-cloud-spanner/pom.xml +++ b/google-cloud-spanner/pom.xml @@ -18,10 +18,11 @@ 0.31.1 22.3.2 com.google.cloud.spanner.GceTestEnvConfig - projects/gcloud-devel/instances/spanner-testing-east1 - gcloud-devel + projects/span-cloud-testing/instances/spanner-testing-east1 + span-cloud-testing projects/gcloud-devel/locations/us-east1/keyRings/cmek-test-key-ring/cryptoKeys/cmek-test-key - + https://staging-wrenchworks.sandbox.googleapis.com + @@ -65,6 +66,7 @@ ${spanner.testenv.instance} ${spanner.gce.config.project_id} ${spanner.testenv.kms_key.name} + ${spanner.gce.config.server_url} @@ -89,6 +91,7 @@ ${spanner.testenv.instance} ${spanner.gce.config.project_id} ${spanner.testenv.kms_key.name} + ${spanner.gce.config.server_url} 3000 From 6701f526da6b18c0afad2c9ea90619ae0fc3c15d Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Thu, 8 Jun 2023 18:08:24 +0000 Subject: [PATCH 07/27] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- README.md | 7 +- .../cloud/spanner/AbstractResultSet.java | 8 +- .../google/cloud/spanner/DatabaseInfo.java | 4 +- .../java/com/google/cloud/spanner/Value.java | 5 +- .../database/v1/CreateDatabaseRequest.java | 106 +-- .../database/v1/GetDatabaseDdlResponse.java | 38 +- .../v1/SpannerDatabaseAdminProto.java | 638 +++++++++--------- .../database/v1/UpdateDatabaseDdlRequest.java | 60 +- .../main/java/com/google/spanner/v1/Type.java | 96 +-- .../java/com/google/spanner/v1/TypeProto.java | 56 +- 10 files changed, 512 insertions(+), 506 deletions(-) diff --git a/README.md b/README.md index 06fe133ba65..2b91d5c989d 100644 --- a/README.md +++ b/README.md @@ -57,13 +57,13 @@ implementation 'com.google.cloud:google-cloud-spanner' If you are using Gradle without BOM, add this to your dependencies: ```Groovy -implementation 'com.google.cloud:google-cloud-spanner:6.42.3' +implementation 'com.google.cloud:google-cloud-spanner:6.43.0' ``` If you are using SBT, add this to your dependencies: ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-spanner" % "6.42.3" +libraryDependencies += "com.google.cloud" % "google-cloud-spanner" % "6.43.0" ``` @@ -263,7 +263,6 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-spanner/tree/ | Create Backup With Encryption Key | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/CreateBackupWithEncryptionKey.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/CreateBackupWithEncryptionKey.java) | | Create Database With Default Leader Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/CreateDatabaseWithDefaultLeaderSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/CreateDatabaseWithDefaultLeaderSample.java) | | Create Database With Encryption Key | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/CreateDatabaseWithEncryptionKey.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/CreateDatabaseWithEncryptionKey.java) | -| Create Database With Proto Descriptor | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/CreateDatabaseWithProtoDescriptor.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/CreateDatabaseWithProtoDescriptor.java) | | Create Database With Version Retention Period Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/CreateDatabaseWithVersionRetentionPeriodSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/CreateDatabaseWithVersionRetentionPeriodSample.java) | | Create Instance Config Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/CreateInstanceConfigSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/CreateInstanceConfigSample.java) | | Create Instance Example | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/CreateInstanceExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/CreateInstanceExample.java) | @@ -416,7 +415,7 @@ Java is a registered trademark of Oracle and/or its affiliates. [kokoro-badge-link-5]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-spanner/java11.html [stability-image]: https://img.shields.io/badge/stability-stable-green [maven-version-image]: https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-spanner.svg -[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-spanner/6.42.3 +[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-spanner/6.43.0 [authentication]: https://github.com/googleapis/google-cloud-java#authentication [auth-scopes]: https://developers.google.com/identity/protocols/oauth2/scopes [predefined-iam-roles]: https://cloud.google.com/iam/docs/understanding-roles#predefined_roles diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AbstractResultSet.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AbstractResultSet.java index ab5075e528c..dea370005e6 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AbstractResultSet.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AbstractResultSet.java @@ -41,8 +41,8 @@ import com.google.protobuf.ByteString; import com.google.protobuf.InvalidProtocolBufferException; import com.google.protobuf.ListValue; -import com.google.protobuf.ProtocolMessageEnum; import com.google.protobuf.NullValue; +import com.google.protobuf.ProtocolMessageEnum; import com.google.protobuf.Value.KindCase; import com.google.spanner.v1.PartialResultSet; import com.google.spanner.v1.ResultSetMetadata; @@ -955,7 +955,11 @@ protected List getProtoMessageListInternal( protoMessagesList.add(null); } else { protoMessagesList.add( - (T) message.toBuilder().mergeFrom(protoMessageBytes.getByteArray().toByteArray()).build()); + (T) + message + .toBuilder() + .mergeFrom(protoMessageBytes.getByteArray().toByteArray()) + .build()); } } return protoMessagesList; diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseInfo.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseInfo.java index 058edbad248..3f1a0f81eb0 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseInfo.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseInfo.java @@ -21,10 +21,10 @@ import com.google.cloud.spanner.encryption.CustomerManagedEncryption; import com.google.common.base.Preconditions; import com.google.protobuf.ByteString; -import java.io.IOException; -import java.io.InputStream; import com.google.protobuf.FieldMask; import com.google.spanner.admin.database.v1.Database.State; +import java.io.IOException; +import java.io.InputStream; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Value.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Value.java index 6de5b75f255..e4379705296 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Value.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Value.java @@ -2289,7 +2289,10 @@ public List getProtoMessageArray(T m) { protoMessagesList.add(null); } else { protoMessagesList.add( - (T) m.toBuilder().mergeFrom(protoMessageBytes.getByteArray().toByteArray()).build()); + (T) + m.toBuilder() + .mergeFrom(protoMessageBytes.getByteArray().toByteArray()) + .build()); } } return protoMessagesList; diff --git a/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/CreateDatabaseRequest.java b/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/CreateDatabaseRequest.java index 217a62e9b2f..2b5c5dd4297 100644 --- a/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/CreateDatabaseRequest.java +++ b/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/CreateDatabaseRequest.java @@ -58,7 +58,7 @@ public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { @java.lang.Override protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { + internalGetFieldAccessorTable() { return com.google.spanner.admin.database.v1.SpannerDatabaseAdminProto .internal_static_google_spanner_admin_database_v1_CreateDatabaseRequest_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -315,7 +315,7 @@ public com.google.spanner.admin.database.v1.EncryptionConfig getEncryptionConfig */ @java.lang.Override public com.google.spanner.admin.database.v1.EncryptionConfigOrBuilder - getEncryptionConfigOrBuilder() { + getEncryptionConfigOrBuilder() { return encryptionConfig_ == null ? com.google.spanner.admin.database.v1.EncryptionConfig.getDefaultInstance() : encryptionConfig_; @@ -422,7 +422,7 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io } if (databaseDialect_ != com.google.spanner.admin.database.v1.DatabaseDialect.DATABASE_DIALECT_UNSPECIFIED - .getNumber()) { + .getNumber()) { output.writeEnum(5, databaseDialect_); } if (!protoDescriptors_.isEmpty()) { @@ -456,7 +456,7 @@ public int getSerializedSize() { } if (databaseDialect_ != com.google.spanner.admin.database.v1.DatabaseDialect.DATABASE_DIALECT_UNSPECIFIED - .getNumber()) { + .getNumber()) { size += com.google.protobuf.CodedOutputStream.computeEnumSize(5, databaseDialect_); } if (!protoDescriptors_.isEmpty()) { @@ -635,7 +635,7 @@ public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { @java.lang.Override protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { + internalGetFieldAccessorTable() { return com.google.spanner.admin.database.v1.SpannerDatabaseAdminProto .internal_static_google_spanner_admin_database_v1_CreateDatabaseRequest_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -791,50 +791,50 @@ public Builder mergeFrom( done = true; break; case 10: - { - parent_ = input.readStringRequireUtf8(); - bitField0_ |= 0x00000001; - break; - } // case 10 + { + parent_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000001; + break; + } // case 10 case 18: - { - createStatement_ = input.readStringRequireUtf8(); - bitField0_ |= 0x00000002; - break; - } // case 18 + { + createStatement_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000002; + break; + } // case 18 case 26: - { - java.lang.String s = input.readStringRequireUtf8(); - ensureExtraStatementsIsMutable(); - extraStatements_.add(s); - break; - } // case 26 + { + java.lang.String s = input.readStringRequireUtf8(); + ensureExtraStatementsIsMutable(); + extraStatements_.add(s); + break; + } // case 26 case 34: - { - input.readMessage( - getEncryptionConfigFieldBuilder().getBuilder(), extensionRegistry); - bitField0_ |= 0x00000008; - break; - } // case 34 + { + input.readMessage( + getEncryptionConfigFieldBuilder().getBuilder(), extensionRegistry); + bitField0_ |= 0x00000008; + break; + } // case 34 case 40: - { - databaseDialect_ = input.readEnum(); - bitField0_ |= 0x00000010; - break; - } // case 40 + { + databaseDialect_ = input.readEnum(); + bitField0_ |= 0x00000010; + break; + } // case 40 case 50: - { - protoDescriptors_ = input.readBytes(); - bitField0_ |= 0x00000020; - break; - } // case 50 + { + protoDescriptors_ = input.readBytes(); + bitField0_ |= 0x00000020; + break; + } // case 50 default: - { - if (!super.parseUnknownField(input, extensionRegistry, tag)) { - done = true; // was an endgroup tag - } - break; - } // default: + { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: } // switch (tag) } // while (!done) } catch (com.google.protobuf.InvalidProtocolBufferException e) { @@ -1297,9 +1297,9 @@ public Builder addExtraStatementsBytes(com.google.protobuf.ByteString value) { private com.google.spanner.admin.database.v1.EncryptionConfig encryptionConfig_; private com.google.protobuf.SingleFieldBuilderV3< - com.google.spanner.admin.database.v1.EncryptionConfig, - com.google.spanner.admin.database.v1.EncryptionConfig.Builder, - com.google.spanner.admin.database.v1.EncryptionConfigOrBuilder> + com.google.spanner.admin.database.v1.EncryptionConfig, + com.google.spanner.admin.database.v1.EncryptionConfig.Builder, + com.google.spanner.admin.database.v1.EncryptionConfigOrBuilder> encryptionConfigBuilder_; /** * @@ -1413,7 +1413,7 @@ public Builder mergeEncryptionConfig( if (((bitField0_ & 0x00000008) != 0) && encryptionConfig_ != null && encryptionConfig_ - != com.google.spanner.admin.database.v1.EncryptionConfig.getDefaultInstance()) { + != com.google.spanner.admin.database.v1.EncryptionConfig.getDefaultInstance()) { getEncryptionConfigBuilder().mergeFrom(value); } else { encryptionConfig_ = value; @@ -1462,7 +1462,7 @@ public Builder clearEncryptionConfig() { *
*/ public com.google.spanner.admin.database.v1.EncryptionConfig.Builder - getEncryptionConfigBuilder() { + getEncryptionConfigBuilder() { bitField0_ |= 0x00000008; onChanged(); return getEncryptionConfigFieldBuilder().getBuilder(); @@ -1481,7 +1481,7 @@ public Builder clearEncryptionConfig() { *
*/ public com.google.spanner.admin.database.v1.EncryptionConfigOrBuilder - getEncryptionConfigOrBuilder() { + getEncryptionConfigOrBuilder() { if (encryptionConfigBuilder_ != null) { return encryptionConfigBuilder_.getMessageOrBuilder(); } else { @@ -1504,10 +1504,10 @@ public Builder clearEncryptionConfig() { * */ private com.google.protobuf.SingleFieldBuilderV3< - com.google.spanner.admin.database.v1.EncryptionConfig, - com.google.spanner.admin.database.v1.EncryptionConfig.Builder, - com.google.spanner.admin.database.v1.EncryptionConfigOrBuilder> - getEncryptionConfigFieldBuilder() { + com.google.spanner.admin.database.v1.EncryptionConfig, + com.google.spanner.admin.database.v1.EncryptionConfig.Builder, + com.google.spanner.admin.database.v1.EncryptionConfigOrBuilder> + getEncryptionConfigFieldBuilder() { if (encryptionConfigBuilder_ == null) { encryptionConfigBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< diff --git a/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/GetDatabaseDdlResponse.java b/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/GetDatabaseDdlResponse.java index e2509afa94e..9a1907fddaf 100644 --- a/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/GetDatabaseDdlResponse.java +++ b/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/GetDatabaseDdlResponse.java @@ -55,7 +55,7 @@ public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { @java.lang.Override protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { + internalGetFieldAccessorTable() { return com.google.spanner.admin.database.v1.SpannerDatabaseAdminProto .internal_static_google_spanner_admin_database_v1_GetDatabaseDdlResponse_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -349,7 +349,7 @@ public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { @java.lang.Override protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { + internalGetFieldAccessorTable() { return com.google.spanner.admin.database.v1.SpannerDatabaseAdminProto .internal_static_google_spanner_admin_database_v1_GetDatabaseDdlResponse_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -468,25 +468,25 @@ public Builder mergeFrom( done = true; break; case 10: - { - java.lang.String s = input.readStringRequireUtf8(); - ensureStatementsIsMutable(); - statements_.add(s); - break; - } // case 10 + { + java.lang.String s = input.readStringRequireUtf8(); + ensureStatementsIsMutable(); + statements_.add(s); + break; + } // case 10 case 18: - { - protoDescriptors_ = input.readBytes(); - bitField0_ |= 0x00000002; - break; - } // case 18 + { + protoDescriptors_ = input.readBytes(); + bitField0_ |= 0x00000002; + break; + } // case 18 default: - { - if (!super.parseUnknownField(input, extensionRegistry, tag)) { - done = true; // was an endgroup tag - } - break; - } // default: + { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: } // switch (tag) } // while (!done) } catch (com.google.protobuf.InvalidProtocolBufferException e) { diff --git a/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/SpannerDatabaseAdminProto.java b/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/SpannerDatabaseAdminProto.java index 396ca7d0a5d..e989cd82f00 100644 --- a/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/SpannerDatabaseAdminProto.java +++ b/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/SpannerDatabaseAdminProto.java @@ -128,285 +128,285 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { static { java.lang.String[] descriptorData = { - "\n=google/spanner/admin/database/v1/spann" - + "er_database_admin.proto\022 google.spanner." - + "admin.database.v1\032\034google/api/annotation" - + "s.proto\032\027google/api/client.proto\032\037google" - + "/api/field_behavior.proto\032\031google/api/re" - + "source.proto\032\036google/iam/v1/iam_policy.p" - + "roto\032\032google/iam/v1/policy.proto\032#google" - + "/longrunning/operations.proto\032\033google/pr" - + "otobuf/empty.proto\032 google/protobuf/fiel" - + "d_mask.proto\032\037google/protobuf/timestamp." - + "proto\032-google/spanner/admin/database/v1/" - + "backup.proto\032-google/spanner/admin/datab" - + "ase/v1/common.proto\"\253\001\n\013RestoreInfo\022H\n\013s" - + "ource_type\030\001 \001(\01623.google.spanner.admin." - + "database.v1.RestoreSourceType\022C\n\013backup_" - + "info\030\002 \001(\0132,.google.spanner.admin.databa" - + "se.v1.BackupInfoH\000B\r\n\013source_info\"\325\006\n\010Da" - + "tabase\022\022\n\004name\030\001 \001(\tB\004\342A\001\002\022E\n\005state\030\002 \001(" - + "\01620.google.spanner.admin.database.v1.Dat" - + "abase.StateB\004\342A\001\003\0225\n\013create_time\030\003 \001(\0132\032" - + ".google.protobuf.TimestampB\004\342A\001\003\022I\n\014rest" - + "ore_info\030\004 \001(\0132-.google.spanner.admin.da" - + "tabase.v1.RestoreInfoB\004\342A\001\003\022S\n\021encryptio" - + "n_config\030\005 \001(\01322.google.spanner.admin.da" - + "tabase.v1.EncryptionConfigB\004\342A\001\003\022O\n\017encr" - + "yption_info\030\010 \003(\01320.google.spanner.admin" - + ".database.v1.EncryptionInfoB\004\342A\001\003\022&\n\030ver" - + "sion_retention_period\030\006 \001(\tB\004\342A\001\003\022?\n\025ear" - + "liest_version_time\030\007 \001(\0132\032.google.protob" - + "uf.TimestampB\004\342A\001\003\022\034\n\016default_leader\030\t \001" - + "(\tB\004\342A\001\003\022Q\n\020database_dialect\030\n \001(\01621.goo" - + "gle.spanner.admin.database.v1.DatabaseDi" - + "alectB\004\342A\001\003\022\036\n\026enable_drop_protection\030\013 " - + "\001(\010\022\031\n\013reconciling\030\014 \001(\010B\004\342A\001\003\"M\n\005State\022" - + "\025\n\021STATE_UNSPECIFIED\020\000\022\014\n\010CREATING\020\001\022\t\n\005" - + "READY\020\002\022\024\n\020READY_OPTIMIZING\020\003:b\352A_\n\037span" - + "ner.googleapis.com/Database\022\332A" - + "\006parent\202\323\344\223\002/\022-/v1/{parent=projects/*/in" - + "stances/*}/databases\022\244\002\n\016CreateDatabase\022" - + "7.google.spanner.admin.database.v1.Creat" - + "eDatabaseRequest\032\035.google.longrunning.Op" - + "eration\"\271\001\312Ad\n)google.spanner.admin.data" - + "base.v1.Database\0227google.spanner.admin.d" - + "atabase.v1.CreateDatabaseMetadata\332A\027pare" - + "nt,create_statement\202\323\344\223\0022\"-/v1/{parent=p" - + "rojects/*/instances/*}/databases:\001*\022\255\001\n\013" - + "GetDatabase\0224.google.spanner.admin.datab" - + "ase.v1.GetDatabaseRequest\032*.google.spann" - + "er.admin.database.v1.Database\"<\332A\004name\202\323" - + "\344\223\002/\022-/v1/{name=projects/*/instances/*/d" - + "atabases/*}\022\357\001\n\016UpdateDatabase\0227.google." - + "spanner.admin.database.v1.UpdateDatabase" - + "Request\032\035.google.longrunning.Operation\"\204" - + "\001\312A\"\n\010Database\022\026UpdateDatabaseMetadata\332A" - + "\024database,update_mask\202\323\344\223\002B26/v1/{databa" - + "se.name=projects/*/instances/*/databases" - + "/*}:\010database\022\235\002\n\021UpdateDatabaseDdl\022:.go" - + "ogle.spanner.admin.database.v1.UpdateDat" - + "abaseDdlRequest\032\035.google.longrunning.Ope" - + "ration\"\254\001\312AS\n\025google.protobuf.Empty\022:goo" - + "gle.spanner.admin.database.v1.UpdateData" - + "baseDdlMetadata\332A\023database,statements\202\323\344" - + "\223\002:25/v1/{database=projects/*/instances/" - + "*/databases/*}/ddl:\001*\022\243\001\n\014DropDatabase\0225" - + ".google.spanner.admin.database.v1.DropDa" - + "tabaseRequest\032\026.google.protobuf.Empty\"D\332" - + "A\010database\202\323\344\223\0023*1/v1/{database=projects" - + "/*/instances/*/databases/*}\022\315\001\n\016GetDatab" - + "aseDdl\0227.google.spanner.admin.database.v" - + "1.GetDatabaseDdlRequest\0328.google.spanner" - + ".admin.database.v1.GetDatabaseDdlRespons" - + "e\"H\332A\010database\202\323\344\223\0027\0225/v1/{database=proj" - + "ects/*/instances/*/databases/*}/ddl\022\353\001\n\014" - + "SetIamPolicy\022\".google.iam.v1.SetIamPolic" - + "yRequest\032\025.google.iam.v1.Policy\"\237\001\332A\017res" - + "ource,policy\202\323\344\223\002\206\001\">/v1/{resource=proje" - + "cts/*/instances/*/databases/*}:setIamPol" - + "icy:\001*ZA\"/v1/{resource=projects/*/ins" - + "tances/*/databases/*}:getIamPolicy:\001*ZA\"" - + ".google.spanner.admin." - + "database.v1.ListBackupOperationsResponse" - + "\"E\332A\006parent\202\323\344\223\0026\0224/v1/{parent=projects/" - + "*/instances/*}/backupOperations\022\334\001\n\021List" - + "DatabaseRoles\022:.google.spanner.admin.dat" - + "abase.v1.ListDatabaseRolesRequest\032;.goog" - + "le.spanner.admin.database.v1.ListDatabas" - + "eRolesResponse\"N\332A\006parent\202\323\344\223\002?\022=/v1/{pa" - + "rent=projects/*/instances/*/databases/*}" - + "/databaseRoles\032x\312A\026spanner.googleapis.co" - + "m\322A\\https://www.googleapis.com/auth/clou" - + "d-platform,https://www.googleapis.com/au" - + "th/spanner.adminB\330\002\n$com.google.spanner." - + "admin.database.v1B\031SpannerDatabaseAdminP" - + "rotoP\001ZFcloud.google.com/go/spanner/admi" - + "n/database/apiv1/databasepb;databasepb\252\002" - + "&Google.Cloud.Spanner.Admin.Database.V1\312" - + "\002&Google\\Cloud\\Spanner\\Admin\\Database\\V1" - + "\352\002+Google::Cloud::Spanner::Admin::Databa" - + "se::V1\352AJ\n\037spanner.googleapis.com/Instan" - + "ce\022\'projects/{project}/instances/{instan" - + "ce}b\006proto3" + "\n=google/spanner/admin/database/v1/spann" + + "er_database_admin.proto\022 google.spanner." + + "admin.database.v1\032\034google/api/annotation" + + "s.proto\032\027google/api/client.proto\032\037google" + + "/api/field_behavior.proto\032\031google/api/re" + + "source.proto\032\036google/iam/v1/iam_policy.p" + + "roto\032\032google/iam/v1/policy.proto\032#google" + + "/longrunning/operations.proto\032\033google/pr" + + "otobuf/empty.proto\032 google/protobuf/fiel" + + "d_mask.proto\032\037google/protobuf/timestamp." + + "proto\032-google/spanner/admin/database/v1/" + + "backup.proto\032-google/spanner/admin/datab" + + "ase/v1/common.proto\"\253\001\n\013RestoreInfo\022H\n\013s" + + "ource_type\030\001 \001(\01623.google.spanner.admin." + + "database.v1.RestoreSourceType\022C\n\013backup_" + + "info\030\002 \001(\0132,.google.spanner.admin.databa" + + "se.v1.BackupInfoH\000B\r\n\013source_info\"\325\006\n\010Da" + + "tabase\022\022\n\004name\030\001 \001(\tB\004\342A\001\002\022E\n\005state\030\002 \001(" + + "\01620.google.spanner.admin.database.v1.Dat" + + "abase.StateB\004\342A\001\003\0225\n\013create_time\030\003 \001(\0132\032" + + ".google.protobuf.TimestampB\004\342A\001\003\022I\n\014rest" + + "ore_info\030\004 \001(\0132-.google.spanner.admin.da" + + "tabase.v1.RestoreInfoB\004\342A\001\003\022S\n\021encryptio" + + "n_config\030\005 \001(\01322.google.spanner.admin.da" + + "tabase.v1.EncryptionConfigB\004\342A\001\003\022O\n\017encr" + + "yption_info\030\010 \003(\01320.google.spanner.admin" + + ".database.v1.EncryptionInfoB\004\342A\001\003\022&\n\030ver" + + "sion_retention_period\030\006 \001(\tB\004\342A\001\003\022?\n\025ear" + + "liest_version_time\030\007 \001(\0132\032.google.protob" + + "uf.TimestampB\004\342A\001\003\022\034\n\016default_leader\030\t \001" + + "(\tB\004\342A\001\003\022Q\n\020database_dialect\030\n \001(\01621.goo" + + "gle.spanner.admin.database.v1.DatabaseDi" + + "alectB\004\342A\001\003\022\036\n\026enable_drop_protection\030\013 " + + "\001(\010\022\031\n\013reconciling\030\014 \001(\010B\004\342A\001\003\"M\n\005State\022" + + "\025\n\021STATE_UNSPECIFIED\020\000\022\014\n\010CREATING\020\001\022\t\n\005" + + "READY\020\002\022\024\n\020READY_OPTIMIZING\020\003:b\352A_\n\037span" + + "ner.googleapis.com/Database\022\332A" + + "\006parent\202\323\344\223\002/\022-/v1/{parent=projects/*/in" + + "stances/*}/databases\022\244\002\n\016CreateDatabase\022" + + "7.google.spanner.admin.database.v1.Creat" + + "eDatabaseRequest\032\035.google.longrunning.Op" + + "eration\"\271\001\312Ad\n)google.spanner.admin.data" + + "base.v1.Database\0227google.spanner.admin.d" + + "atabase.v1.CreateDatabaseMetadata\332A\027pare" + + "nt,create_statement\202\323\344\223\0022\"-/v1/{parent=p" + + "rojects/*/instances/*}/databases:\001*\022\255\001\n\013" + + "GetDatabase\0224.google.spanner.admin.datab" + + "ase.v1.GetDatabaseRequest\032*.google.spann" + + "er.admin.database.v1.Database\"<\332A\004name\202\323" + + "\344\223\002/\022-/v1/{name=projects/*/instances/*/d" + + "atabases/*}\022\357\001\n\016UpdateDatabase\0227.google." + + "spanner.admin.database.v1.UpdateDatabase" + + "Request\032\035.google.longrunning.Operation\"\204" + + "\001\312A\"\n\010Database\022\026UpdateDatabaseMetadata\332A" + + "\024database,update_mask\202\323\344\223\002B26/v1/{databa" + + "se.name=projects/*/instances/*/databases" + + "/*}:\010database\022\235\002\n\021UpdateDatabaseDdl\022:.go" + + "ogle.spanner.admin.database.v1.UpdateDat" + + "abaseDdlRequest\032\035.google.longrunning.Ope" + + "ration\"\254\001\312AS\n\025google.protobuf.Empty\022:goo" + + "gle.spanner.admin.database.v1.UpdateData" + + "baseDdlMetadata\332A\023database,statements\202\323\344" + + "\223\002:25/v1/{database=projects/*/instances/" + + "*/databases/*}/ddl:\001*\022\243\001\n\014DropDatabase\0225" + + ".google.spanner.admin.database.v1.DropDa" + + "tabaseRequest\032\026.google.protobuf.Empty\"D\332" + + "A\010database\202\323\344\223\0023*1/v1/{database=projects" + + "/*/instances/*/databases/*}\022\315\001\n\016GetDatab" + + "aseDdl\0227.google.spanner.admin.database.v" + + "1.GetDatabaseDdlRequest\0328.google.spanner" + + ".admin.database.v1.GetDatabaseDdlRespons" + + "e\"H\332A\010database\202\323\344\223\0027\0225/v1/{database=proj" + + "ects/*/instances/*/databases/*}/ddl\022\353\001\n\014" + + "SetIamPolicy\022\".google.iam.v1.SetIamPolic" + + "yRequest\032\025.google.iam.v1.Policy\"\237\001\332A\017res" + + "ource,policy\202\323\344\223\002\206\001\">/v1/{resource=proje" + + "cts/*/instances/*/databases/*}:setIamPol" + + "icy:\001*ZA\"/v1/{resource=projects/*/ins" + + "tances/*/databases/*}:getIamPolicy:\001*ZA\"" + + ".google.spanner.admin." + + "database.v1.ListBackupOperationsResponse" + + "\"E\332A\006parent\202\323\344\223\0026\0224/v1/{parent=projects/" + + "*/instances/*}/backupOperations\022\334\001\n\021List" + + "DatabaseRoles\022:.google.spanner.admin.dat" + + "abase.v1.ListDatabaseRolesRequest\032;.goog" + + "le.spanner.admin.database.v1.ListDatabas" + + "eRolesResponse\"N\332A\006parent\202\323\344\223\002?\022=/v1/{pa" + + "rent=projects/*/instances/*/databases/*}" + + "/databaseRoles\032x\312A\026spanner.googleapis.co" + + "m\322A\\https://www.googleapis.com/auth/clou" + + "d-platform,https://www.googleapis.com/au" + + "th/spanner.adminB\330\002\n$com.google.spanner." + + "admin.database.v1B\031SpannerDatabaseAdminP" + + "rotoP\001ZFcloud.google.com/go/spanner/admi" + + "n/database/apiv1/databasepb;databasepb\252\002" + + "&Google.Cloud.Spanner.Admin.Database.V1\312" + + "\002&Google\\Cloud\\Spanner\\Admin\\Database\\V1" + + "\352\002+Google::Cloud::Spanner::Admin::Databa" + + "se::V1\352AJ\n\037spanner.googleapis.com/Instan" + + "ce\022\'projects/{project}/instances/{instan" + + "ce}b\006proto3" }; descriptor = com.google.protobuf.Descriptors.FileDescriptor.internalBuildGeneratedFileFrom( descriptorData, new com.google.protobuf.Descriptors.FileDescriptor[] { - com.google.api.AnnotationsProto.getDescriptor(), - com.google.api.ClientProto.getDescriptor(), - com.google.api.FieldBehaviorProto.getDescriptor(), - com.google.api.ResourceProto.getDescriptor(), - com.google.iam.v1.IamPolicyProto.getDescriptor(), - com.google.iam.v1.PolicyProto.getDescriptor(), - com.google.longrunning.OperationsProto.getDescriptor(), - com.google.protobuf.EmptyProto.getDescriptor(), - com.google.protobuf.FieldMaskProto.getDescriptor(), - com.google.protobuf.TimestampProto.getDescriptor(), - com.google.spanner.admin.database.v1.BackupProto.getDescriptor(), - com.google.spanner.admin.database.v1.CommonProto.getDescriptor(), + com.google.api.AnnotationsProto.getDescriptor(), + com.google.api.ClientProto.getDescriptor(), + com.google.api.FieldBehaviorProto.getDescriptor(), + com.google.api.ResourceProto.getDescriptor(), + com.google.iam.v1.IamPolicyProto.getDescriptor(), + com.google.iam.v1.PolicyProto.getDescriptor(), + com.google.longrunning.OperationsProto.getDescriptor(), + com.google.protobuf.EmptyProto.getDescriptor(), + com.google.protobuf.FieldMaskProto.getDescriptor(), + com.google.protobuf.TimestampProto.getDescriptor(), + com.google.spanner.admin.database.v1.BackupProto.getDescriptor(), + com.google.spanner.admin.database.v1.CommonProto.getDescriptor(), }); internal_static_google_spanner_admin_database_v1_RestoreInfo_descriptor = getDescriptor().getMessageTypes().get(0); @@ -414,7 +414,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_spanner_admin_database_v1_RestoreInfo_descriptor, new java.lang.String[] { - "SourceType", "BackupInfo", "SourceInfo", + "SourceType", "BackupInfo", "SourceInfo", }); internal_static_google_spanner_admin_database_v1_Database_descriptor = getDescriptor().getMessageTypes().get(1); @@ -422,18 +422,18 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_spanner_admin_database_v1_Database_descriptor, new java.lang.String[] { - "Name", - "State", - "CreateTime", - "RestoreInfo", - "EncryptionConfig", - "EncryptionInfo", - "VersionRetentionPeriod", - "EarliestVersionTime", - "DefaultLeader", - "DatabaseDialect", - "EnableDropProtection", - "Reconciling", + "Name", + "State", + "CreateTime", + "RestoreInfo", + "EncryptionConfig", + "EncryptionInfo", + "VersionRetentionPeriod", + "EarliestVersionTime", + "DefaultLeader", + "DatabaseDialect", + "EnableDropProtection", + "Reconciling", }); internal_static_google_spanner_admin_database_v1_ListDatabasesRequest_descriptor = getDescriptor().getMessageTypes().get(2); @@ -441,7 +441,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_spanner_admin_database_v1_ListDatabasesRequest_descriptor, new java.lang.String[] { - "Parent", "PageSize", "PageToken", + "Parent", "PageSize", "PageToken", }); internal_static_google_spanner_admin_database_v1_ListDatabasesResponse_descriptor = getDescriptor().getMessageTypes().get(3); @@ -449,7 +449,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_spanner_admin_database_v1_ListDatabasesResponse_descriptor, new java.lang.String[] { - "Databases", "NextPageToken", + "Databases", "NextPageToken", }); internal_static_google_spanner_admin_database_v1_CreateDatabaseRequest_descriptor = getDescriptor().getMessageTypes().get(4); @@ -457,12 +457,12 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_spanner_admin_database_v1_CreateDatabaseRequest_descriptor, new java.lang.String[] { - "Parent", - "CreateStatement", - "ExtraStatements", - "EncryptionConfig", - "DatabaseDialect", - "ProtoDescriptors", + "Parent", + "CreateStatement", + "ExtraStatements", + "EncryptionConfig", + "DatabaseDialect", + "ProtoDescriptors", }); internal_static_google_spanner_admin_database_v1_CreateDatabaseMetadata_descriptor = getDescriptor().getMessageTypes().get(5); @@ -470,7 +470,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_spanner_admin_database_v1_CreateDatabaseMetadata_descriptor, new java.lang.String[] { - "Database", + "Database", }); internal_static_google_spanner_admin_database_v1_GetDatabaseRequest_descriptor = getDescriptor().getMessageTypes().get(6); @@ -478,7 +478,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_spanner_admin_database_v1_GetDatabaseRequest_descriptor, new java.lang.String[] { - "Name", + "Name", }); internal_static_google_spanner_admin_database_v1_UpdateDatabaseRequest_descriptor = getDescriptor().getMessageTypes().get(7); @@ -486,7 +486,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_spanner_admin_database_v1_UpdateDatabaseRequest_descriptor, new java.lang.String[] { - "Database", "UpdateMask", + "Database", "UpdateMask", }); internal_static_google_spanner_admin_database_v1_UpdateDatabaseMetadata_descriptor = getDescriptor().getMessageTypes().get(8); @@ -494,7 +494,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_spanner_admin_database_v1_UpdateDatabaseMetadata_descriptor, new java.lang.String[] { - "Request", "Progress", "CancelTime", + "Request", "Progress", "CancelTime", }); internal_static_google_spanner_admin_database_v1_UpdateDatabaseDdlRequest_descriptor = getDescriptor().getMessageTypes().get(9); @@ -502,7 +502,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_spanner_admin_database_v1_UpdateDatabaseDdlRequest_descriptor, new java.lang.String[] { - "Database", "Statements", "OperationId", "ProtoDescriptors", + "Database", "Statements", "OperationId", "ProtoDescriptors", }); internal_static_google_spanner_admin_database_v1_UpdateDatabaseDdlMetadata_descriptor = getDescriptor().getMessageTypes().get(10); @@ -510,7 +510,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_spanner_admin_database_v1_UpdateDatabaseDdlMetadata_descriptor, new java.lang.String[] { - "Database", "Statements", "CommitTimestamps", "Throttled", "Progress", + "Database", "Statements", "CommitTimestamps", "Throttled", "Progress", }); internal_static_google_spanner_admin_database_v1_DropDatabaseRequest_descriptor = getDescriptor().getMessageTypes().get(11); @@ -518,7 +518,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_spanner_admin_database_v1_DropDatabaseRequest_descriptor, new java.lang.String[] { - "Database", + "Database", }); internal_static_google_spanner_admin_database_v1_GetDatabaseDdlRequest_descriptor = getDescriptor().getMessageTypes().get(12); @@ -526,7 +526,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_spanner_admin_database_v1_GetDatabaseDdlRequest_descriptor, new java.lang.String[] { - "Database", + "Database", }); internal_static_google_spanner_admin_database_v1_GetDatabaseDdlResponse_descriptor = getDescriptor().getMessageTypes().get(13); @@ -534,7 +534,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_spanner_admin_database_v1_GetDatabaseDdlResponse_descriptor, new java.lang.String[] { - "Statements", "ProtoDescriptors", + "Statements", "ProtoDescriptors", }); internal_static_google_spanner_admin_database_v1_ListDatabaseOperationsRequest_descriptor = getDescriptor().getMessageTypes().get(14); @@ -542,7 +542,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_spanner_admin_database_v1_ListDatabaseOperationsRequest_descriptor, new java.lang.String[] { - "Parent", "Filter", "PageSize", "PageToken", + "Parent", "Filter", "PageSize", "PageToken", }); internal_static_google_spanner_admin_database_v1_ListDatabaseOperationsResponse_descriptor = getDescriptor().getMessageTypes().get(15); @@ -550,7 +550,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_spanner_admin_database_v1_ListDatabaseOperationsResponse_descriptor, new java.lang.String[] { - "Operations", "NextPageToken", + "Operations", "NextPageToken", }); internal_static_google_spanner_admin_database_v1_RestoreDatabaseRequest_descriptor = getDescriptor().getMessageTypes().get(16); @@ -558,7 +558,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_spanner_admin_database_v1_RestoreDatabaseRequest_descriptor, new java.lang.String[] { - "Parent", "DatabaseId", "Backup", "EncryptionConfig", "Source", + "Parent", "DatabaseId", "Backup", "EncryptionConfig", "Source", }); internal_static_google_spanner_admin_database_v1_RestoreDatabaseEncryptionConfig_descriptor = getDescriptor().getMessageTypes().get(17); @@ -566,7 +566,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_spanner_admin_database_v1_RestoreDatabaseEncryptionConfig_descriptor, new java.lang.String[] { - "EncryptionType", "KmsKeyName", + "EncryptionType", "KmsKeyName", }); internal_static_google_spanner_admin_database_v1_RestoreDatabaseMetadata_descriptor = getDescriptor().getMessageTypes().get(18); @@ -574,13 +574,13 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_spanner_admin_database_v1_RestoreDatabaseMetadata_descriptor, new java.lang.String[] { - "Name", - "SourceType", - "BackupInfo", - "Progress", - "CancelTime", - "OptimizeDatabaseOperationName", - "SourceInfo", + "Name", + "SourceType", + "BackupInfo", + "Progress", + "CancelTime", + "OptimizeDatabaseOperationName", + "SourceInfo", }); internal_static_google_spanner_admin_database_v1_OptimizeRestoredDatabaseMetadata_descriptor = getDescriptor().getMessageTypes().get(19); @@ -588,7 +588,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_spanner_admin_database_v1_OptimizeRestoredDatabaseMetadata_descriptor, new java.lang.String[] { - "Name", "Progress", + "Name", "Progress", }); internal_static_google_spanner_admin_database_v1_DatabaseRole_descriptor = getDescriptor().getMessageTypes().get(20); @@ -596,7 +596,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_spanner_admin_database_v1_DatabaseRole_descriptor, new java.lang.String[] { - "Name", + "Name", }); internal_static_google_spanner_admin_database_v1_ListDatabaseRolesRequest_descriptor = getDescriptor().getMessageTypes().get(21); @@ -604,7 +604,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_spanner_admin_database_v1_ListDatabaseRolesRequest_descriptor, new java.lang.String[] { - "Parent", "PageSize", "PageToken", + "Parent", "PageSize", "PageToken", }); internal_static_google_spanner_admin_database_v1_ListDatabaseRolesResponse_descriptor = getDescriptor().getMessageTypes().get(22); @@ -612,7 +612,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_spanner_admin_database_v1_ListDatabaseRolesResponse_descriptor, new java.lang.String[] { - "DatabaseRoles", "NextPageToken", + "DatabaseRoles", "NextPageToken", }); com.google.protobuf.ExtensionRegistry registry = com.google.protobuf.ExtensionRegistry.newInstance(); diff --git a/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/UpdateDatabaseDdlRequest.java b/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/UpdateDatabaseDdlRequest.java index 6815e9376ea..9b97b0c1174 100644 --- a/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/UpdateDatabaseDdlRequest.java +++ b/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/UpdateDatabaseDdlRequest.java @@ -72,7 +72,7 @@ public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { @java.lang.Override protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { + internalGetFieldAccessorTable() { return com.google.spanner.admin.database.v1.SpannerDatabaseAdminProto .internal_static_google_spanner_admin_database_v1_UpdateDatabaseDdlRequest_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -552,7 +552,7 @@ public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { @java.lang.Override protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { + internalGetFieldAccessorTable() { return com.google.spanner.admin.database.v1.SpannerDatabaseAdminProto .internal_static_google_spanner_admin_database_v1_UpdateDatabaseDdlRequest_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -586,7 +586,7 @@ public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { @java.lang.Override public com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest - getDefaultInstanceForType() { + getDefaultInstanceForType() { return com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest.getDefaultInstance(); } @@ -692,37 +692,37 @@ public Builder mergeFrom( done = true; break; case 10: - { - database_ = input.readStringRequireUtf8(); - bitField0_ |= 0x00000001; - break; - } // case 10 + { + database_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000001; + break; + } // case 10 case 18: - { - java.lang.String s = input.readStringRequireUtf8(); - ensureStatementsIsMutable(); - statements_.add(s); - break; - } // case 18 + { + java.lang.String s = input.readStringRequireUtf8(); + ensureStatementsIsMutable(); + statements_.add(s); + break; + } // case 18 case 26: - { - operationId_ = input.readStringRequireUtf8(); - bitField0_ |= 0x00000004; - break; - } // case 26 + { + operationId_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000004; + break; + } // case 26 case 34: - { - protoDescriptors_ = input.readBytes(); - bitField0_ |= 0x00000008; - break; - } // case 34 + { + protoDescriptors_ = input.readBytes(); + bitField0_ |= 0x00000008; + break; + } // case 34 default: - { - if (!super.parseUnknownField(input, extensionRegistry, tag)) { - done = true; // was an endgroup tag - } - break; - } // default: + { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: } // switch (tag) } // while (!done) } catch (com.google.protobuf.InvalidProtocolBufferException e) { diff --git a/proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/Type.java b/proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/Type.java index 7cf247a9c6d..3acefe94de2 100644 --- a/proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/Type.java +++ b/proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/Type.java @@ -56,7 +56,7 @@ public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { @java.lang.Override protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { + internalGetFieldAccessorTable() { return com.google.spanner.v1.TypeProto.internal_static_google_spanner_v1_Type_fieldAccessorTable .ensureFieldAccessorsInitialized( com.google.spanner.v1.Type.class, com.google.spanner.v1.Type.Builder.class); @@ -527,7 +527,7 @@ public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { @java.lang.Override protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { + internalGetFieldAccessorTable() { return com.google.spanner.v1.TypeProto .internal_static_google_spanner_v1_Type_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -666,43 +666,43 @@ public Builder mergeFrom( done = true; break; case 8: - { - code_ = input.readEnum(); - bitField0_ |= 0x00000001; - break; - } // case 8 + { + code_ = input.readEnum(); + bitField0_ |= 0x00000001; + break; + } // case 8 case 18: - { - input.readMessage( - getArrayElementTypeFieldBuilder().getBuilder(), extensionRegistry); - bitField0_ |= 0x00000002; - break; - } // case 18 + { + input.readMessage( + getArrayElementTypeFieldBuilder().getBuilder(), extensionRegistry); + bitField0_ |= 0x00000002; + break; + } // case 18 case 26: - { - input.readMessage(getStructTypeFieldBuilder().getBuilder(), extensionRegistry); - bitField0_ |= 0x00000004; - break; - } // case 26 + { + input.readMessage(getStructTypeFieldBuilder().getBuilder(), extensionRegistry); + bitField0_ |= 0x00000004; + break; + } // case 26 case 32: - { - typeAnnotation_ = input.readEnum(); - bitField0_ |= 0x00000008; - break; - } // case 32 + { + typeAnnotation_ = input.readEnum(); + bitField0_ |= 0x00000008; + break; + } // case 32 case 42: - { - protoTypeFqn_ = input.readStringRequireUtf8(); - bitField0_ |= 0x00000010; - break; - } // case 42 + { + protoTypeFqn_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000010; + break; + } // case 42 default: - { - if (!super.parseUnknownField(input, extensionRegistry, tag)) { - done = true; // was an endgroup tag - } - break; - } // default: + { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: } // switch (tag) } // while (!done) } catch (com.google.protobuf.InvalidProtocolBufferException e) { @@ -806,9 +806,9 @@ public Builder clearCode() { private com.google.spanner.v1.Type arrayElementType_; private com.google.protobuf.SingleFieldBuilderV3< - com.google.spanner.v1.Type, - com.google.spanner.v1.Type.Builder, - com.google.spanner.v1.TypeOrBuilder> + com.google.spanner.v1.Type, + com.google.spanner.v1.Type.Builder, + com.google.spanner.v1.TypeOrBuilder> arrayElementTypeBuilder_; /** * @@ -980,10 +980,10 @@ public com.google.spanner.v1.TypeOrBuilder getArrayElementTypeOrBuilder() { * .google.spanner.v1.Type array_element_type = 2; */ private com.google.protobuf.SingleFieldBuilderV3< - com.google.spanner.v1.Type, - com.google.spanner.v1.Type.Builder, - com.google.spanner.v1.TypeOrBuilder> - getArrayElementTypeFieldBuilder() { + com.google.spanner.v1.Type, + com.google.spanner.v1.Type.Builder, + com.google.spanner.v1.TypeOrBuilder> + getArrayElementTypeFieldBuilder() { if (arrayElementTypeBuilder_ == null) { arrayElementTypeBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< @@ -998,9 +998,9 @@ public com.google.spanner.v1.TypeOrBuilder getArrayElementTypeOrBuilder() { private com.google.spanner.v1.StructType structType_; private com.google.protobuf.SingleFieldBuilderV3< - com.google.spanner.v1.StructType, - com.google.spanner.v1.StructType.Builder, - com.google.spanner.v1.StructTypeOrBuilder> + com.google.spanner.v1.StructType, + com.google.spanner.v1.StructType.Builder, + com.google.spanner.v1.StructTypeOrBuilder> structTypeBuilder_; /** * @@ -1172,10 +1172,10 @@ public com.google.spanner.v1.StructTypeOrBuilder getStructTypeOrBuilder() { * .google.spanner.v1.StructType struct_type = 3; */ private com.google.protobuf.SingleFieldBuilderV3< - com.google.spanner.v1.StructType, - com.google.spanner.v1.StructType.Builder, - com.google.spanner.v1.StructTypeOrBuilder> - getStructTypeFieldBuilder() { + com.google.spanner.v1.StructType, + com.google.spanner.v1.StructType.Builder, + com.google.spanner.v1.StructTypeOrBuilder> + getStructTypeFieldBuilder() { if (structTypeBuilder_ == null) { structTypeBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< diff --git a/proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/TypeProto.java b/proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/TypeProto.java index 7fe78fbe45a..50884f3aa93 100644 --- a/proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/TypeProto.java +++ b/proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/TypeProto.java @@ -48,43 +48,43 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { static { java.lang.String[] descriptorData = { - "\n\034google/spanner/v1/type.proto\022\021google.s" - + "panner.v1\032\037google/api/field_behavior.pro" - + "to\"\370\001\n\004Type\022/\n\004code\030\001 \001(\0162\033.google.spann" - + "er.v1.TypeCodeB\004\342A\001\002\0223\n\022array_element_ty" - + "pe\030\002 \001(\0132\027.google.spanner.v1.Type\0222\n\013str" - + "uct_type\030\003 \001(\0132\035.google.spanner.v1.Struc" - + "tType\022>\n\017type_annotation\030\004 \001(\0162%.google." - + "spanner.v1.TypeAnnotationCode\022\026\n\016proto_t" - + "ype_fqn\030\005 \001(\t\"\177\n\nStructType\0223\n\006fields\030\001 " - + "\003(\0132#.google.spanner.v1.StructType.Field" - + "\032<\n\005Field\022\014\n\004name\030\001 \001(\t\022%\n\004type\030\002 \001(\0132\027." - + "google.spanner.v1.Type*\272\001\n\010TypeCode\022\031\n\025T" - + "YPE_CODE_UNSPECIFIED\020\000\022\010\n\004BOOL\020\001\022\t\n\005INT6" - + "4\020\002\022\013\n\007FLOAT64\020\003\022\r\n\tTIMESTAMP\020\004\022\010\n\004DATE\020" - + "\005\022\n\n\006STRING\020\006\022\t\n\005BYTES\020\007\022\t\n\005ARRAY\020\010\022\n\n\006S" - + "TRUCT\020\t\022\013\n\007NUMERIC\020\n\022\010\n\004JSON\020\013\022\t\n\005PROTO\020" - + "\r\022\010\n\004ENUM\020\016*X\n\022TypeAnnotationCode\022$\n TYP" - + "E_ANNOTATION_CODE_UNSPECIFIED\020\000\022\016\n\nPG_NU" - + "MERIC\020\002\022\014\n\010PG_JSONB\020\003B\254\001\n\025com.google.spa" - + "nner.v1B\tTypeProtoP\001Z5cloud.google.com/g" - + "o/spanner/apiv1/spannerpb;spannerpb\252\002\027Go" - + "ogle.Cloud.Spanner.V1\312\002\027Google\\Cloud\\Spa" - + "nner\\V1\352\002\032Google::Cloud::Spanner::V1b\006pr" - + "oto3" + "\n\034google/spanner/v1/type.proto\022\021google.s" + + "panner.v1\032\037google/api/field_behavior.pro" + + "to\"\370\001\n\004Type\022/\n\004code\030\001 \001(\0162\033.google.spann" + + "er.v1.TypeCodeB\004\342A\001\002\0223\n\022array_element_ty" + + "pe\030\002 \001(\0132\027.google.spanner.v1.Type\0222\n\013str" + + "uct_type\030\003 \001(\0132\035.google.spanner.v1.Struc" + + "tType\022>\n\017type_annotation\030\004 \001(\0162%.google." + + "spanner.v1.TypeAnnotationCode\022\026\n\016proto_t" + + "ype_fqn\030\005 \001(\t\"\177\n\nStructType\0223\n\006fields\030\001 " + + "\003(\0132#.google.spanner.v1.StructType.Field" + + "\032<\n\005Field\022\014\n\004name\030\001 \001(\t\022%\n\004type\030\002 \001(\0132\027." + + "google.spanner.v1.Type*\272\001\n\010TypeCode\022\031\n\025T" + + "YPE_CODE_UNSPECIFIED\020\000\022\010\n\004BOOL\020\001\022\t\n\005INT6" + + "4\020\002\022\013\n\007FLOAT64\020\003\022\r\n\tTIMESTAMP\020\004\022\010\n\004DATE\020" + + "\005\022\n\n\006STRING\020\006\022\t\n\005BYTES\020\007\022\t\n\005ARRAY\020\010\022\n\n\006S" + + "TRUCT\020\t\022\013\n\007NUMERIC\020\n\022\010\n\004JSON\020\013\022\t\n\005PROTO\020" + + "\r\022\010\n\004ENUM\020\016*X\n\022TypeAnnotationCode\022$\n TYP" + + "E_ANNOTATION_CODE_UNSPECIFIED\020\000\022\016\n\nPG_NU" + + "MERIC\020\002\022\014\n\010PG_JSONB\020\003B\254\001\n\025com.google.spa" + + "nner.v1B\tTypeProtoP\001Z5cloud.google.com/g" + + "o/spanner/apiv1/spannerpb;spannerpb\252\002\027Go" + + "ogle.Cloud.Spanner.V1\312\002\027Google\\Cloud\\Spa" + + "nner\\V1\352\002\032Google::Cloud::Spanner::V1b\006pr" + + "oto3" }; descriptor = com.google.protobuf.Descriptors.FileDescriptor.internalBuildGeneratedFileFrom( descriptorData, new com.google.protobuf.Descriptors.FileDescriptor[] { - com.google.api.FieldBehaviorProto.getDescriptor(), + com.google.api.FieldBehaviorProto.getDescriptor(), }); internal_static_google_spanner_v1_Type_descriptor = getDescriptor().getMessageTypes().get(0); internal_static_google_spanner_v1_Type_fieldAccessorTable = new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_spanner_v1_Type_descriptor, new java.lang.String[] { - "Code", "ArrayElementType", "StructType", "TypeAnnotation", "ProtoTypeFqn", + "Code", "ArrayElementType", "StructType", "TypeAnnotation", "ProtoTypeFqn", }); internal_static_google_spanner_v1_StructType_descriptor = getDescriptor().getMessageTypes().get(1); @@ -92,7 +92,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_spanner_v1_StructType_descriptor, new java.lang.String[] { - "Fields", + "Fields", }); internal_static_google_spanner_v1_StructType_Field_descriptor = internal_static_google_spanner_v1_StructType_descriptor.getNestedTypes().get(0); @@ -100,7 +100,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_spanner_v1_StructType_Field_descriptor, new java.lang.String[] { - "Name", "Type", + "Name", "Type", }); com.google.protobuf.ExtensionRegistry registry = com.google.protobuf.ExtensionRegistry.newInstance(); From f63da186b441e41a961f97a741939a42ba45970d Mon Sep 17 00:00:00 2001 From: Sri Harsha CH Date: Fri, 9 Jun 2023 04:59:06 +0000 Subject: [PATCH 08/27] fix: revert host changes in pom.xml file --- google-cloud-spanner/pom.xml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/google-cloud-spanner/pom.xml b/google-cloud-spanner/pom.xml index b6bc5dedcc6..8ca79d2eb58 100644 --- a/google-cloud-spanner/pom.xml +++ b/google-cloud-spanner/pom.xml @@ -18,11 +18,10 @@ 0.31.1 22.3.2 com.google.cloud.spanner.GceTestEnvConfig - projects/span-cloud-testing/instances/spanner-testing-east1 - span-cloud-testing + projects/gcloud-devel/instances/spanner-testing-east1 + gcloud-devel projects/gcloud-devel/locations/us-east1/keyRings/cmek-test-key-ring/cryptoKeys/cmek-test-key - https://staging-wrenchworks.sandbox.googleapis.com - + @@ -66,7 +65,6 @@ ${spanner.testenv.instance} ${spanner.gce.config.project_id} ${spanner.testenv.kms_key.name} - ${spanner.gce.config.server_url} @@ -91,7 +89,6 @@ ${spanner.testenv.instance} ${spanner.gce.config.project_id} ${spanner.testenv.kms_key.name} - ${spanner.gce.config.server_url} 3000 From 7f5bd9811fa64e3d918d5a33e5cbae72f10166b8 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Wed, 10 Jan 2024 13:33:18 +0000 Subject: [PATCH 09/27] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 14ae7d30256..9ed8546f7be 100644 --- a/README.md +++ b/README.md @@ -57,13 +57,13 @@ implementation 'com.google.cloud:google-cloud-spanner' If you are using Gradle without BOM, add this to your dependencies: ```Groovy -implementation 'com.google.cloud:google-cloud-spanner:6.55.0' +implementation 'com.google.cloud:google-cloud-spanner:6.56.0' ``` If you are using SBT, add this to your dependencies: ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-spanner" % "6.55.0" +libraryDependencies += "com.google.cloud" % "google-cloud-spanner" % "6.56.0" ``` @@ -438,7 +438,7 @@ Java is a registered trademark of Oracle and/or its affiliates. [kokoro-badge-link-5]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-spanner/java11.html [stability-image]: https://img.shields.io/badge/stability-stable-green [maven-version-image]: https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-spanner.svg -[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-spanner/6.55.0 +[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-spanner/6.56.0 [authentication]: https://github.com/googleapis/google-cloud-java#authentication [auth-scopes]: https://developers.google.com/identity/protocols/oauth2/scopes [predefined-iam-roles]: https://cloud.google.com/iam/docs/understanding-roles#predefined_roles From 058b75c84563c6c393e149d5efb8f8b5a2e8e8cf Mon Sep 17 00:00:00 2001 From: Sri Harsha CH Date: Wed, 24 Jan 2024 13:03:55 +0000 Subject: [PATCH 10/27] feat(spanner): revert autogenerated code --- .../database/v1/CreateDatabaseRequest.java | 185 ++------ .../v1/CreateDatabaseRequestOrBuilder.java | 27 -- .../database/v1/GetDatabaseDdlResponse.java | 112 ----- .../v1/GetDatabaseDdlResponseOrBuilder.java | 17 - .../v1/SpannerDatabaseAdminProto.java | 432 +++++++++--------- .../database/v1/UpdateDatabaseDdlRequest.java | 205 ++------- .../v1/UpdateDatabaseDdlRequestOrBuilder.java | 32 -- .../database/v1/spanner_database_admin.proto | 46 -- .../main/java/com/google/spanner/v1/Type.java | 229 ++-------- .../java/com/google/spanner/v1/TypeCode.java | 12 - .../com/google/spanner/v1/TypeOrBuilder.java | 13 - .../java/com/google/spanner/v1/TypeProto.java | 35 +- .../main/proto/google/spanner/v1/type.proto | 12 - 13 files changed, 330 insertions(+), 1027 deletions(-) diff --git a/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/CreateDatabaseRequest.java b/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/CreateDatabaseRequest.java index 2b5c5dd4297..54065db2840 100644 --- a/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/CreateDatabaseRequest.java +++ b/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/CreateDatabaseRequest.java @@ -42,7 +42,6 @@ private CreateDatabaseRequest() { createStatement_ = ""; extraStatements_ = com.google.protobuf.LazyStringArrayList.emptyList(); databaseDialect_ = 0; - protoDescriptors_ = com.google.protobuf.ByteString.EMPTY; } @java.lang.Override @@ -362,38 +361,6 @@ public com.google.spanner.admin.database.v1.DatabaseDialect getDatabaseDialect() : result; } - public static final int PROTO_DESCRIPTORS_FIELD_NUMBER = 6; - private com.google.protobuf.ByteString protoDescriptors_ = com.google.protobuf.ByteString.EMPTY; - /** - * - * - *
-   * Proto descriptors used by CREATE/ALTER PROTO BUNDLE statements in
-   * 'extra_statements' above.
-   * Contains a protobuf-serialized
-   * [google.protobuf.FileDescriptorSet](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto).
-   * To generate it, [install](https://grpc.io/docs/protoc-installation/) and
-   * run `protoc` with --include_imports and --descriptor_set_out. For example,
-   * to generate for moon/shot/app.proto, run
-   * """
-   * $protoc  --proto_path=/app_path --proto_path=/lib_path \
-   *          --include_imports \
-   *          --descriptor_set_out=descriptors.data \
-   *          moon/shot/app.proto
-   * """
-   * For more details, see protobuffer [self
-   * description](https://developers.google.com/protocol-buffers/docs/techniques#self-description).
-   * 
- * - * bytes proto_descriptors = 6 [(.google.api.field_behavior) = OPTIONAL]; - * - * @return The protoDescriptors. - */ - @java.lang.Override - public com.google.protobuf.ByteString getProtoDescriptors() { - return protoDescriptors_; - } - private byte memoizedIsInitialized = -1; @java.lang.Override @@ -425,9 +392,6 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io .getNumber()) { output.writeEnum(5, databaseDialect_); } - if (!protoDescriptors_.isEmpty()) { - output.writeBytes(6, protoDescriptors_); - } getUnknownFields().writeTo(output); } @@ -459,9 +423,6 @@ public int getSerializedSize() { .getNumber()) { size += com.google.protobuf.CodedOutputStream.computeEnumSize(5, databaseDialect_); } - if (!protoDescriptors_.isEmpty()) { - size += com.google.protobuf.CodedOutputStream.computeBytesSize(6, protoDescriptors_); - } size += getUnknownFields().getSerializedSize(); memoizedSize = size; return size; @@ -486,7 +447,6 @@ public boolean equals(final java.lang.Object obj) { if (!getEncryptionConfig().equals(other.getEncryptionConfig())) return false; } if (databaseDialect_ != other.databaseDialect_) return false; - if (!getProtoDescriptors().equals(other.getProtoDescriptors())) return false; if (!getUnknownFields().equals(other.getUnknownFields())) return false; return true; } @@ -512,8 +472,6 @@ public int hashCode() { } hash = (37 * hash) + DATABASE_DIALECT_FIELD_NUMBER; hash = (53 * hash) + databaseDialect_; - hash = (37 * hash) + PROTO_DESCRIPTORS_FIELD_NUMBER; - hash = (53 * hash) + getProtoDescriptors().hashCode(); hash = (29 * hash) + getUnknownFields().hashCode(); memoizedHashCode = hash; return hash; @@ -663,7 +621,6 @@ public Builder clear() { encryptionConfigBuilder_ = null; } databaseDialect_ = 0; - protoDescriptors_ = com.google.protobuf.ByteString.EMPTY; return this; } @@ -717,9 +674,39 @@ private void buildPartial0(com.google.spanner.admin.database.v1.CreateDatabaseRe if (((from_bitField0_ & 0x00000010) != 0)) { result.databaseDialect_ = databaseDialect_; } - if (((from_bitField0_ & 0x00000020) != 0)) { - result.protoDescriptors_ = protoDescriptors_; - } + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.setField(field, value); + } + + @java.lang.Override + public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + + @java.lang.Override + public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.addRepeatedField(field, value); } @java.lang.Override @@ -761,9 +748,6 @@ public Builder mergeFrom(com.google.spanner.admin.database.v1.CreateDatabaseRequ if (other.databaseDialect_ != 0) { setDatabaseDialectValue(other.getDatabaseDialectValue()); } - if (other.getProtoDescriptors() != com.google.protobuf.ByteString.EMPTY) { - setProtoDescriptors(other.getProtoDescriptors()); - } this.mergeUnknownFields(other.getUnknownFields()); onChanged(); return this; @@ -822,12 +806,6 @@ public Builder mergeFrom( bitField0_ |= 0x00000010; break; } // case 40 - case 50: - { - protoDescriptors_ = input.readBytes(); - bitField0_ |= 0x00000020; - break; - } // case 50 default: { if (!super.parseUnknownField(input, extensionRegistry, tag)) { @@ -1622,103 +1600,6 @@ public Builder clearDatabaseDialect() { return this; } - private com.google.protobuf.ByteString protoDescriptors_ = com.google.protobuf.ByteString.EMPTY; - /** - * - * - *
-     * Proto descriptors used by CREATE/ALTER PROTO BUNDLE statements in
-     * 'extra_statements' above.
-     * Contains a protobuf-serialized
-     * [google.protobuf.FileDescriptorSet](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto).
-     * To generate it, [install](https://grpc.io/docs/protoc-installation/) and
-     * run `protoc` with --include_imports and --descriptor_set_out. For example,
-     * to generate for moon/shot/app.proto, run
-     * """
-     * $protoc  --proto_path=/app_path --proto_path=/lib_path \
-     *          --include_imports \
-     *          --descriptor_set_out=descriptors.data \
-     *          moon/shot/app.proto
-     * """
-     * For more details, see protobuffer [self
-     * description](https://developers.google.com/protocol-buffers/docs/techniques#self-description).
-     * 
- * - * bytes proto_descriptors = 6 [(.google.api.field_behavior) = OPTIONAL]; - * - * @return The protoDescriptors. - */ - @java.lang.Override - public com.google.protobuf.ByteString getProtoDescriptors() { - return protoDescriptors_; - } - /** - * - * - *
-     * Proto descriptors used by CREATE/ALTER PROTO BUNDLE statements in
-     * 'extra_statements' above.
-     * Contains a protobuf-serialized
-     * [google.protobuf.FileDescriptorSet](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto).
-     * To generate it, [install](https://grpc.io/docs/protoc-installation/) and
-     * run `protoc` with --include_imports and --descriptor_set_out. For example,
-     * to generate for moon/shot/app.proto, run
-     * """
-     * $protoc  --proto_path=/app_path --proto_path=/lib_path \
-     *          --include_imports \
-     *          --descriptor_set_out=descriptors.data \
-     *          moon/shot/app.proto
-     * """
-     * For more details, see protobuffer [self
-     * description](https://developers.google.com/protocol-buffers/docs/techniques#self-description).
-     * 
- * - * bytes proto_descriptors = 6 [(.google.api.field_behavior) = OPTIONAL]; - * - * @param value The protoDescriptors to set. - * @return This builder for chaining. - */ - public Builder setProtoDescriptors(com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - protoDescriptors_ = value; - bitField0_ |= 0x00000020; - onChanged(); - return this; - } - /** - * - * - *
-     * Proto descriptors used by CREATE/ALTER PROTO BUNDLE statements in
-     * 'extra_statements' above.
-     * Contains a protobuf-serialized
-     * [google.protobuf.FileDescriptorSet](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto).
-     * To generate it, [install](https://grpc.io/docs/protoc-installation/) and
-     * run `protoc` with --include_imports and --descriptor_set_out. For example,
-     * to generate for moon/shot/app.proto, run
-     * """
-     * $protoc  --proto_path=/app_path --proto_path=/lib_path \
-     *          --include_imports \
-     *          --descriptor_set_out=descriptors.data \
-     *          moon/shot/app.proto
-     * """
-     * For more details, see protobuffer [self
-     * description](https://developers.google.com/protocol-buffers/docs/techniques#self-description).
-     * 
- * - * bytes proto_descriptors = 6 [(.google.api.field_behavior) = OPTIONAL]; - * - * @return This builder for chaining. - */ - public Builder clearProtoDescriptors() { - bitField0_ = (bitField0_ & ~0x00000020); - protoDescriptors_ = getDefaultInstance().getProtoDescriptors(); - onChanged(); - return this; - } - @java.lang.Override public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { return super.setUnknownFields(unknownFields); diff --git a/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/CreateDatabaseRequestOrBuilder.java b/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/CreateDatabaseRequestOrBuilder.java index 88240ab0e24..2a71d1e2808 100644 --- a/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/CreateDatabaseRequestOrBuilder.java +++ b/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/CreateDatabaseRequestOrBuilder.java @@ -225,31 +225,4 @@ public interface CreateDatabaseRequestOrBuilder * @return The databaseDialect. */ com.google.spanner.admin.database.v1.DatabaseDialect getDatabaseDialect(); - - /** - * - * - *
-   * Proto descriptors used by CREATE/ALTER PROTO BUNDLE statements in
-   * 'extra_statements' above.
-   * Contains a protobuf-serialized
-   * [google.protobuf.FileDescriptorSet](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto).
-   * To generate it, [install](https://grpc.io/docs/protoc-installation/) and
-   * run `protoc` with --include_imports and --descriptor_set_out. For example,
-   * to generate for moon/shot/app.proto, run
-   * """
-   * $protoc  --proto_path=/app_path --proto_path=/lib_path \
-   *          --include_imports \
-   *          --descriptor_set_out=descriptors.data \
-   *          moon/shot/app.proto
-   * """
-   * For more details, see protobuffer [self
-   * description](https://developers.google.com/protocol-buffers/docs/techniques#self-description).
-   * 
- * - * bytes proto_descriptors = 6 [(.google.api.field_behavior) = OPTIONAL]; - * - * @return The protoDescriptors. - */ - com.google.protobuf.ByteString getProtoDescriptors(); } diff --git a/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/GetDatabaseDdlResponse.java b/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/GetDatabaseDdlResponse.java index f928c934301..b35f72c212c 100644 --- a/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/GetDatabaseDdlResponse.java +++ b/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/GetDatabaseDdlResponse.java @@ -39,7 +39,6 @@ private GetDatabaseDdlResponse(com.google.protobuf.GeneratedMessageV3.Builder private GetDatabaseDdlResponse() { statements_ = com.google.protobuf.LazyStringArrayList.emptyList(); - protoDescriptors_ = com.google.protobuf.ByteString.EMPTY; } @java.lang.Override @@ -131,28 +130,6 @@ public com.google.protobuf.ByteString getStatementsBytes(int index) { return statements_.getByteString(index); } - public static final int PROTO_DESCRIPTORS_FIELD_NUMBER = 2; - private com.google.protobuf.ByteString protoDescriptors_ = com.google.protobuf.ByteString.EMPTY; - /** - * - * - *
-   * Proto descriptors stored in the database.
-   * Contains a protobuf-serialized
-   * [google.protobuf.FileDescriptorSet](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto).
-   * For more details, see protobuffer [self
-   * description](https://developers.google.com/protocol-buffers/docs/techniques#self-description).
-   * 
- * - * bytes proto_descriptors = 2; - * - * @return The protoDescriptors. - */ - @java.lang.Override - public com.google.protobuf.ByteString getProtoDescriptors() { - return protoDescriptors_; - } - private byte memoizedIsInitialized = -1; @java.lang.Override @@ -170,9 +147,6 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io for (int i = 0; i < statements_.size(); i++) { com.google.protobuf.GeneratedMessageV3.writeString(output, 1, statements_.getRaw(i)); } - if (!protoDescriptors_.isEmpty()) { - output.writeBytes(2, protoDescriptors_); - } getUnknownFields().writeTo(output); } @@ -190,9 +164,6 @@ public int getSerializedSize() { size += dataSize; size += 1 * getStatementsList().size(); } - if (!protoDescriptors_.isEmpty()) { - size += com.google.protobuf.CodedOutputStream.computeBytesSize(2, protoDescriptors_); - } size += getUnknownFields().getSerializedSize(); memoizedSize = size; return size; @@ -210,7 +181,6 @@ public boolean equals(final java.lang.Object obj) { (com.google.spanner.admin.database.v1.GetDatabaseDdlResponse) obj; if (!getStatementsList().equals(other.getStatementsList())) return false; - if (!getProtoDescriptors().equals(other.getProtoDescriptors())) return false; if (!getUnknownFields().equals(other.getUnknownFields())) return false; return true; } @@ -226,8 +196,6 @@ public int hashCode() { hash = (37 * hash) + STATEMENTS_FIELD_NUMBER; hash = (53 * hash) + getStatementsList().hashCode(); } - hash = (37 * hash) + PROTO_DESCRIPTORS_FIELD_NUMBER; - hash = (53 * hash) + getProtoDescriptors().hashCode(); hash = (29 * hash) + getUnknownFields().hashCode(); memoizedHashCode = hash; return hash; @@ -369,7 +337,6 @@ public Builder clear() { super.clear(); bitField0_ = 0; statements_ = com.google.protobuf.LazyStringArrayList.emptyList(); - protoDescriptors_ = com.google.protobuf.ByteString.EMPTY; return this; } @@ -410,9 +377,6 @@ private void buildPartial0(com.google.spanner.admin.database.v1.GetDatabaseDdlRe statements_.makeImmutable(); result.statements_ = statements_; } - if (((from_bitField0_ & 0x00000002) != 0)) { - result.protoDescriptors_ = protoDescriptors_; - } } @java.lang.Override @@ -471,9 +435,6 @@ public Builder mergeFrom(com.google.spanner.admin.database.v1.GetDatabaseDdlResp } onChanged(); } - if (other.getProtoDescriptors() != com.google.protobuf.ByteString.EMPTY) { - setProtoDescriptors(other.getProtoDescriptors()); - } this.mergeUnknownFields(other.getUnknownFields()); onChanged(); return this; @@ -507,12 +468,6 @@ public Builder mergeFrom( statements_.add(s); break; } // case 10 - case 18: - { - protoDescriptors_ = input.readBytes(); - bitField0_ |= 0x00000002; - break; - } // case 18 default: { if (!super.parseUnknownField(input, extensionRegistry, tag)) { @@ -715,73 +670,6 @@ public Builder addStatementsBytes(com.google.protobuf.ByteString value) { return this; } - private com.google.protobuf.ByteString protoDescriptors_ = com.google.protobuf.ByteString.EMPTY; - /** - * - * - *
-     * Proto descriptors stored in the database.
-     * Contains a protobuf-serialized
-     * [google.protobuf.FileDescriptorSet](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto).
-     * For more details, see protobuffer [self
-     * description](https://developers.google.com/protocol-buffers/docs/techniques#self-description).
-     * 
- * - * bytes proto_descriptors = 2; - * - * @return The protoDescriptors. - */ - @java.lang.Override - public com.google.protobuf.ByteString getProtoDescriptors() { - return protoDescriptors_; - } - /** - * - * - *
-     * Proto descriptors stored in the database.
-     * Contains a protobuf-serialized
-     * [google.protobuf.FileDescriptorSet](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto).
-     * For more details, see protobuffer [self
-     * description](https://developers.google.com/protocol-buffers/docs/techniques#self-description).
-     * 
- * - * bytes proto_descriptors = 2; - * - * @param value The protoDescriptors to set. - * @return This builder for chaining. - */ - public Builder setProtoDescriptors(com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - protoDescriptors_ = value; - bitField0_ |= 0x00000002; - onChanged(); - return this; - } - /** - * - * - *
-     * Proto descriptors stored in the database.
-     * Contains a protobuf-serialized
-     * [google.protobuf.FileDescriptorSet](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto).
-     * For more details, see protobuffer [self
-     * description](https://developers.google.com/protocol-buffers/docs/techniques#self-description).
-     * 
- * - * bytes proto_descriptors = 2; - * - * @return This builder for chaining. - */ - public Builder clearProtoDescriptors() { - bitField0_ = (bitField0_ & ~0x00000002); - protoDescriptors_ = getDefaultInstance().getProtoDescriptors(); - onChanged(); - return this; - } - @java.lang.Override public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { return super.setUnknownFields(unknownFields); diff --git a/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/GetDatabaseDdlResponseOrBuilder.java b/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/GetDatabaseDdlResponseOrBuilder.java index b85b1c1a389..c436d5c844f 100644 --- a/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/GetDatabaseDdlResponseOrBuilder.java +++ b/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/GetDatabaseDdlResponseOrBuilder.java @@ -77,21 +77,4 @@ public interface GetDatabaseDdlResponseOrBuilder * @return The bytes of the statements at the given index. */ com.google.protobuf.ByteString getStatementsBytes(int index); - - /** - * - * - *
-   * Proto descriptors stored in the database.
-   * Contains a protobuf-serialized
-   * [google.protobuf.FileDescriptorSet](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto).
-   * For more details, see protobuffer [self
-   * description](https://developers.google.com/protocol-buffers/docs/techniques#self-description).
-   * 
- * - * bytes proto_descriptors = 2; - * - * @return The protoDescriptors. - */ - com.google.protobuf.ByteString getProtoDescriptors(); } diff --git a/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/SpannerDatabaseAdminProto.java b/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/SpannerDatabaseAdminProto.java index ae32748c346..9fd014fc9ac 100644 --- a/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/SpannerDatabaseAdminProto.java +++ b/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/SpannerDatabaseAdminProto.java @@ -183,217 +183,218 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { + "ption_config\030\004 \001(\01322.google.spanner.admi" + "n.database.v1.EncryptionConfigB\004\342A\001\001\022Q\n\020" + "database_dialect\030\005 \001(\01621.google.spanner." - + "admin.database.v1.DatabaseDialectB\004\342A\001\001\022" - + "\037\n\021proto_descriptors\030\006 \001(\014B\004\342A\001\001\"P\n\026Crea" - + "teDatabaseMetadata\0226\n\010database\030\001 \001(\tB$\372A" - + "!\n\037spanner.googleapis.com/Database\"L\n\022Ge" - + "tDatabaseRequest\0226\n\004name\030\001 \001(\tB(\342A\001\002\372A!\n" - + "\037spanner.googleapis.com/Database\"\222\001\n\025Upd" - + "ateDatabaseRequest\022B\n\010database\030\001 \001(\0132*.g" - + "oogle.spanner.admin.database.v1.Database" - + "B\004\342A\001\002\0225\n\013update_mask\030\002 \001(\0132\032.google.pro" - + "tobuf.FieldMaskB\004\342A\001\002\"\332\001\n\026UpdateDatabase" - + "Metadata\022H\n\007request\030\001 \001(\01327.google.spann" - + "er.admin.database.v1.UpdateDatabaseReque" - + "st\022E\n\010progress\030\002 \001(\01323.google.spanner.ad" - + "min.database.v1.OperationProgress\022/\n\013can" - + "cel_time\030\003 \001(\0132\032.google.protobuf.Timesta" - + "mp\"\247\001\n\030UpdateDatabaseDdlRequest\022:\n\010datab" + + "admin.database.v1.DatabaseDialectB\004\342A\001\001\"" + + "P\n\026CreateDatabaseMetadata\0226\n\010database\030\001 " + + "\001(\tB$\372A!\n\037spanner.googleapis.com/Databas" + + "e\"L\n\022GetDatabaseRequest\0226\n\004name\030\001 \001(\tB(\342" + + "A\001\002\372A!\n\037spanner.googleapis.com/Database\"" + + "\222\001\n\025UpdateDatabaseRequest\022B\n\010database\030\001 " + + "\001(\0132*.google.spanner.admin.database.v1.D" + + "atabaseB\004\342A\001\002\0225\n\013update_mask\030\002 \001(\0132\032.goo" + + "gle.protobuf.FieldMaskB\004\342A\001\002\"\332\001\n\026UpdateD" + + "atabaseMetadata\022H\n\007request\030\001 \001(\01327.googl" + + "e.spanner.admin.database.v1.UpdateDataba" + + "seRequest\022E\n\010progress\030\002 \001(\01323.google.spa" + + "nner.admin.database.v1.OperationProgress" + + "\022/\n\013cancel_time\030\003 \001(\0132\032.google.protobuf." + + "Timestamp\"\206\001\n\030UpdateDatabaseDdlRequest\022:" + + "\n\010database\030\001 \001(\tB(\342A\001\002\372A!\n\037spanner.googl" + + "eapis.com/Database\022\030\n\nstatements\030\002 \003(\tB\004" + + "\342A\001\002\022\024\n\014operation_id\030\003 \001(\t\"S\n\026DdlStateme" + + "ntActionInfo\022\016\n\006action\030\001 \001(\t\022\023\n\013entity_t" + + "ype\030\002 \001(\t\022\024\n\014entity_names\030\003 \003(\t\"\311\002\n\031Upda" + + "teDatabaseDdlMetadata\0226\n\010database\030\001 \001(\tB" + + "$\372A!\n\037spanner.googleapis.com/Database\022\022\n" + + "\nstatements\030\002 \003(\t\0225\n\021commit_timestamps\030\003" + + " \003(\0132\032.google.protobuf.Timestamp\022\027\n\tthro" + + "ttled\030\004 \001(\010B\004\342A\001\003\022E\n\010progress\030\005 \003(\01323.go" + + "ogle.spanner.admin.database.v1.Operation" + + "Progress\022I\n\007actions\030\006 \003(\01328.google.spann" + + "er.admin.database.v1.DdlStatementActionI" + + "nfo\"Q\n\023DropDatabaseRequest\022:\n\010database\030\001" + + " \001(\tB(\342A\001\002\372A!\n\037spanner.googleapis.com/Da" + + "tabase\"S\n\025GetDatabaseDdlRequest\022:\n\010datab" + "ase\030\001 \001(\tB(\342A\001\002\372A!\n\037spanner.googleapis.c" - + "om/Database\022\030\n\nstatements\030\002 \003(\tB\004\342A\001\002\022\024\n" - + "\014operation_id\030\003 \001(\t\022\037\n\021proto_descriptors" - + "\030\004 \001(\014B\004\342A\001\001\"\376\001\n\031UpdateDatabaseDdlMetada" - + "ta\0226\n\010database\030\001 \001(\tB$\372A!\n\037spanner.googl" - + "eapis.com/Database\022\022\n\nstatements\030\002 \003(\t\0225" - + "\n\021commit_timestamps\030\003 \003(\0132\032.google.proto" - + "buf.Timestamp\022\027\n\tthrottled\030\004 \001(\010B\004\342A\001\003\022E" - + "\n\010progress\030\005 \003(\01323.google.spanner.admin." - + "database.v1.OperationProgress\"Q\n\023DropDat" - + "abaseRequest\022:\n\010database\030\001 \001(\tB(\342A\001\002\372A!\n" - + "\037spanner.googleapis.com/Database\"S\n\025GetD" - + "atabaseDdlRequest\022:\n\010database\030\001 \001(\tB(\342A\001" - + "\002\372A!\n\037spanner.googleapis.com/Database\"G\n" - + "\026GetDatabaseDdlResponse\022\022\n\nstatements\030\001 " - + "\003(\t\022\031\n\021proto_descriptors\030\002 \001(\014\"\220\001\n\035ListD" - + "atabaseOperationsRequest\0228\n\006parent\030\001 \001(\t" - + "B(\342A\001\002\372A!\n\037spanner.googleapis.com/Instan" - + "ce\022\016\n\006filter\030\002 \001(\t\022\021\n\tpage_size\030\003 \001(\005\022\022\n" - + "\npage_token\030\004 \001(\t\"l\n\036ListDatabaseOperati" - + "onsResponse\0221\n\noperations\030\001 \003(\0132\035.google" - + ".longrunning.Operation\022\027\n\017next_page_toke" - + "n\030\002 \001(\t\"\221\002\n\026RestoreDatabaseRequest\0228\n\006pa" - + "rent\030\001 \001(\tB(\342A\001\002\372A!\n\037spanner.googleapis." - + "com/Instance\022\031\n\013database_id\030\002 \001(\tB\004\342A\001\002\022" - + "4\n\006backup\030\003 \001(\tB\"\372A\037\n\035spanner.googleapis" - + ".com/BackupH\000\022b\n\021encryption_config\030\004 \001(\013" - + "2A.google.spanner.admin.database.v1.Rest" - + "oreDatabaseEncryptionConfigB\004\342A\001\001B\010\n\006sou" - + "rce\"\365\002\n\037RestoreDatabaseEncryptionConfig\022" - + "o\n\017encryption_type\030\001 \001(\0162P.google.spanne" - + "r.admin.database.v1.RestoreDatabaseEncry" - + "ptionConfig.EncryptionTypeB\004\342A\001\002\022@\n\014kms_" - + "key_name\030\002 \001(\tB*\342A\001\001\372A#\n!cloudkms.google" - + "apis.com/CryptoKey\"\236\001\n\016EncryptionType\022\037\n" - + "\033ENCRYPTION_TYPE_UNSPECIFIED\020\000\022+\n\'USE_CO" - + "NFIG_DEFAULT_OR_BACKUP_ENCRYPTION\020\001\022\035\n\031G" - + "OOGLE_DEFAULT_ENCRYPTION\020\002\022\037\n\033CUSTOMER_M" - + "ANAGED_ENCRYPTION\020\003\"\215\003\n\027RestoreDatabaseM" - + "etadata\0222\n\004name\030\001 \001(\tB$\372A!\n\037spanner.goog" - + "leapis.com/Database\022H\n\013source_type\030\002 \001(\016" - + "23.google.spanner.admin.database.v1.Rest" - + "oreSourceType\022C\n\013backup_info\030\003 \001(\0132,.goo" - + "gle.spanner.admin.database.v1.BackupInfo" - + "H\000\022E\n\010progress\030\004 \001(\01323.google.spanner.ad" - + "min.database.v1.OperationProgress\022/\n\013can" - + "cel_time\030\005 \001(\0132\032.google.protobuf.Timesta" - + "mp\022(\n optimize_database_operation_name\030\006" - + " \001(\tB\r\n\013source_info\"\235\001\n OptimizeRestored" - + "DatabaseMetadata\0222\n\004name\030\001 \001(\tB$\372A!\n\037spa" - + "nner.googleapis.com/Database\022E\n\010progress" - + "\030\002 \001(\01323.google.spanner.admin.database.v" - + "1.OperationProgress\"\237\001\n\014DatabaseRole\022\022\n\004" - + "name\030\001 \001(\tB\004\342A\001\002:{\352Ax\n#spanner.googleapi" - + "s.com/DatabaseRole\022Qprojects/{project}/i" - + "nstances/{instance}/databases/{database}" - + "/databaseRoles/{role}\"{\n\030ListDatabaseRol" - + "esRequest\0228\n\006parent\030\001 \001(\tB(\342A\001\002\372A!\n\037span" - + "ner.googleapis.com/Database\022\021\n\tpage_size" - + "\030\002 \001(\005\022\022\n\npage_token\030\003 \001(\t\"|\n\031ListDataba" - + "seRolesResponse\022F\n\016database_roles\030\001 \003(\0132" - + "..google.spanner.admin.database.v1.Datab" - + "aseRole\022\027\n\017next_page_token\030\002 \001(\t*5\n\021Rest" - + "oreSourceType\022\024\n\020TYPE_UNSPECIFIED\020\000\022\n\n\006B" - + "ACKUP\020\0012\356%\n\rDatabaseAdmin\022\300\001\n\rListDataba" - + "ses\0226.google.spanner.admin.database.v1.L" - + "istDatabasesRequest\0327.google.spanner.adm" - + "in.database.v1.ListDatabasesResponse\">\332A" - + "\006parent\202\323\344\223\002/\022-/v1/{parent=projects/*/in" - + "stances/*}/databases\022\244\002\n\016CreateDatabase\022" - + "7.google.spanner.admin.database.v1.Creat" - + "eDatabaseRequest\032\035.google.longrunning.Op" - + "eration\"\271\001\312Ad\n)google.spanner.admin.data" - + "base.v1.Database\0227google.spanner.admin.d" - + "atabase.v1.CreateDatabaseMetadata\332A\027pare" - + "nt,create_statement\202\323\344\223\0022\"-/v1/{parent=p" - + "rojects/*/instances/*}/databases:\001*\022\255\001\n\013" - + "GetDatabase\0224.google.spanner.admin.datab" - + "ase.v1.GetDatabaseRequest\032*.google.spann" - + "er.admin.database.v1.Database\"<\332A\004name\202\323" - + "\344\223\002/\022-/v1/{name=projects/*/instances/*/d" - + "atabases/*}\022\357\001\n\016UpdateDatabase\0227.google." - + "spanner.admin.database.v1.UpdateDatabase" - + "Request\032\035.google.longrunning.Operation\"\204" - + "\001\312A\"\n\010Database\022\026UpdateDatabaseMetadata\332A" - + "\024database,update_mask\202\323\344\223\002B26/v1/{databa" - + "se.name=projects/*/instances/*/databases" - + "/*}:\010database\022\235\002\n\021UpdateDatabaseDdl\022:.go" - + "ogle.spanner.admin.database.v1.UpdateDat" - + "abaseDdlRequest\032\035.google.longrunning.Ope" - + "ration\"\254\001\312AS\n\025google.protobuf.Empty\022:goo" - + "gle.spanner.admin.database.v1.UpdateData" - + "baseDdlMetadata\332A\023database,statements\202\323\344" - + "\223\002:25/v1/{database=projects/*/instances/" - + "*/databases/*}/ddl:\001*\022\243\001\n\014DropDatabase\0225" - + ".google.spanner.admin.database.v1.DropDa" - + "tabaseRequest\032\026.google.protobuf.Empty\"D\332" - + "A\010database\202\323\344\223\0023*1/v1/{database=projects" - + "/*/instances/*/databases/*}\022\315\001\n\016GetDatab" - + "aseDdl\0227.google.spanner.admin.database.v" - + "1.GetDatabaseDdlRequest\0328.google.spanner" - + ".admin.database.v1.GetDatabaseDdlRespons" - + "e\"H\332A\010database\202\323\344\223\0027\0225/v1/{database=proj" - + "ects/*/instances/*/databases/*}/ddl\022\353\001\n\014" - + "SetIamPolicy\022\".google.iam.v1.SetIamPolic" - + "yRequest\032\025.google.iam.v1.Policy\"\237\001\332A\017res" - + "ource,policy\202\323\344\223\002\206\001\">/v1/{resource=proje" - + "cts/*/instances/*/databases/*}:setIamPol" - + "icy:\001*ZA\"/v1/{resource=projects/*/ins" - + "tances/*/databases/*}:getIamPolicy:\001*ZA\"" - + ".google.spanner.admin." - + "database.v1.ListBackupOperationsResponse" - + "\"E\332A\006parent\202\323\344\223\0026\0224/v1/{parent=projects/" - + "*/instances/*}/backupOperations\022\334\001\n\021List" - + "DatabaseRoles\022:.google.spanner.admin.dat" - + "abase.v1.ListDatabaseRolesRequest\032;.goog" - + "le.spanner.admin.database.v1.ListDatabas" - + "eRolesResponse\"N\332A\006parent\202\323\344\223\002?\022=/v1/{pa" - + "rent=projects/*/instances/*/databases/*}" - + "/databaseRoles\032x\312A\026spanner.googleapis.co" - + "m\322A\\https://www.googleapis.com/auth/clou" - + "d-platform,https://www.googleapis.com/au" - + "th/spanner.adminB\330\002\n$com.google.spanner." - + "admin.database.v1B\031SpannerDatabaseAdminP" - + "rotoP\001ZFcloud.google.com/go/spanner/admi" - + "n/database/apiv1/databasepb;databasepb\252\002" - + "&Google.Cloud.Spanner.Admin.Database.V1\312" - + "\002&Google\\Cloud\\Spanner\\Admin\\Database\\V1" - + "\352\002+Google::Cloud::Spanner::Admin::Databa" - + "se::V1\352AJ\n\037spanner.googleapis.com/Instan" - + "ce\022\'projects/{project}/instances/{instan" - + "ce}b\006proto3" + + "om/Database\",\n\026GetDatabaseDdlResponse\022\022\n" + + "\nstatements\030\001 \003(\t\"\220\001\n\035ListDatabaseOperat" + + "ionsRequest\0228\n\006parent\030\001 \001(\tB(\342A\001\002\372A!\n\037sp" + + "anner.googleapis.com/Instance\022\016\n\006filter\030" + + "\002 \001(\t\022\021\n\tpage_size\030\003 \001(\005\022\022\n\npage_token\030\004" + + " \001(\t\"l\n\036ListDatabaseOperationsResponse\0221" + + "\n\noperations\030\001 \003(\0132\035.google.longrunning." + + "Operation\022\027\n\017next_page_token\030\002 \001(\t\"\221\002\n\026R" + + "estoreDatabaseRequest\0228\n\006parent\030\001 \001(\tB(\342" + + "A\001\002\372A!\n\037spanner.googleapis.com/Instance\022" + + "\031\n\013database_id\030\002 \001(\tB\004\342A\001\002\0224\n\006backup\030\003 \001" + + "(\tB\"\372A\037\n\035spanner.googleapis.com/BackupH\000" + + "\022b\n\021encryption_config\030\004 \001(\0132A.google.spa" + + "nner.admin.database.v1.RestoreDatabaseEn" + + "cryptionConfigB\004\342A\001\001B\010\n\006source\"\365\002\n\037Resto" + + "reDatabaseEncryptionConfig\022o\n\017encryption" + + "_type\030\001 \001(\0162P.google.spanner.admin.datab" + + "ase.v1.RestoreDatabaseEncryptionConfig.E" + + "ncryptionTypeB\004\342A\001\002\022@\n\014kms_key_name\030\002 \001(" + + "\tB*\342A\001\001\372A#\n!cloudkms.googleapis.com/Cryp" + + "toKey\"\236\001\n\016EncryptionType\022\037\n\033ENCRYPTION_T" + + "YPE_UNSPECIFIED\020\000\022+\n\'USE_CONFIG_DEFAULT_" + + "OR_BACKUP_ENCRYPTION\020\001\022\035\n\031GOOGLE_DEFAULT" + + "_ENCRYPTION\020\002\022\037\n\033CUSTOMER_MANAGED_ENCRYP" + + "TION\020\003\"\215\003\n\027RestoreDatabaseMetadata\0222\n\004na" + + "me\030\001 \001(\tB$\372A!\n\037spanner.googleapis.com/Da" + + "tabase\022H\n\013source_type\030\002 \001(\01623.google.spa" + + "nner.admin.database.v1.RestoreSourceType" + + "\022C\n\013backup_info\030\003 \001(\0132,.google.spanner.a" + + "dmin.database.v1.BackupInfoH\000\022E\n\010progres" + + "s\030\004 \001(\01323.google.spanner.admin.database." + + "v1.OperationProgress\022/\n\013cancel_time\030\005 \001(" + + "\0132\032.google.protobuf.Timestamp\022(\n optimiz" + + "e_database_operation_name\030\006 \001(\tB\r\n\013sourc" + + "e_info\"\235\001\n OptimizeRestoredDatabaseMetad" + + "ata\0222\n\004name\030\001 \001(\tB$\372A!\n\037spanner.googleap" + + "is.com/Database\022E\n\010progress\030\002 \001(\01323.goog" + + "le.spanner.admin.database.v1.OperationPr" + + "ogress\"\237\001\n\014DatabaseRole\022\022\n\004name\030\001 \001(\tB\004\342" + + "A\001\002:{\352Ax\n#spanner.googleapis.com/Databas" + + "eRole\022Qprojects/{project}/instances/{ins" + + "tance}/databases/{database}/databaseRole" + + "s/{role}\"{\n\030ListDatabaseRolesRequest\0228\n\006" + + "parent\030\001 \001(\tB(\342A\001\002\372A!\n\037spanner.googleapi" + + "s.com/Database\022\021\n\tpage_size\030\002 \001(\005\022\022\n\npag" + + "e_token\030\003 \001(\t\"|\n\031ListDatabaseRolesRespon" + + "se\022F\n\016database_roles\030\001 \003(\0132..google.span" + + "ner.admin.database.v1.DatabaseRole\022\027\n\017ne" + + "xt_page_token\030\002 \001(\t*5\n\021RestoreSourceType" + + "\022\024\n\020TYPE_UNSPECIFIED\020\000\022\n\n\006BACKUP\020\0012\356%\n\rD" + + "atabaseAdmin\022\300\001\n\rListDatabases\0226.google." + + "spanner.admin.database.v1.ListDatabasesR" + + "equest\0327.google.spanner.admin.database.v" + + "1.ListDatabasesResponse\">\332A\006parent\202\323\344\223\002/" + + "\022-/v1/{parent=projects/*/instances/*}/da" + + "tabases\022\244\002\n\016CreateDatabase\0227.google.span" + + "ner.admin.database.v1.CreateDatabaseRequ" + + "est\032\035.google.longrunning.Operation\"\271\001\312Ad" + + "\n)google.spanner.admin.database.v1.Datab" + + "ase\0227google.spanner.admin.database.v1.Cr" + + "eateDatabaseMetadata\332A\027parent,create_sta" + + "tement\202\323\344\223\0022\"-/v1/{parent=projects/*/ins" + + "tances/*}/databases:\001*\022\255\001\n\013GetDatabase\0224" + + ".google.spanner.admin.database.v1.GetDat" + + "abaseRequest\032*.google.spanner.admin.data" + + "base.v1.Database\"<\332A\004name\202\323\344\223\002/\022-/v1/{na" + + "me=projects/*/instances/*/databases/*}\022\357" + + "\001\n\016UpdateDatabase\0227.google.spanner.admin" + + ".database.v1.UpdateDatabaseRequest\032\035.goo" + + "gle.longrunning.Operation\"\204\001\312A\"\n\010Databas" + + "e\022\026UpdateDatabaseMetadata\332A\024database,upd" + + "ate_mask\202\323\344\223\002B26/v1/{database.name=proje" + + "cts/*/instances/*/databases/*}:\010database" + + "\022\235\002\n\021UpdateDatabaseDdl\022:.google.spanner." + + "admin.database.v1.UpdateDatabaseDdlReque" + + "st\032\035.google.longrunning.Operation\"\254\001\312AS\n" + + "\025google.protobuf.Empty\022:google.spanner.a" + + "dmin.database.v1.UpdateDatabaseDdlMetada" + + "ta\332A\023database,statements\202\323\344\223\002:25/v1/{dat" + + "abase=projects/*/instances/*/databases/*" + + "}/ddl:\001*\022\243\001\n\014DropDatabase\0225.google.spann" + + "er.admin.database.v1.DropDatabaseRequest" + + "\032\026.google.protobuf.Empty\"D\332A\010database\202\323\344" + + "\223\0023*1/v1/{database=projects/*/instances/" + + "*/databases/*}\022\315\001\n\016GetDatabaseDdl\0227.goog" + + "le.spanner.admin.database.v1.GetDatabase" + + "DdlRequest\0328.google.spanner.admin.databa" + + "se.v1.GetDatabaseDdlResponse\"H\332A\010databas" + + "e\202\323\344\223\0027\0225/v1/{database=projects/*/instan" + + "ces/*/databases/*}/ddl\022\353\001\n\014SetIamPolicy\022" + + "\".google.iam.v1.SetIamPolicyRequest\032\025.go" + + "ogle.iam.v1.Policy\"\237\001\332A\017resource,policy\202" + + "\323\344\223\002\206\001\">/v1/{resource=projects/*/instanc" + + "es/*/databases/*}:setIamPolicy:\001*ZA\"/" + + "v1/{resource=projects/*/instances/*/data" + + "bases/*}:getIamPolicy:\001*ZA\".google.spanner.admin.database.v1.L" + + "istBackupOperationsResponse\"E\332A\006parent\202\323" + + "\344\223\0026\0224/v1/{parent=projects/*/instances/*" + + "}/backupOperations\022\334\001\n\021ListDatabaseRoles" + + "\022:.google.spanner.admin.database.v1.List" + + "DatabaseRolesRequest\032;.google.spanner.ad" + + "min.database.v1.ListDatabaseRolesRespons" + + "e\"N\332A\006parent\202\323\344\223\002?\022=/v1/{parent=projects" + + "/*/instances/*/databases/*}/databaseRole" + + "s\032x\312A\026spanner.googleapis.com\322A\\https://w" + + "ww.googleapis.com/auth/cloud-platform,ht" + + "tps://www.googleapis.com/auth/spanner.ad" + + "minB\330\002\n$com.google.spanner.admin.databas" + + "e.v1B\031SpannerDatabaseAdminProtoP\001ZFcloud" + + ".google.com/go/spanner/admin/database/ap" + + "iv1/databasepb;databasepb\252\002&Google.Cloud" + + ".Spanner.Admin.Database.V1\312\002&Google\\Clou" + + "d\\Spanner\\Admin\\Database\\V1\352\002+Google::Cl" + + "oud::Spanner::Admin::Database::V1\352AJ\n\037sp" + + "anner.googleapis.com/Instance\022\'projects/" + + "{project}/instances/{instance}b\006proto3" }; descriptor = com.google.protobuf.Descriptors.FileDescriptor.internalBuildGeneratedFileFrom( @@ -461,12 +462,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_spanner_admin_database_v1_CreateDatabaseRequest_descriptor, new java.lang.String[] { - "Parent", - "CreateStatement", - "ExtraStatements", - "EncryptionConfig", - "DatabaseDialect", - "ProtoDescriptors", + "Parent", "CreateStatement", "ExtraStatements", "EncryptionConfig", "DatabaseDialect", }); internal_static_google_spanner_admin_database_v1_CreateDatabaseMetadata_descriptor = getDescriptor().getMessageTypes().get(5); @@ -506,7 +502,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_spanner_admin_database_v1_UpdateDatabaseDdlRequest_descriptor, new java.lang.String[] { - "Database", "Statements", "OperationId", "ProtoDescriptors", + "Database", "Statements", "OperationId", }); internal_static_google_spanner_admin_database_v1_DdlStatementActionInfo_descriptor = getDescriptor().getMessageTypes().get(10); @@ -546,7 +542,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_spanner_admin_database_v1_GetDatabaseDdlResponse_descriptor, new java.lang.String[] { - "Statements", "ProtoDescriptors", + "Statements", }); internal_static_google_spanner_admin_database_v1_ListDatabaseOperationsRequest_descriptor = getDescriptor().getMessageTypes().get(15); diff --git a/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/UpdateDatabaseDdlRequest.java b/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/UpdateDatabaseDdlRequest.java index 9b97b0c1174..dee90581940 100644 --- a/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/UpdateDatabaseDdlRequest.java +++ b/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/UpdateDatabaseDdlRequest.java @@ -56,7 +56,6 @@ private UpdateDatabaseDdlRequest() { database_ = ""; statements_ = com.google.protobuf.LazyStringArrayList.emptyList(); operationId_ = ""; - protoDescriptors_ = com.google.protobuf.ByteString.EMPTY; } @java.lang.Override @@ -286,43 +285,6 @@ public com.google.protobuf.ByteString getOperationIdBytes() { } } - public static final int PROTO_DESCRIPTORS_FIELD_NUMBER = 4; - private com.google.protobuf.ByteString protoDescriptors_ = com.google.protobuf.ByteString.EMPTY; - /** - * - * - *
-   * Proto descriptors used by CREATE/ALTER PROTO BUNDLE statements.
-   * Contains a protobuf-serialized
-   * [google.protobuf.FileDescriptorSet](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto).
-   * To generate it, [install](https://grpc.io/docs/protoc-installation/) and
-   * run `protoc` with --include_imports and --descriptor_set_out. For example,
-   * to generate for moon/shot/app.proto, run
-   * """
-   * $protoc  --proto_path=/app_path --proto_path=/lib_path \
-   *          --include_imports \
-   *          --descriptor_set_out=descriptors.data \
-   *          moon/shot/app.proto
-   * """
-   * For more details, see protobuffer [self
-   * description](https://developers.google.com/protocol-buffers/docs/techniques#self-description).
-   * (--
-   * TODO(b/236424835) remove visibility check before launch.
-   * --)
-   * (-- api-linter: core::0134::request-unknown-fields=disabled
-   *     aip.dev/not-precedent: This Update*Request provides an alter action
-   *     rather than the usual entity field updating. --)
-   * 
- * - * bytes proto_descriptors = 4 [(.google.api.field_behavior) = OPTIONAL]; - * - * @return The protoDescriptors. - */ - @java.lang.Override - public com.google.protobuf.ByteString getProtoDescriptors() { - return protoDescriptors_; - } - private byte memoizedIsInitialized = -1; @java.lang.Override @@ -346,9 +308,6 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(operationId_)) { com.google.protobuf.GeneratedMessageV3.writeString(output, 3, operationId_); } - if (!protoDescriptors_.isEmpty()) { - output.writeBytes(4, protoDescriptors_); - } getUnknownFields().writeTo(output); } @@ -372,9 +331,6 @@ public int getSerializedSize() { if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(operationId_)) { size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, operationId_); } - if (!protoDescriptors_.isEmpty()) { - size += com.google.protobuf.CodedOutputStream.computeBytesSize(4, protoDescriptors_); - } size += getUnknownFields().getSerializedSize(); memoizedSize = size; return size; @@ -394,7 +350,6 @@ public boolean equals(final java.lang.Object obj) { if (!getDatabase().equals(other.getDatabase())) return false; if (!getStatementsList().equals(other.getStatementsList())) return false; if (!getOperationId().equals(other.getOperationId())) return false; - if (!getProtoDescriptors().equals(other.getProtoDescriptors())) return false; if (!getUnknownFields().equals(other.getUnknownFields())) return false; return true; } @@ -414,8 +369,6 @@ public int hashCode() { } hash = (37 * hash) + OPERATION_ID_FIELD_NUMBER; hash = (53 * hash) + getOperationId().hashCode(); - hash = (37 * hash) + PROTO_DESCRIPTORS_FIELD_NUMBER; - hash = (53 * hash) + getProtoDescriptors().hashCode(); hash = (29 * hash) + getUnknownFields().hashCode(); memoizedHashCode = hash; return hash; @@ -574,7 +527,6 @@ public Builder clear() { database_ = ""; statements_ = com.google.protobuf.LazyStringArrayList.emptyList(); operationId_ = ""; - protoDescriptors_ = com.google.protobuf.ByteString.EMPTY; return this; } @@ -623,9 +575,39 @@ private void buildPartial0( if (((from_bitField0_ & 0x00000004) != 0)) { result.operationId_ = operationId_; } - if (((from_bitField0_ & 0x00000008) != 0)) { - result.protoDescriptors_ = protoDescriptors_; - } + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.setField(field, value); + } + + @java.lang.Override + public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + + @java.lang.Override + public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.addRepeatedField(field, value); } @java.lang.Override @@ -662,9 +644,6 @@ public Builder mergeFrom(com.google.spanner.admin.database.v1.UpdateDatabaseDdlR bitField0_ |= 0x00000004; onChanged(); } - if (other.getProtoDescriptors() != com.google.protobuf.ByteString.EMPTY) { - setProtoDescriptors(other.getProtoDescriptors()); - } this.mergeUnknownFields(other.getUnknownFields()); onChanged(); return this; @@ -710,12 +689,6 @@ public Builder mergeFrom( bitField0_ |= 0x00000004; break; } // case 26 - case 34: - { - protoDescriptors_ = input.readBytes(); - bitField0_ |= 0x00000008; - break; - } // case 34 default: { if (!super.parseUnknownField(input, extensionRegistry, tag)) { @@ -1221,118 +1194,6 @@ public Builder setOperationIdBytes(com.google.protobuf.ByteString value) { return this; } - private com.google.protobuf.ByteString protoDescriptors_ = com.google.protobuf.ByteString.EMPTY; - /** - * - * - *
-     * Proto descriptors used by CREATE/ALTER PROTO BUNDLE statements.
-     * Contains a protobuf-serialized
-     * [google.protobuf.FileDescriptorSet](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto).
-     * To generate it, [install](https://grpc.io/docs/protoc-installation/) and
-     * run `protoc` with --include_imports and --descriptor_set_out. For example,
-     * to generate for moon/shot/app.proto, run
-     * """
-     * $protoc  --proto_path=/app_path --proto_path=/lib_path \
-     *          --include_imports \
-     *          --descriptor_set_out=descriptors.data \
-     *          moon/shot/app.proto
-     * """
-     * For more details, see protobuffer [self
-     * description](https://developers.google.com/protocol-buffers/docs/techniques#self-description).
-     * (--
-     * TODO(b/236424835) remove visibility check before launch.
-     * --)
-     * (-- api-linter: core::0134::request-unknown-fields=disabled
-     *     aip.dev/not-precedent: This Update*Request provides an alter action
-     *     rather than the usual entity field updating. --)
-     * 
- * - * bytes proto_descriptors = 4 [(.google.api.field_behavior) = OPTIONAL]; - * - * @return The protoDescriptors. - */ - @java.lang.Override - public com.google.protobuf.ByteString getProtoDescriptors() { - return protoDescriptors_; - } - /** - * - * - *
-     * Proto descriptors used by CREATE/ALTER PROTO BUNDLE statements.
-     * Contains a protobuf-serialized
-     * [google.protobuf.FileDescriptorSet](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto).
-     * To generate it, [install](https://grpc.io/docs/protoc-installation/) and
-     * run `protoc` with --include_imports and --descriptor_set_out. For example,
-     * to generate for moon/shot/app.proto, run
-     * """
-     * $protoc  --proto_path=/app_path --proto_path=/lib_path \
-     *          --include_imports \
-     *          --descriptor_set_out=descriptors.data \
-     *          moon/shot/app.proto
-     * """
-     * For more details, see protobuffer [self
-     * description](https://developers.google.com/protocol-buffers/docs/techniques#self-description).
-     * (--
-     * TODO(b/236424835) remove visibility check before launch.
-     * --)
-     * (-- api-linter: core::0134::request-unknown-fields=disabled
-     *     aip.dev/not-precedent: This Update*Request provides an alter action
-     *     rather than the usual entity field updating. --)
-     * 
- * - * bytes proto_descriptors = 4 [(.google.api.field_behavior) = OPTIONAL]; - * - * @param value The protoDescriptors to set. - * @return This builder for chaining. - */ - public Builder setProtoDescriptors(com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - protoDescriptors_ = value; - bitField0_ |= 0x00000008; - onChanged(); - return this; - } - /** - * - * - *
-     * Proto descriptors used by CREATE/ALTER PROTO BUNDLE statements.
-     * Contains a protobuf-serialized
-     * [google.protobuf.FileDescriptorSet](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto).
-     * To generate it, [install](https://grpc.io/docs/protoc-installation/) and
-     * run `protoc` with --include_imports and --descriptor_set_out. For example,
-     * to generate for moon/shot/app.proto, run
-     * """
-     * $protoc  --proto_path=/app_path --proto_path=/lib_path \
-     *          --include_imports \
-     *          --descriptor_set_out=descriptors.data \
-     *          moon/shot/app.proto
-     * """
-     * For more details, see protobuffer [self
-     * description](https://developers.google.com/protocol-buffers/docs/techniques#self-description).
-     * (--
-     * TODO(b/236424835) remove visibility check before launch.
-     * --)
-     * (-- api-linter: core::0134::request-unknown-fields=disabled
-     *     aip.dev/not-precedent: This Update*Request provides an alter action
-     *     rather than the usual entity field updating. --)
-     * 
- * - * bytes proto_descriptors = 4 [(.google.api.field_behavior) = OPTIONAL]; - * - * @return This builder for chaining. - */ - public Builder clearProtoDescriptors() { - bitField0_ = (bitField0_ & ~0x00000008); - protoDescriptors_ = getDefaultInstance().getProtoDescriptors(); - onChanged(); - return this; - } - @java.lang.Override public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { return super.setUnknownFields(unknownFields); diff --git a/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/UpdateDatabaseDdlRequestOrBuilder.java b/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/UpdateDatabaseDdlRequestOrBuilder.java index 5d8bf19f939..ead26bcfab8 100644 --- a/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/UpdateDatabaseDdlRequestOrBuilder.java +++ b/proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/UpdateDatabaseDdlRequestOrBuilder.java @@ -163,36 +163,4 @@ public interface UpdateDatabaseDdlRequestOrBuilder * @return The bytes for operationId. */ com.google.protobuf.ByteString getOperationIdBytes(); - - /** - * - * - *
-   * Proto descriptors used by CREATE/ALTER PROTO BUNDLE statements.
-   * Contains a protobuf-serialized
-   * [google.protobuf.FileDescriptorSet](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto).
-   * To generate it, [install](https://grpc.io/docs/protoc-installation/) and
-   * run `protoc` with --include_imports and --descriptor_set_out. For example,
-   * to generate for moon/shot/app.proto, run
-   * """
-   * $protoc  --proto_path=/app_path --proto_path=/lib_path \
-   *          --include_imports \
-   *          --descriptor_set_out=descriptors.data \
-   *          moon/shot/app.proto
-   * """
-   * For more details, see protobuffer [self
-   * description](https://developers.google.com/protocol-buffers/docs/techniques#self-description).
-   * (--
-   * TODO(b/236424835) remove visibility check before launch.
-   * --)
-   * (-- api-linter: core::0134::request-unknown-fields=disabled
-   *     aip.dev/not-precedent: This Update*Request provides an alter action
-   *     rather than the usual entity field updating. --)
-   * 
- * - * bytes proto_descriptors = 4 [(.google.api.field_behavior) = OPTIONAL]; - * - * @return The protoDescriptors. - */ - com.google.protobuf.ByteString getProtoDescriptors(); } diff --git a/proto-google-cloud-spanner-admin-database-v1/src/main/proto/google/spanner/admin/database/v1/spanner_database_admin.proto b/proto-google-cloud-spanner-admin-database-v1/src/main/proto/google/spanner/admin/database/v1/spanner_database_admin.proto index 4c03f9b6844..6cf0e5a4b94 100644 --- a/proto-google-cloud-spanner-admin-database-v1/src/main/proto/google/spanner/admin/database/v1/spanner_database_admin.proto +++ b/proto-google-cloud-spanner-admin-database-v1/src/main/proto/google/spanner/admin/database/v1/spanner_database_admin.proto @@ -572,23 +572,6 @@ message CreateDatabaseRequest { // Optional. The dialect of the Cloud Spanner Database. DatabaseDialect database_dialect = 5 [(google.api.field_behavior) = OPTIONAL]; - - // Proto descriptors used by CREATE/ALTER PROTO BUNDLE statements in - // 'extra_statements' above. - // Contains a protobuf-serialized - // [google.protobuf.FileDescriptorSet](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto). - // To generate it, [install](https://grpc.io/docs/protoc-installation/) and - // run `protoc` with --include_imports and --descriptor_set_out. For example, - // to generate for moon/shot/app.proto, run - // """ - // $protoc --proto_path=/app_path --proto_path=/lib_path \ - // --include_imports \ - // --descriptor_set_out=descriptors.data \ - // moon/shot/app.proto - // """ - // For more details, see protobuffer [self - // description](https://developers.google.com/protocol-buffers/docs/techniques#self-description). - bytes proto_descriptors = 6 [(google.api.field_behavior) = OPTIONAL]; } // Metadata type for the operation returned by @@ -691,28 +674,6 @@ message UpdateDatabaseDdlRequest { // [UpdateDatabaseDdl][google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabaseDdl] returns // `ALREADY_EXISTS`. string operation_id = 3; - - // Proto descriptors used by CREATE/ALTER PROTO BUNDLE statements. - // Contains a protobuf-serialized - // [google.protobuf.FileDescriptorSet](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto). - // To generate it, [install](https://grpc.io/docs/protoc-installation/) and - // run `protoc` with --include_imports and --descriptor_set_out. For example, - // to generate for moon/shot/app.proto, run - // """ - // $protoc --proto_path=/app_path --proto_path=/lib_path \ - // --include_imports \ - // --descriptor_set_out=descriptors.data \ - // moon/shot/app.proto - // """ - // For more details, see protobuffer [self - // description](https://developers.google.com/protocol-buffers/docs/techniques#self-description). - // (-- - // TODO(b/236424835) remove visibility check before launch. - // --) - // (-- api-linter: core::0134::request-unknown-fields=disabled - // aip.dev/not-precedent: This Update*Request provides an alter action - // rather than the usual entity field updating. --) - bytes proto_descriptors = 4 [(google.api.field_behavior) = OPTIONAL]; } // Action information extracted from a DDL statement. This proto is used to @@ -801,13 +762,6 @@ message GetDatabaseDdlResponse { // A list of formatted DDL statements defining the schema of the database // specified in the request. repeated string statements = 1; - - // Proto descriptors stored in the database. - // Contains a protobuf-serialized - // [google.protobuf.FileDescriptorSet](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto). - // For more details, see protobuffer [self - // description](https://developers.google.com/protocol-buffers/docs/techniques#self-description). - bytes proto_descriptors = 2; } // The request for diff --git a/proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/Type.java b/proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/Type.java index 3acefe94de2..560fd9b137e 100644 --- a/proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/Type.java +++ b/proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/Type.java @@ -41,7 +41,6 @@ private Type(com.google.protobuf.GeneratedMessageV3.Builder builder) { private Type() { code_ = 0; typeAnnotation_ = 0; - protoTypeFqn_ = ""; } @java.lang.Override @@ -247,61 +246,6 @@ public com.google.spanner.v1.TypeAnnotationCode getTypeAnnotation() { return result == null ? com.google.spanner.v1.TypeAnnotationCode.UNRECOGNIZED : result; } - public static final int PROTO_TYPE_FQN_FIELD_NUMBER = 5; - - @SuppressWarnings("serial") - private volatile java.lang.Object protoTypeFqn_ = ""; - /** - * - * - *
-   * If [code][] == [PROTO][TypeCode.PROTO] or [code][] ==
-   * [ENUM][TypeCode.ENUM], then `proto_type_fqn` is the fully qualified name of
-   * the proto type representing the proto/enum definition.
-   * 
- * - * string proto_type_fqn = 5; - * - * @return The protoTypeFqn. - */ - @java.lang.Override - public java.lang.String getProtoTypeFqn() { - java.lang.Object ref = protoTypeFqn_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - protoTypeFqn_ = s; - return s; - } - } - /** - * - * - *
-   * If [code][] == [PROTO][TypeCode.PROTO] or [code][] ==
-   * [ENUM][TypeCode.ENUM], then `proto_type_fqn` is the fully qualified name of
-   * the proto type representing the proto/enum definition.
-   * 
- * - * string proto_type_fqn = 5; - * - * @return The bytes for protoTypeFqn. - */ - @java.lang.Override - public com.google.protobuf.ByteString getProtoTypeFqnBytes() { - java.lang.Object ref = protoTypeFqn_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); - protoTypeFqn_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - private byte memoizedIsInitialized = -1; @java.lang.Override @@ -329,9 +273,6 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io != com.google.spanner.v1.TypeAnnotationCode.TYPE_ANNOTATION_CODE_UNSPECIFIED.getNumber()) { output.writeEnum(4, typeAnnotation_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(protoTypeFqn_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 5, protoTypeFqn_); - } getUnknownFields().writeTo(output); } @@ -354,9 +295,6 @@ public int getSerializedSize() { != com.google.spanner.v1.TypeAnnotationCode.TYPE_ANNOTATION_CODE_UNSPECIFIED.getNumber()) { size += com.google.protobuf.CodedOutputStream.computeEnumSize(4, typeAnnotation_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(protoTypeFqn_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(5, protoTypeFqn_); - } size += getUnknownFields().getSerializedSize(); memoizedSize = size; return size; @@ -382,7 +320,6 @@ public boolean equals(final java.lang.Object obj) { if (!getStructType().equals(other.getStructType())) return false; } if (typeAnnotation_ != other.typeAnnotation_) return false; - if (!getProtoTypeFqn().equals(other.getProtoTypeFqn())) return false; if (!getUnknownFields().equals(other.getUnknownFields())) return false; return true; } @@ -406,8 +343,6 @@ public int hashCode() { } hash = (37 * hash) + TYPE_ANNOTATION_FIELD_NUMBER; hash = (53 * hash) + typeAnnotation_; - hash = (37 * hash) + PROTO_TYPE_FQN_FIELD_NUMBER; - hash = (53 * hash) + getProtoTypeFqn().hashCode(); hash = (29 * hash) + getUnknownFields().hashCode(); memoizedHashCode = hash; return hash; @@ -557,7 +492,6 @@ public Builder clear() { structTypeBuilder_ = null; } typeAnnotation_ = 0; - protoTypeFqn_ = ""; return this; } @@ -605,9 +539,39 @@ private void buildPartial0(com.google.spanner.v1.Type result) { if (((from_bitField0_ & 0x00000008) != 0)) { result.typeAnnotation_ = typeAnnotation_; } - if (((from_bitField0_ & 0x00000010) != 0)) { - result.protoTypeFqn_ = protoTypeFqn_; - } + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.setField(field, value); + } + + @java.lang.Override + public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + + @java.lang.Override + public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.addRepeatedField(field, value); } @java.lang.Override @@ -634,11 +598,6 @@ public Builder mergeFrom(com.google.spanner.v1.Type other) { if (other.typeAnnotation_ != 0) { setTypeAnnotationValue(other.getTypeAnnotationValue()); } - if (!other.getProtoTypeFqn().isEmpty()) { - protoTypeFqn_ = other.protoTypeFqn_; - bitField0_ |= 0x00000010; - onChanged(); - } this.mergeUnknownFields(other.getUnknownFields()); onChanged(); return this; @@ -690,12 +649,6 @@ public Builder mergeFrom( bitField0_ |= 0x00000008; break; } // case 32 - case 42: - { - protoTypeFqn_ = input.readStringRequireUtf8(); - bitField0_ |= 0x00000010; - break; - } // case 42 default: { if (!super.parseUnknownField(input, extensionRegistry, tag)) { @@ -1303,122 +1256,6 @@ public Builder clearTypeAnnotation() { return this; } - private java.lang.Object protoTypeFqn_ = ""; - /** - * - * - *
-     * If [code][] == [PROTO][TypeCode.PROTO] or [code][] ==
-     * [ENUM][TypeCode.ENUM], then `proto_type_fqn` is the fully qualified name of
-     * the proto type representing the proto/enum definition.
-     * 
- * - * string proto_type_fqn = 5; - * - * @return The protoTypeFqn. - */ - public java.lang.String getProtoTypeFqn() { - java.lang.Object ref = protoTypeFqn_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - protoTypeFqn_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * - * - *
-     * If [code][] == [PROTO][TypeCode.PROTO] or [code][] ==
-     * [ENUM][TypeCode.ENUM], then `proto_type_fqn` is the fully qualified name of
-     * the proto type representing the proto/enum definition.
-     * 
- * - * string proto_type_fqn = 5; - * - * @return The bytes for protoTypeFqn. - */ - public com.google.protobuf.ByteString getProtoTypeFqnBytes() { - java.lang.Object ref = protoTypeFqn_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); - protoTypeFqn_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * - * - *
-     * If [code][] == [PROTO][TypeCode.PROTO] or [code][] ==
-     * [ENUM][TypeCode.ENUM], then `proto_type_fqn` is the fully qualified name of
-     * the proto type representing the proto/enum definition.
-     * 
- * - * string proto_type_fqn = 5; - * - * @param value The protoTypeFqn to set. - * @return This builder for chaining. - */ - public Builder setProtoTypeFqn(java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - protoTypeFqn_ = value; - bitField0_ |= 0x00000010; - onChanged(); - return this; - } - /** - * - * - *
-     * If [code][] == [PROTO][TypeCode.PROTO] or [code][] ==
-     * [ENUM][TypeCode.ENUM], then `proto_type_fqn` is the fully qualified name of
-     * the proto type representing the proto/enum definition.
-     * 
- * - * string proto_type_fqn = 5; - * - * @return This builder for chaining. - */ - public Builder clearProtoTypeFqn() { - protoTypeFqn_ = getDefaultInstance().getProtoTypeFqn(); - bitField0_ = (bitField0_ & ~0x00000010); - onChanged(); - return this; - } - /** - * - * - *
-     * If [code][] == [PROTO][TypeCode.PROTO] or [code][] ==
-     * [ENUM][TypeCode.ENUM], then `proto_type_fqn` is the fully qualified name of
-     * the proto type representing the proto/enum definition.
-     * 
- * - * string proto_type_fqn = 5; - * - * @param value The bytes for protoTypeFqn to set. - * @return This builder for chaining. - */ - public Builder setProtoTypeFqnBytes(com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - protoTypeFqn_ = value; - bitField0_ |= 0x00000010; - onChanged(); - return this; - } - @java.lang.Override public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { return super.setUnknownFields(unknownFields); diff --git a/proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/TypeCode.java b/proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/TypeCode.java index 1c23cee42ce..736f0f0ef63 100644 --- a/proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/TypeCode.java +++ b/proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/TypeCode.java @@ -181,10 +181,6 @@ public enum TypeCode implements com.google.protobuf.ProtocolMessageEnum { * JSON = 11; */ JSON(11), - /** PROTO = 13; */ - PROTO(13), - /** ENUM = 14; */ - ENUM(14), UNRECOGNIZED(-1), ; @@ -335,10 +331,6 @@ public enum TypeCode implements com.google.protobuf.ProtocolMessageEnum { * JSON = 11; */ public static final int JSON_VALUE = 11; - /** PROTO = 13; */ - public static final int PROTO_VALUE = 13; - /** ENUM = 14; */ - public static final int ENUM_VALUE = 14; public final int getNumber() { if (this == UNRECOGNIZED) { @@ -388,10 +380,6 @@ public static TypeCode forNumber(int value) { return NUMERIC; case 11: return JSON; - case 13: - return PROTO; - case 14: - return ENUM; default: return null; } diff --git a/proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/TypeOrBuilder.java b/proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/TypeOrBuilder.java index 54c7fff486f..35e645298d1 100644 --- a/proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/TypeOrBuilder.java +++ b/proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/TypeOrBuilder.java @@ -158,17 +158,4 @@ public interface TypeOrBuilder * @return The typeAnnotation. */ com.google.spanner.v1.TypeAnnotationCode getTypeAnnotation(); - - /** - * string proto_type_fqn = 5; - * - * @return The protoTypeFqn. - */ - java.lang.String getProtoTypeFqn(); - /** - * string proto_type_fqn = 5; - * - * @return The bytes for protoTypeFqn. - */ - com.google.protobuf.ByteString getProtoTypeFqnBytes(); } diff --git a/proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/TypeProto.java b/proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/TypeProto.java index c478d32bf05..4df6b4e7c63 100644 --- a/proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/TypeProto.java +++ b/proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/TypeProto.java @@ -55,23 +55,22 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { + "pe\030\002 \001(\0132\027.google.spanner.v1.Type\0222\n\013str" + "uct_type\030\003 \001(\0132\035.google.spanner.v1.Struc" + "tType\022>\n\017type_annotation\030\004 \001(\0162%.google." - + "spanner.v1.TypeAnnotationCode\022\026\n\016proto_t" - + "ype_fqn\030\005 \001(\t\"\177\n\nStructType\0223\n\006fields\030\001 " - + "\003(\0132#.google.spanner.v1.StructType.Field" - + "\032<\n\005Field\022\014\n\004name\030\001 \001(\t\022%\n\004type\030\002 \001(\0132\027." - + "google.spanner.v1.Type*\272\001\n\010TypeCode\022\031\n\025T" - + "YPE_CODE_UNSPECIFIED\020\000\022\010\n\004BOOL\020\001\022\t\n\005INT6" - + "4\020\002\022\013\n\007FLOAT64\020\003\022\r\n\tTIMESTAMP\020\004\022\010\n\004DATE\020" - + "\005\022\n\n\006STRING\020\006\022\t\n\005BYTES\020\007\022\t\n\005ARRAY\020\010\022\n\n\006S" - + "TRUCT\020\t\022\013\n\007NUMERIC\020\n\022\010\n\004JSON\020\013\022\t\n\005PROTO\020" - + "\r\022\010\n\004ENUM\020\016*X\n\022TypeAnnotationCode\022$\n TYP" - + "E_ANNOTATION_CODE_UNSPECIFIED\020\000\022\016\n\nPG_NU" - + "MERIC\020\002\022\014\n\010PG_JSONB\020\003B\254\001\n\025com.google.spa" - + "nner.v1B\tTypeProtoP\001Z5cloud.google.com/g" - + "o/spanner/apiv1/spannerpb;spannerpb\252\002\027Go" - + "ogle.Cloud.Spanner.V1\312\002\027Google\\Cloud\\Spa" - + "nner\\V1\352\002\032Google::Cloud::Spanner::V1b\006pr" - + "oto3" + + "spanner.v1.TypeAnnotationCode\"\177\n\nStructT" + + "ype\0223\n\006fields\030\001 \003(\0132#.google.spanner.v1." + + "StructType.Field\032<\n\005Field\022\014\n\004name\030\001 \001(\t\022" + + "%\n\004type\030\002 \001(\0132\027.google.spanner.v1.Type*\245" + + "\001\n\010TypeCode\022\031\n\025TYPE_CODE_UNSPECIFIED\020\000\022\010" + + "\n\004BOOL\020\001\022\t\n\005INT64\020\002\022\013\n\007FLOAT64\020\003\022\r\n\tTIME" + + "STAMP\020\004\022\010\n\004DATE\020\005\022\n\n\006STRING\020\006\022\t\n\005BYTES\020\007" + + "\022\t\n\005ARRAY\020\010\022\n\n\006STRUCT\020\t\022\013\n\007NUMERIC\020\n\022\010\n\004" + + "JSON\020\013*d\n\022TypeAnnotationCode\022$\n TYPE_ANN" + + "OTATION_CODE_UNSPECIFIED\020\000\022\016\n\nPG_NUMERIC" + + "\020\002\022\014\n\010PG_JSONB\020\003\022\n\n\006PG_OID\020\004B\254\001\n\025com.goo" + + "gle.spanner.v1B\tTypeProtoP\001Z5cloud.googl" + + "e.com/go/spanner/apiv1/spannerpb;spanner" + + "pb\252\002\027Google.Cloud.Spanner.V1\312\002\027Google\\Cl" + + "oud\\Spanner\\V1\352\002\032Google::Cloud::Spanner:" + + ":V1b\006proto3" }; descriptor = com.google.protobuf.Descriptors.FileDescriptor.internalBuildGeneratedFileFrom( @@ -84,7 +83,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_spanner_v1_Type_descriptor, new java.lang.String[] { - "Code", "ArrayElementType", "StructType", "TypeAnnotation", "ProtoTypeFqn", + "Code", "ArrayElementType", "StructType", "TypeAnnotation", }); internal_static_google_spanner_v1_StructType_descriptor = getDescriptor().getMessageTypes().get(1); diff --git a/proto-google-cloud-spanner-v1/src/main/proto/google/spanner/v1/type.proto b/proto-google-cloud-spanner-v1/src/main/proto/google/spanner/v1/type.proto index 5b7db1b74cc..412cfa12625 100644 --- a/proto-google-cloud-spanner-v1/src/main/proto/google/spanner/v1/type.proto +++ b/proto-google-cloud-spanner-v1/src/main/proto/google/spanner/v1/type.proto @@ -47,11 +47,6 @@ message Type { // typically is not needed to process the content of a value (it doesn't // affect serialization) and clients can ignore it on the read path. TypeAnnotationCode type_annotation = 4; - - // If [code][] == [PROTO][TypeCode.PROTO] or [code][] == - // [ENUM][TypeCode.ENUM], then `proto_type_fqn` is the fully qualified name of - // the proto type representing the proto/enum definition. - string proto_type_fqn = 5; } // `StructType` defines the fields of a [STRUCT][google.spanner.v1.TypeCode.STRUCT] type. @@ -150,13 +145,6 @@ enum TypeCode { // preserved. // - JSON array elements will have their order preserved. JSON = 11; - - // Encoded as a base64-encoded `string`, as described in RFC 4648, - // section 4. - PROTO = 13; - - // Encoded as `string`, in decimal format. - ENUM = 14; } // `TypeAnnotationCode` is used as a part of [Type][google.spanner.v1.Type] to From e01d0c732296dee499c0c195b4da8ece8975f705 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Wed, 24 Jan 2024 13:06:50 +0000 Subject: [PATCH 11/27] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9ed8546f7be..4ff9e58f910 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ If you are using Maven without the BOM, add this to your dependencies: If you are using Gradle 5.x or later, add this to your dependencies: ```Groovy -implementation platform('com.google.cloud:libraries-bom:26.29.0') +implementation platform('com.google.cloud:libraries-bom:26.30.0') implementation 'com.google.cloud:google-cloud-spanner' ``` From 45ad85e545d0b50beedc113e2bd2d7ce97c79451 Mon Sep 17 00:00:00 2001 From: Sri Harsha CH Date: Wed, 24 Jan 2024 13:52:56 +0000 Subject: [PATCH 12/27] feat(spanner): remove samples --- .../spanner/QueryProtoColumnSample.java | 78 - .../java/com/example/spanner/SingerProto.java | 1271 ----------------- .../spanner/UpdateProtoColumnSample.java | 83 -- 3 files changed, 1432 deletions(-) delete mode 100644 samples/snippets/src/main/java/com/example/spanner/QueryProtoColumnSample.java delete mode 100644 samples/snippets/src/main/java/com/example/spanner/SingerProto.java delete mode 100644 samples/snippets/src/main/java/com/example/spanner/UpdateProtoColumnSample.java diff --git a/samples/snippets/src/main/java/com/example/spanner/QueryProtoColumnSample.java b/samples/snippets/src/main/java/com/example/spanner/QueryProtoColumnSample.java deleted file mode 100644 index d5001cc6ddc..00000000000 --- a/samples/snippets/src/main/java/com/example/spanner/QueryProtoColumnSample.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2022 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.example.spanner; - -import com.example.spanner.SingerProto.Genre; -import com.example.spanner.SingerProto.SingerInfo; -import com.google.cloud.spanner.DatabaseClient; -import com.google.cloud.spanner.DatabaseId; -import com.google.cloud.spanner.ResultSet; -import com.google.cloud.spanner.Spanner; -import com.google.cloud.spanner.SpannerOptions; -import com.google.cloud.spanner.Statement; - -/** - * To query Proto column including messages and enums and array of them. - */ -public class QueryProtoColumnSample { - - static void queryProtoColumn() { - // TODO(developer): Replace these variables before running the sample. - String projectId = "my-project"; - String instanceId = "my-instance"; - String databaseId = "my-database"; - - try (Spanner spanner = - SpannerOptions.newBuilder().setProjectId(projectId).build().getService()) { - DatabaseClient client = - spanner.getDatabaseClient(DatabaseId.of(projectId, instanceId, databaseId)); - queryProtoColumn(client); - } - } - - /** - * Method to query Singer Table using DQL. - * - * Assuming a table Singer with columns with following DDL: - * CREATE TABLE Singer ( - * singer_id INT64 NOT NULL, - * singer_info spanner.examples.music.SingerInfo, - * genre spanner.examples.music.Genre, - * singer_info_list ARRAY, - * genre_list ARRAY, - * ) PRIMARY KEY (singer_id); - */ - static void queryProtoColumn(DatabaseClient client) { - Statement statement = - Statement.newBuilder( - "SELECT singer_id, singer_info, genre, singer_info_list, genre_list\n" - + "FROM Singer") - .build(); - - try (ResultSet resultSet = client.singleUse().executeQuery(statement)) { - while (resultSet.next()) { - System.out.printf( - "singer_id: %s, singer_info: %s , genre: %s, " - + "singer_info_list: %s, genre_list: %s%n ", - resultSet.getLong("singer_id"), - resultSet.getProtoMessage("singer_info", SingerInfo.getDefaultInstance()), - resultSet.getProtoEnum("genre", Genre::forNumber), - resultSet.getProtoMessageList("singer_info_list", SingerInfo.getDefaultInstance()), - resultSet.getProtoEnumList("genre_list", Genre::forNumber)); - } - } - } -} diff --git a/samples/snippets/src/main/java/com/example/spanner/SingerProto.java b/samples/snippets/src/main/java/com/example/spanner/SingerProto.java deleted file mode 100644 index 93f2bfaa8b8..00000000000 --- a/samples/snippets/src/main/java/com/example/spanner/SingerProto.java +++ /dev/null @@ -1,1271 +0,0 @@ -/* - * Copyright 2022 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: src/test/resources/com/google/cloud/spanner/singer.proto -package com.example.spanner; - -public final class SingerProto { - - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_spanner_examples_music_SingerInfo_descriptor; - private static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_spanner_examples_music_SingerInfo_fieldAccessorTable; - private static com.google.protobuf.Descriptors.FileDescriptor descriptor; - - static { - java.lang.String[] descriptorData = { - "\n\014singer.proto\022\026spanner.examples.music\"v" - + "\n\nSingerInfo\022\021\n\tsinger_id\030\001 \001(\003\022\022\n\nbirth" - + "_date\030\002 \001(\t\022\023\n\013nationality\030\003 \001(\t\022,\n\005genr" - + "e\030\004 \001(\0162\035.spanner.examples.music.Genre*." - + "\n\005Genre\022\007\n\003POP\020\000\022\010\n\004JAZZ\020\001\022\010\n\004FOLK\020\002\022\010\n\004" - + "ROCK\020\003B)\n\030com.example.spannerB\013Sing" - + "erProtoP\000" - }; - descriptor = - com.google.protobuf.Descriptors.FileDescriptor.internalBuildGeneratedFileFrom( - descriptorData, new com.google.protobuf.Descriptors.FileDescriptor[]{}); - internal_static_spanner_examples_music_SingerInfo_descriptor = - getDescriptor().getMessageTypes().get(0); - internal_static_spanner_examples_music_SingerInfo_fieldAccessorTable = - new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_spanner_examples_music_SingerInfo_descriptor, - new java.lang.String[]{ - "SingerId", "BirthDate", "Nationality", "Genre", - }); - } - - private SingerProto() { - } - - public static void registerAllExtensions(com.google.protobuf.ExtensionRegistryLite registry) { - } - - public static void registerAllExtensions(com.google.protobuf.ExtensionRegistry registry) { - registerAllExtensions((com.google.protobuf.ExtensionRegistryLite) registry); - } - - public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { - return descriptor; - } - - /** - * Protobuf enum {@code spanner.examples.music.Genre} - */ - public enum Genre implements com.google.protobuf.ProtocolMessageEnum { - /** - * POP = 0; - */ - POP(0), - /** - * JAZZ = 1; - */ - JAZZ(1), - /** - * FOLK = 2; - */ - FOLK(2), - /** - * ROCK = 3; - */ - ROCK(3), - ; - - /** - * POP = 0; - */ - public static final int POP_VALUE = 0; - /** - * JAZZ = 1; - */ - public static final int JAZZ_VALUE = 1; - /** - * FOLK = 2; - */ - public static final int FOLK_VALUE = 2; - /** - * ROCK = 3; - */ - public static final int ROCK_VALUE = 3; - private static final com.google.protobuf.Internal.EnumLiteMap internalValueMap = - new com.google.protobuf.Internal.EnumLiteMap() { - public Genre findValueByNumber(int number) { - return Genre.forNumber(number); - } - }; - private static final Genre[] VALUES = values(); - private final int value; - - private Genre(int value) { - this.value = value; - } - - /** - * @param value The numeric wire value of the corresponding enum entry. - * @return The enum associated with the given numeric wire value. - * @deprecated Use {@link #forNumber(int)} instead. - */ - @java.lang.Deprecated - public static Genre valueOf(int value) { - return forNumber(value); - } - - /** - * @param value The numeric wire value of the corresponding enum entry. - * @return The enum associated with the given numeric wire value. - */ - public static Genre forNumber(int value) { - switch (value) { - case 0: - return POP; - case 1: - return JAZZ; - case 2: - return FOLK; - case 3: - return ROCK; - default: - return null; - } - } - - public static com.google.protobuf.Internal.EnumLiteMap internalGetValueMap() { - return internalValueMap; - } - - public static final com.google.protobuf.Descriptors.EnumDescriptor getDescriptor() { - return com.example.spanner.SingerProto.getDescriptor().getEnumTypes().get(0); - } - - public static Genre valueOf(com.google.protobuf.Descriptors.EnumValueDescriptor desc) { - if (desc.getType() != getDescriptor()) { - throw new java.lang.IllegalArgumentException("EnumValueDescriptor is not for this type."); - } - return VALUES[desc.getIndex()]; - } - - public final int getNumber() { - return value; - } - - public final com.google.protobuf.Descriptors.EnumValueDescriptor getValueDescriptor() { - return getDescriptor().getValues().get(ordinal()); - } - - public final com.google.protobuf.Descriptors.EnumDescriptor getDescriptorForType() { - return getDescriptor(); - } - - // @@protoc_insertion_point(enum_scope:spanner.examples.music.Genre) - } - - public interface SingerInfoOrBuilder - extends - // @@protoc_insertion_point(interface_extends:spanner.examples.music.SingerInfo) - com.google.protobuf.MessageOrBuilder { - - /** - * optional int64 singer_id = 1; - * - * @return Whether the singerId field is set. - */ - boolean hasSingerId(); - - /** - * optional int64 singer_id = 1; - * - * @return The singerId. - */ - long getSingerId(); - - /** - * optional string birth_date = 2; - * - * @return Whether the birthDate field is set. - */ - boolean hasBirthDate(); - - /** - * optional string birth_date = 2; - * - * @return The birthDate. - */ - java.lang.String getBirthDate(); - - /** - * optional string birth_date = 2; - * - * @return The bytes for birthDate. - */ - com.google.protobuf.ByteString getBirthDateBytes(); - - /** - * optional string nationality = 3; - * - * @return Whether the nationality field is set. - */ - boolean hasNationality(); - - /** - * optional string nationality = 3; - * - * @return The nationality. - */ - java.lang.String getNationality(); - - /** - * optional string nationality = 3; - * - * @return The bytes for nationality. - */ - com.google.protobuf.ByteString getNationalityBytes(); - - /** - * optional .spanner.examples.music.Genre genre = 4; - * - * @return Whether the genre field is set. - */ - boolean hasGenre(); - - /** - * optional .spanner.examples.music.Genre genre = 4; - * - * @return The genre. - */ - com.example.spanner.SingerProto.Genre getGenre(); - } - - /** - * Protobuf type {@code spanner.examples.music.SingerInfo} - */ - public static final class SingerInfo extends com.google.protobuf.GeneratedMessageV3 - implements - // @@protoc_insertion_point(message_implements:spanner.examples.music.SingerInfo) - SingerInfoOrBuilder { - - public static final int SINGER_ID_FIELD_NUMBER = 1; - public static final int BIRTH_DATE_FIELD_NUMBER = 2; - public static final int NATIONALITY_FIELD_NUMBER = 3; - public static final int GENRE_FIELD_NUMBER = 4; - @java.lang.Deprecated - public static final com.google.protobuf.Parser PARSER = - new com.google.protobuf.AbstractParser() { - @java.lang.Override - public SingerInfo parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new SingerInfo(input, extensionRegistry); - } - }; - private static final long serialVersionUID = 0L; - // @@protoc_insertion_point(class_scope:spanner.examples.music.SingerInfo) - private static final com.example.spanner.SingerProto.SingerInfo DEFAULT_INSTANCE; - - static { - DEFAULT_INSTANCE = new com.example.spanner.SingerProto.SingerInfo(); - } - - private int bitField0_; - private long singerId_; - private volatile java.lang.Object birthDate_; - private volatile java.lang.Object nationality_; - private int genre_; - private byte memoizedIsInitialized = -1; - // Use SingerInfo.newBuilder() to construct. - private SingerInfo(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - - private SingerInfo() { - birthDate_ = ""; - nationality_ = ""; - genre_ = 0; - } - - private SingerInfo( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - case 8: { - bitField0_ |= 0x00000001; - singerId_ = input.readInt64(); - break; - } - case 18: { - com.google.protobuf.ByteString bs = input.readBytes(); - bitField0_ |= 0x00000002; - birthDate_ = bs; - break; - } - case 26: { - com.google.protobuf.ByteString bs = input.readBytes(); - bitField0_ |= 0x00000004; - nationality_ = bs; - break; - } - case 32: { - int rawValue = input.readEnum(); - @SuppressWarnings("deprecation") - com.example.spanner.SingerProto.Genre value = - com.example.spanner.SingerProto.Genre.valueOf(rawValue); - if (value == null) { - unknownFields.mergeVarintField(4, rawValue); - } else { - bitField0_ |= 0x00000008; - genre_ = rawValue; - } - break; - } - default: { - if (!parseUnknownField(input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException(e).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - - public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { - return com.example.spanner.SingerProto - .internal_static_spanner_examples_music_SingerInfo_descriptor; - } - - public static com.example.spanner.SingerProto.SingerInfo parseFrom(java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - - public static com.example.spanner.SingerProto.SingerInfo parseFrom( - java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - - public static com.example.spanner.SingerProto.SingerInfo parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - - public static com.example.spanner.SingerProto.SingerInfo parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - - public static com.example.spanner.SingerProto.SingerInfo parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - - public static com.example.spanner.SingerProto.SingerInfo parseFrom( - byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - - public static com.example.spanner.SingerProto.SingerInfo parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); - } - - public static com.example.spanner.SingerProto.SingerInfo parseFrom( - java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3.parseWithIOException( - PARSER, input, extensionRegistry); - } - - public static com.example.spanner.SingerProto.SingerInfo parseDelimitedFrom( - java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); - } - - public static com.example.spanner.SingerProto.SingerInfo parseDelimitedFrom( - java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException( - PARSER, input, extensionRegistry); - } - - public static com.example.spanner.SingerProto.SingerInfo parseFrom( - com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); - } - - public static com.example.spanner.SingerProto.SingerInfo parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3.parseWithIOException( - PARSER, input, extensionRegistry); - } - - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - - public static Builder newBuilder(com.example.spanner.SingerProto.SingerInfo prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - - public static com.example.spanner.SingerProto.SingerInfo getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - @SuppressWarnings({"unused"}) - protected java.lang.Object newInstance(UnusedPrivateParameter unused) { - return new SingerInfo(); - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet getUnknownFields() { - return this.unknownFields; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return com.example.spanner.SingerProto - .internal_static_spanner_examples_music_SingerInfo_fieldAccessorTable - .ensureFieldAccessorsInitialized( - com.example.spanner.SingerProto.SingerInfo.class, - com.example.spanner.SingerProto.SingerInfo.Builder.class); - } - - /** - * optional int64 singer_id = 1; - * - * @return Whether the singerId field is set. - */ - @java.lang.Override - public boolean hasSingerId() { - return ((bitField0_ & 0x00000001) != 0); - } - - /** - * optional int64 singer_id = 1; - * - * @return The singerId. - */ - @java.lang.Override - public long getSingerId() { - return singerId_; - } - - /** - * optional string birth_date = 2; - * - * @return Whether the birthDate field is set. - */ - @java.lang.Override - public boolean hasBirthDate() { - return ((bitField0_ & 0x00000002) != 0); - } - - /** - * optional string birth_date = 2; - * - * @return The birthDate. - */ - @java.lang.Override - public java.lang.String getBirthDate() { - java.lang.Object ref = birthDate_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - if (bs.isValidUtf8()) { - birthDate_ = s; - } - return s; - } - } - - /** - * optional string birth_date = 2; - * - * @return The bytes for birthDate. - */ - @java.lang.Override - public com.google.protobuf.ByteString getBirthDateBytes() { - java.lang.Object ref = birthDate_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); - birthDate_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - /** - * optional string nationality = 3; - * - * @return Whether the nationality field is set. - */ - @java.lang.Override - public boolean hasNationality() { - return ((bitField0_ & 0x00000004) != 0); - } - - /** - * optional string nationality = 3; - * - * @return The nationality. - */ - @java.lang.Override - public java.lang.String getNationality() { - java.lang.Object ref = nationality_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - if (bs.isValidUtf8()) { - nationality_ = s; - } - return s; - } - } - - /** - * optional string nationality = 3; - * - * @return The bytes for nationality. - */ - @java.lang.Override - public com.google.protobuf.ByteString getNationalityBytes() { - java.lang.Object ref = nationality_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); - nationality_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - /** - * optional .spanner.examples.music.Genre genre = 4; - * - * @return Whether the genre field is set. - */ - @java.lang.Override - public boolean hasGenre() { - return ((bitField0_ & 0x00000008) != 0); - } - - /** - * optional .spanner.examples.music.Genre genre = 4; - * - * @return The genre. - */ - @java.lang.Override - public com.example.spanner.SingerProto.Genre getGenre() { - @SuppressWarnings("deprecation") - com.example.spanner.SingerProto.Genre result = - com.example.spanner.SingerProto.Genre.valueOf(genre_); - return result == null ? com.example.spanner.SingerProto.Genre.POP : result; - } - - @java.lang.Override - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) { - return true; - } - if (isInitialized == 0) { - return false; - } - - memoizedIsInitialized = 1; - return true; - } - - @java.lang.Override - public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - if (((bitField0_ & 0x00000001) != 0)) { - output.writeInt64(1, singerId_); - } - if (((bitField0_ & 0x00000002) != 0)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 2, birthDate_); - } - if (((bitField0_ & 0x00000004) != 0)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 3, nationality_); - } - if (((bitField0_ & 0x00000008) != 0)) { - output.writeEnum(4, genre_); - } - unknownFields.writeTo(output); - } - - @java.lang.Override - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) { - return size; - } - - size = 0; - if (((bitField0_ & 0x00000001) != 0)) { - size += com.google.protobuf.CodedOutputStream.computeInt64Size(1, singerId_); - } - if (((bitField0_ & 0x00000002) != 0)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, birthDate_); - } - if (((bitField0_ & 0x00000004) != 0)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, nationality_); - } - if (((bitField0_ & 0x00000008) != 0)) { - size += com.google.protobuf.CodedOutputStream.computeEnumSize(4, genre_); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof com.example.spanner.SingerProto.SingerInfo)) { - return super.equals(obj); - } - com.example.spanner.SingerProto.SingerInfo other = - (com.example.spanner.SingerProto.SingerInfo) obj; - - if (hasSingerId() != other.hasSingerId()) { - return false; - } - if (hasSingerId()) { - if (getSingerId() != other.getSingerId()) { - return false; - } - } - if (hasBirthDate() != other.hasBirthDate()) { - return false; - } - if (hasBirthDate()) { - if (!getBirthDate().equals(other.getBirthDate())) { - return false; - } - } - if (hasNationality() != other.hasNationality()) { - return false; - } - if (hasNationality()) { - if (!getNationality().equals(other.getNationality())) { - return false; - } - } - if (hasGenre() != other.hasGenre()) { - return false; - } - if (hasGenre()) { - if (genre_ != other.genre_) { - return false; - } - } - if (!unknownFields.equals(other.unknownFields)) { - return false; - } - return true; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - if (hasSingerId()) { - hash = (37 * hash) + SINGER_ID_FIELD_NUMBER; - hash = (53 * hash) + com.google.protobuf.Internal.hashLong(getSingerId()); - } - if (hasBirthDate()) { - hash = (37 * hash) + BIRTH_DATE_FIELD_NUMBER; - hash = (53 * hash) + getBirthDate().hashCode(); - } - if (hasNationality()) { - hash = (37 * hash) + NATIONALITY_FIELD_NUMBER; - hash = (53 * hash) + getNationality().hashCode(); - } - if (hasGenre()) { - hash = (37 * hash) + GENRE_FIELD_NUMBER; - hash = (53 * hash) + genre_; - } - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - @java.lang.Override - public Builder newBuilderForType() { - return newBuilder(); - } - - @java.lang.Override - public Builder toBuilder() { - return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - @java.lang.Override - public com.example.spanner.SingerProto.SingerInfo getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - /** - * Protobuf type {@code spanner.examples.music.SingerInfo} - */ - public static final class Builder - extends com.google.protobuf.GeneratedMessageV3.Builder - implements - // @@protoc_insertion_point(builder_implements:spanner.examples.music.SingerInfo) - com.example.spanner.SingerProto.SingerInfoOrBuilder { - - private int bitField0_; - private long singerId_; - private java.lang.Object birthDate_ = ""; - private java.lang.Object nationality_ = ""; - private int genre_ = 0; - - // Construct using com.example.spanner.SingerProto.SingerInfo.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - - public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { - return com.example.spanner.SingerProto - .internal_static_spanner_examples_music_SingerInfo_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return com.example.spanner.SingerProto - .internal_static_spanner_examples_music_SingerInfo_fieldAccessorTable - .ensureFieldAccessorsInitialized( - com.example.spanner.SingerProto.SingerInfo.class, - com.example.spanner.SingerProto.SingerInfo.Builder.class); - } - - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders) { - } - } - - @java.lang.Override - public Builder clear() { - super.clear(); - singerId_ = 0L; - bitField0_ = (bitField0_ & ~0x00000001); - birthDate_ = ""; - bitField0_ = (bitField0_ & ~0x00000002); - nationality_ = ""; - bitField0_ = (bitField0_ & ~0x00000004); - genre_ = 0; - bitField0_ = (bitField0_ & ~0x00000008); - return this; - } - - @java.lang.Override - public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { - return com.example.spanner.SingerProto - .internal_static_spanner_examples_music_SingerInfo_descriptor; - } - - @java.lang.Override - public com.example.spanner.SingerProto.SingerInfo getDefaultInstanceForType() { - return com.example.spanner.SingerProto.SingerInfo.getDefaultInstance(); - } - - @java.lang.Override - public com.example.spanner.SingerProto.SingerInfo build() { - com.example.spanner.SingerProto.SingerInfo result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - @java.lang.Override - public com.example.spanner.SingerProto.SingerInfo buildPartial() { - com.example.spanner.SingerProto.SingerInfo result = - new com.example.spanner.SingerProto.SingerInfo(this); - int from_bitField0_ = bitField0_; - int to_bitField0_ = 0; - if (((from_bitField0_ & 0x00000001) != 0)) { - result.singerId_ = singerId_; - to_bitField0_ |= 0x00000001; - } - if (((from_bitField0_ & 0x00000002) != 0)) { - to_bitField0_ |= 0x00000002; - } - result.birthDate_ = birthDate_; - if (((from_bitField0_ & 0x00000004) != 0)) { - to_bitField0_ |= 0x00000004; - } - result.nationality_ = nationality_; - if (((from_bitField0_ & 0x00000008) != 0)) { - to_bitField0_ |= 0x00000008; - } - result.genre_ = genre_; - result.bitField0_ = to_bitField0_; - onBuilt(); - return result; - } - - @java.lang.Override - public Builder clone() { - return super.clone(); - } - - @java.lang.Override - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { - return super.setField(field, value); - } - - @java.lang.Override - public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { - return super.clearField(field); - } - - @java.lang.Override - public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return super.clearOneof(oneof); - } - - @java.lang.Override - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, - java.lang.Object value) { - return super.setRepeatedField(field, index, value); - } - - @java.lang.Override - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { - return super.addRepeatedField(field, value); - } - - @java.lang.Override - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof com.example.spanner.SingerProto.SingerInfo) { - return mergeFrom((com.example.spanner.SingerProto.SingerInfo) other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(com.example.spanner.SingerProto.SingerInfo other) { - if (other == com.example.spanner.SingerProto.SingerInfo.getDefaultInstance()) { - return this; - } - if (other.hasSingerId()) { - setSingerId(other.getSingerId()); - } - if (other.hasBirthDate()) { - bitField0_ |= 0x00000002; - birthDate_ = other.birthDate_; - onChanged(); - } - if (other.hasNationality()) { - bitField0_ |= 0x00000004; - nationality_ = other.nationality_; - onChanged(); - } - if (other.hasGenre()) { - setGenre(other.getGenre()); - } - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - @java.lang.Override - public final boolean isInitialized() { - return true; - } - - @java.lang.Override - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - com.example.spanner.SingerProto.SingerInfo parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (com.example.spanner.SingerProto.SingerInfo) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - - /** - * optional int64 singer_id = 1; - * - * @return Whether the singerId field is set. - */ - @java.lang.Override - public boolean hasSingerId() { - return ((bitField0_ & 0x00000001) != 0); - } - - /** - * optional int64 singer_id = 1; - * - * @return The singerId. - */ - @java.lang.Override - public long getSingerId() { - return singerId_; - } - - /** - * optional int64 singer_id = 1; - * - * @param value The singerId to set. - * @return This builder for chaining. - */ - public Builder setSingerId(long value) { - bitField0_ |= 0x00000001; - singerId_ = value; - onChanged(); - return this; - } - - /** - * optional int64 singer_id = 1; - * - * @return This builder for chaining. - */ - public Builder clearSingerId() { - bitField0_ = (bitField0_ & ~0x00000001); - singerId_ = 0L; - onChanged(); - return this; - } - - /** - * optional string birth_date = 2; - * - * @return Whether the birthDate field is set. - */ - public boolean hasBirthDate() { - return ((bitField0_ & 0x00000002) != 0); - } - - /** - * optional string birth_date = 2; - * - * @return The birthDate. - */ - public java.lang.String getBirthDate() { - java.lang.Object ref = birthDate_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - if (bs.isValidUtf8()) { - birthDate_ = s; - } - return s; - } else { - return (java.lang.String) ref; - } - } - - /** - * optional string birth_date = 2; - * - * @param value The birthDate to set. - * @return This builder for chaining. - */ - public Builder setBirthDate(java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - bitField0_ |= 0x00000002; - birthDate_ = value; - onChanged(); - return this; - } - - /** - * optional string birth_date = 2; - * - * @return The bytes for birthDate. - */ - public com.google.protobuf.ByteString getBirthDateBytes() { - java.lang.Object ref = birthDate_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); - birthDate_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - /** - * optional string birth_date = 2; - * - * @param value The bytes for birthDate to set. - * @return This builder for chaining. - */ - public Builder setBirthDateBytes(com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - bitField0_ |= 0x00000002; - birthDate_ = value; - onChanged(); - return this; - } - - /** - * optional string birth_date = 2; - * - * @return This builder for chaining. - */ - public Builder clearBirthDate() { - bitField0_ = (bitField0_ & ~0x00000002); - birthDate_ = getDefaultInstance().getBirthDate(); - onChanged(); - return this; - } - - /** - * optional string nationality = 3; - * - * @return Whether the nationality field is set. - */ - public boolean hasNationality() { - return ((bitField0_ & 0x00000004) != 0); - } - - /** - * optional string nationality = 3; - * - * @return The nationality. - */ - public java.lang.String getNationality() { - java.lang.Object ref = nationality_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - if (bs.isValidUtf8()) { - nationality_ = s; - } - return s; - } else { - return (java.lang.String) ref; - } - } - - /** - * optional string nationality = 3; - * - * @param value The nationality to set. - * @return This builder for chaining. - */ - public Builder setNationality(java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - bitField0_ |= 0x00000004; - nationality_ = value; - onChanged(); - return this; - } - - /** - * optional string nationality = 3; - * - * @return The bytes for nationality. - */ - public com.google.protobuf.ByteString getNationalityBytes() { - java.lang.Object ref = nationality_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); - nationality_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - /** - * optional string nationality = 3; - * - * @param value The bytes for nationality to set. - * @return This builder for chaining. - */ - public Builder setNationalityBytes(com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - bitField0_ |= 0x00000004; - nationality_ = value; - onChanged(); - return this; - } - - /** - * optional string nationality = 3; - * - * @return This builder for chaining. - */ - public Builder clearNationality() { - bitField0_ = (bitField0_ & ~0x00000004); - nationality_ = getDefaultInstance().getNationality(); - onChanged(); - return this; - } - - /** - * optional .spanner.examples.music.Genre genre = 4; - * - * @return Whether the genre field is set. - */ - @java.lang.Override - public boolean hasGenre() { - return ((bitField0_ & 0x00000008) != 0); - } - - /** - * optional .spanner.examples.music.Genre genre = 4; - * - * @return The genre. - */ - @java.lang.Override - public com.example.spanner.SingerProto.Genre getGenre() { - @SuppressWarnings("deprecation") - com.example.spanner.SingerProto.Genre result = - com.example.spanner.SingerProto.Genre.valueOf(genre_); - return result == null ? com.example.spanner.SingerProto.Genre.POP : result; - } - - /** - * optional .spanner.examples.music.Genre genre = 4; - * - * @param value The genre to set. - * @return This builder for chaining. - */ - public Builder setGenre(com.example.spanner.SingerProto.Genre value) { - if (value == null) { - throw new NullPointerException(); - } - bitField0_ |= 0x00000008; - genre_ = value.getNumber(); - onChanged(); - return this; - } - - /** - * optional .spanner.examples.music.Genre genre = 4; - * - * @return This builder for chaining. - */ - public Builder clearGenre() { - bitField0_ = (bitField0_ & ~0x00000008); - genre_ = 0; - onChanged(); - return this; - } - - @java.lang.Override - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFields(unknownFields); - } - - @java.lang.Override - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - // @@protoc_insertion_point(builder_scope:spanner.examples.music.SingerInfo) - } - } - - // @@protoc_insertion_point(outer_class_scope) -} diff --git a/samples/snippets/src/main/java/com/example/spanner/UpdateProtoColumnSample.java b/samples/snippets/src/main/java/com/example/spanner/UpdateProtoColumnSample.java deleted file mode 100644 index e2c97264575..00000000000 --- a/samples/snippets/src/main/java/com/example/spanner/UpdateProtoColumnSample.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2022 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.example.spanner; - -import com.example.spanner.SingerProto.Genre; -import com.example.spanner.SingerProto.SingerInfo; -import com.google.cloud.spanner.DatabaseClient; -import com.google.cloud.spanner.DatabaseId; -import com.google.cloud.spanner.Mutation; -import com.google.cloud.spanner.Spanner; -import com.google.cloud.spanner.SpannerOptions; -import com.google.common.collect.ImmutableList; -import java.util.Arrays; - -/** - * To insert data into Proto column including messages and enums and array of them. - */ -public class UpdateProtoColumnSample { - - static void updateProtoData() { - // TODO(developer): Replace these variables before running the sample. - String projectId = "my-project"; - String instanceId = "my-instance"; - String databaseId = "my-database"; - - try (Spanner spanner = - SpannerOptions.newBuilder().setProjectId(projectId).build().getService()) { - DatabaseClient client = - spanner.getDatabaseClient(DatabaseId.of(projectId, instanceId, databaseId)); - updateProtoData(client); - } - } - - /** - * Method to update Singer Table using mutations. - * - * Assuming a table Singer with columns with following DDL: - * CREATE TABLE Singer ( - * singer_id INT64 NOT NULL, - * singer_info spanner.examples.music.SingerInfo, - * genre spanner.examples.music.Genre, - * singer_info_list ARRAY, - * genre_list ARRAY, - * ) PRIMARY KEY (singer_id); - */ - static void updateProtoData(DatabaseClient client) { - SingerInfo singerInfo = - SingerInfo.newBuilder().setSingerId(11).setNationality("Country1").build(); - - client.write( - ImmutableList.of( - Mutation.newInsertOrUpdateBuilder("Singer") - .set("singer_id") - .to(32) - .set("singer_info") - .to(singerInfo) - .set("genre") - .to(Genre.JAZZ) - .set("singer_info_list") - .toProtoMessageArray( - Arrays.asList(singerInfo, null, SingerInfo.getDefaultInstance()), - SingerInfo.getDescriptor()) - .set("genre_list") - .toProtoEnumArray( - Arrays.asList(Genre.FOLK, null, Genre.ROCK), Genre.getDescriptor()) - .build())); - - System.out.println("Singer data successfully updated"); - } -} From ab35680854fe9557647700ec6efbed68efc84a5b Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Wed, 24 Jan 2024 14:10:47 +0000 Subject: [PATCH 13/27] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index 00e28775e7d..4784fc5caeb 100644 --- a/README.md +++ b/README.md @@ -313,14 +313,12 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-spanner/tree/ | Pg Spanner Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/PgSpannerSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/PgSpannerSample.java) | | Pg Update Using Dml Returning Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/PgUpdateUsingDmlReturningSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/PgUpdateUsingDmlReturningSample.java) | | Query Information Schema Database Options Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/QueryInformationSchemaDatabaseOptionsSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/QueryInformationSchemaDatabaseOptionsSample.java) | -| Query Proto Column Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/QueryProtoColumnSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/QueryProtoColumnSample.java) | | Query With Json Parameter Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/QueryWithJsonParameterSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/QueryWithJsonParameterSample.java) | | Query With Jsonb Parameter Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/QueryWithJsonbParameterSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/QueryWithJsonbParameterSample.java) | | Query With Numeric Parameter Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/QueryWithNumericParameterSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/QueryWithNumericParameterSample.java) | | Quickstart Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/QuickstartSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/QuickstartSample.java) | | Read Data With Database Role | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/ReadDataWithDatabaseRole.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/ReadDataWithDatabaseRole.java) | | Restore Backup With Encryption Key | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/RestoreBackupWithEncryptionKey.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/RestoreBackupWithEncryptionKey.java) | -| Singer Proto | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/SingerProto.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/SingerProto.java) | | Spanner Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/SpannerSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/SpannerSample.java) | | Statement Timeout Example | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/StatementTimeoutExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/StatementTimeoutExample.java) | | Tag Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/TagSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/TagSample.java) | @@ -332,7 +330,6 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-spanner/tree/ | Update Json Data Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/UpdateJsonDataSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/UpdateJsonDataSample.java) | | Update Jsonb Data Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/UpdateJsonbDataSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/UpdateJsonbDataSample.java) | | Update Numeric Data Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/UpdateNumericDataSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/UpdateNumericDataSample.java) | -| Update Proto Column Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/UpdateProtoColumnSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/UpdateProtoColumnSample.java) | | Update Using Dml Returning Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/UpdateUsingDmlReturningSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/UpdateUsingDmlReturningSample.java) | | Create Database With Default Leader Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/admin/generated/CreateDatabaseWithDefaultLeaderSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/admin/generated/CreateDatabaseWithDefaultLeaderSample.java) | | Create Instance Config Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/admin/generated/CreateInstanceConfigSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/admin/generated/CreateInstanceConfigSample.java) | From d7fbc09b342cf9ede04c1c6eb497160de047f603 Mon Sep 17 00:00:00 2001 From: Sri Harsha CH Date: Wed, 24 Jan 2024 15:12:36 +0000 Subject: [PATCH 14/27] feat(spanner): remove clirr --- google-cloud-spanner/clirr-ignored-differences.xml | 6 ------ .../java/com/google/cloud/spanner/it/ITProtoColumnTest.java | 2 ++ 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/google-cloud-spanner/clirr-ignored-differences.xml b/google-cloud-spanner/clirr-ignored-differences.xml index c8608c32e03..9b631dee18d 100644 --- a/google-cloud-spanner/clirr-ignored-differences.xml +++ b/google-cloud-spanner/clirr-ignored-differences.xml @@ -331,12 +331,6 @@ com/google/cloud/spanner/spi/v1/GapicSpannerRpc com.google.cloud.spanner.spi.v1.SpannerRpc$StreamingCall read(com.google.spanner.v1.ReadRequest, com.google.cloud.spanner.spi.v1.SpannerRpc$ResultStreamConsumer, java.util.Map)
- - 7005 - com/google/cloud/spanner/spi/v1/GapicSpannerRpc - com.google.api.gax.longrunning.OperationFuture updateDatabaseDdl(java.lang.String, java.lang.Iterable, java.lang.String) - com.google.api.gax.longrunning.OperationFuture updateDatabaseDdl(com.google.cloud.spanner.Database, java.lang.Iterable, java.lang.String) - 7005 com/google/cloud/spanner/spi/v1/GapicSpannerRpc diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITProtoColumnTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITProtoColumnTest.java index cbe00c1db4d..2178285528e 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITProtoColumnTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITProtoColumnTest.java @@ -69,6 +69,8 @@ public class ITProtoColumnTest { @BeforeClass public static void setUpDatabase() throws Exception { + assumeFalse( + "Proto Column is not supported in the emulator", EmulatorSpannerHelper.isUsingEmulator()); RemoteSpannerHelper testHelper = env.getTestHelper(); databaseID = DatabaseId.of(testHelper.getInstanceId(), testHelper.getUniqueDatabaseId()); dbAdminClient = testHelper.getClient().getDatabaseAdminClient(); From 2de342fe85ff9877a53ccf1a1c35ed5902f1280a Mon Sep 17 00:00:00 2001 From: Sri Harsha CH Date: Wed, 24 Jan 2024 15:37:21 +0000 Subject: [PATCH 15/27] feat(spanner): skip emulator test --- .../java/com/google/cloud/spanner/it/ITProtoColumnTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITProtoColumnTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITProtoColumnTest.java index 2178285528e..0ae78c3fe27 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITProtoColumnTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITProtoColumnTest.java @@ -129,6 +129,8 @@ public static void createDatabase() throws Exception { @AfterClass public static void afterClass() throws Exception { + assumeFalse( + "Proto Column is not supported in the emulator", EmulatorSpannerHelper.isUsingEmulator()); try { dbAdminClient.dropDatabase( databaseID.getInstanceId().getInstance(), databaseID.getDatabase()); From d18c28e1f5644ea50a878fa4bbcf3ecf6e69af48 Mon Sep 17 00:00:00 2001 From: Sri Harsha CH Date: Wed, 24 Jan 2024 16:44:23 +0000 Subject: [PATCH 16/27] feat(spanner): clirr --- google-cloud-spanner/clirr-ignored-differences.xml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/google-cloud-spanner/clirr-ignored-differences.xml b/google-cloud-spanner/clirr-ignored-differences.xml index 9b631dee18d..e1b39583966 100644 --- a/google-cloud-spanner/clirr-ignored-differences.xml +++ b/google-cloud-spanner/clirr-ignored-differences.xml @@ -331,6 +331,12 @@ com/google/cloud/spanner/spi/v1/GapicSpannerRpc com.google.cloud.spanner.spi.v1.SpannerRpc$StreamingCall read(com.google.spanner.v1.ReadRequest, com.google.cloud.spanner.spi.v1.SpannerRpc$ResultStreamConsumer, java.util.Map) + + 7005 + com/google/cloud/spanner/spi/v1/GapicSpannerRpc + public com.google.api.gax.longrunning.OperationFuture updateDatabaseDdl(java.lang.String, java.lang.Iterable, java.lang.String) + com.google.api.gax.longrunning.OperationFuture updateDatabaseDdl(com.google.cloud.spanner.Database, java.lang.Iterable, java.lang.String) + 7005 com/google/cloud/spanner/spi/v1/GapicSpannerRpc @@ -384,7 +390,7 @@ 7005 com/google/cloud/spanner/spi/v1/SpannerRpc - com.google.api.gax.longrunning.OperationFuture updateDatabaseDdl(java.lang.String, java.lang.Iterable, java.lang.String) + public com.google.api.gax.longrunning.OperationFuture updateDatabaseDdl(java.lang.String, java.lang.Iterable, java.lang.String) com.google.api.gax.longrunning.OperationFuture updateDatabaseDdl(com.google.cloud.spanner.Database, java.lang.Iterable, java.lang.String) From 3e46cd997db8310371c942cacab389235f6bd0d1 Mon Sep 17 00:00:00 2001 From: Sri Harsha CH Date: Wed, 24 Jan 2024 17:36:36 +0000 Subject: [PATCH 17/27] feat(spanner): fix javadoc --- google-cloud-spanner/clirr-ignored-differences.xml | 4 ++-- .../java/com/google/cloud/spanner/DatabaseAdminClient.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-spanner/clirr-ignored-differences.xml b/google-cloud-spanner/clirr-ignored-differences.xml index e1b39583966..c8608c32e03 100644 --- a/google-cloud-spanner/clirr-ignored-differences.xml +++ b/google-cloud-spanner/clirr-ignored-differences.xml @@ -334,7 +334,7 @@ 7005 com/google/cloud/spanner/spi/v1/GapicSpannerRpc - public com.google.api.gax.longrunning.OperationFuture updateDatabaseDdl(java.lang.String, java.lang.Iterable, java.lang.String) + com.google.api.gax.longrunning.OperationFuture updateDatabaseDdl(java.lang.String, java.lang.Iterable, java.lang.String) com.google.api.gax.longrunning.OperationFuture updateDatabaseDdl(com.google.cloud.spanner.Database, java.lang.Iterable, java.lang.String) @@ -390,7 +390,7 @@ 7005 com/google/cloud/spanner/spi/v1/SpannerRpc - public com.google.api.gax.longrunning.OperationFuture updateDatabaseDdl(java.lang.String, java.lang.Iterable, java.lang.String) + com.google.api.gax.longrunning.OperationFuture updateDatabaseDdl(java.lang.String, java.lang.Iterable, java.lang.String) com.google.api.gax.longrunning.OperationFuture updateDatabaseDdl(com.google.cloud.spanner.Database, java.lang.Iterable, java.lang.String) diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseAdminClient.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseAdminClient.java index 9f1fd79f0f6..69420f080da 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseAdminClient.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseAdminClient.java @@ -453,7 +453,7 @@ OperationFuture updateDatabaseDdl( /** * Updates a database in a Cloud Spanner instance. Any proto descriptors that have been set for - * the {@link Database} instance will be included in the {@link UpdateDatabaseDdlRequest}. + * the {@link com.google.cloud.spanner.Database} instance will be included in the {@link UpdateDatabaseDdlRequest}. * *

If an operation already exists with the given operation id, the operation will be resumed * and the returned future will complete when the original operation finishes. See more From ee333a3be2620d0cab19a28d45d5ccc3f656ccf3 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Wed, 24 Jan 2024 17:39:40 +0000 Subject: [PATCH 18/27] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- .../java/com/google/cloud/spanner/DatabaseAdminClient.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseAdminClient.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseAdminClient.java index 69420f080da..77314e2bba5 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseAdminClient.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseAdminClient.java @@ -453,7 +453,8 @@ OperationFuture updateDatabaseDdl( /** * Updates a database in a Cloud Spanner instance. Any proto descriptors that have been set for - * the {@link com.google.cloud.spanner.Database} instance will be included in the {@link UpdateDatabaseDdlRequest}. + * the {@link com.google.cloud.spanner.Database} instance will be included in the {@link + * UpdateDatabaseDdlRequest}. * *

If an operation already exists with the given operation id, the operation will be resumed * and the returned future will complete when the original operation finishes. See more From e1051016e8afac8c9bc7aae78973cdc42d1aacbb Mon Sep 17 00:00:00 2001 From: Sri Harsha CH Date: Wed, 24 Jan 2024 17:48:53 +0000 Subject: [PATCH 19/27] feat(spanner): fix javadoc --- .../main/java/com/google/cloud/spanner/DatabaseAdminClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseAdminClient.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseAdminClient.java index 77314e2bba5..f961a13845b 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseAdminClient.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseAdminClient.java @@ -454,7 +454,7 @@ OperationFuture updateDatabaseDdl( /** * Updates a database in a Cloud Spanner instance. Any proto descriptors that have been set for * the {@link com.google.cloud.spanner.Database} instance will be included in the {@link - * UpdateDatabaseDdlRequest}. + * com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest}. * *

If an operation already exists with the given operation id, the operation will be resumed * and the returned future will complete when the original operation finishes. See more From 7dfe81e36e1591726dfc5201c17700e6b7cd1986 Mon Sep 17 00:00:00 2001 From: Sri Harsha CH Date: Wed, 24 Jan 2024 17:53:58 +0000 Subject: [PATCH 20/27] feat(spanner): fix javadoc --- .../com/google/cloud/spanner/it/ITProtoColumnTest.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITProtoColumnTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITProtoColumnTest.java index 0ae78c3fe27..c79e479eecb 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITProtoColumnTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITProtoColumnTest.java @@ -56,7 +56,7 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -// Integration Tests to test DDL, DML and DQL for Proto Columns & Enums +// Integration Tests to test DDL, DML and DQL for Proto Columns and Enums // TODO(harsha): Check session leak warning @Category(ParallelIntegrationTest.class) @RunWith(JUnit4.class) @@ -153,8 +153,8 @@ public void after() throws Exception { /** * Test to check data update and read queries on Proto Messages, Proto Enums and their arrays. - * Test also checks for compatability between following types: 1. Proto Messages & Bytes 2. Proto - * Enums & Int64 + * Test also checks for compatability between following types: 1. Proto Messages and Bytes 2. Proto + * Enums and Int64 */ @Test public void testProtoColumnsUpdateAndRead() { @@ -242,7 +242,7 @@ public void testProtoColumnsUpdateAndRead() { resultSet.getProtoMessageList("ProtoMessageArray", SingerInfo.getDefaultInstance())); assertEquals(enumList, resultSet.getProtoEnumList("ProtoEnumArray", Genre::forNumber)); - // Check compatability between Proto Messages & Bytes + // Check compatability between Proto Messages and Bytes assertEquals(singerInfoBytes, resultSet.getBytes("ProtoMessage")); assertEquals( singerInfo, resultSet.getProtoMessage("Bytes", SingerInfo.getDefaultInstance())); @@ -252,7 +252,7 @@ public void testProtoColumnsUpdateAndRead() { singerInfoList, resultSet.getProtoMessageList("BytesArray", SingerInfo.getDefaultInstance())); - // Check compatability between Proto Enum & Int64 + // Check compatability between Proto Enum and Int64 assertEquals(genreConst, resultSet.getLong("ProtoEnum")); assertEquals(genre, resultSet.getProtoEnum("Int64a", Genre::forNumber)); From 5491ca39bdd0d6ee00ffee78b16b21113c47a723 Mon Sep 17 00:00:00 2001 From: Sri Harsha CH Date: Wed, 24 Jan 2024 17:56:30 +0000 Subject: [PATCH 21/27] feat(spanner): fix javadoc --- .../java/com/google/cloud/spanner/it/ITProtoColumnTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITProtoColumnTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITProtoColumnTest.java index c79e479eecb..8d9c58e02c4 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITProtoColumnTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITProtoColumnTest.java @@ -153,8 +153,8 @@ public void after() throws Exception { /** * Test to check data update and read queries on Proto Messages, Proto Enums and their arrays. - * Test also checks for compatability between following types: 1. Proto Messages and Bytes 2. Proto - * Enums and Int64 + * Test also checks for compatability between following types: 1. Proto Messages and Bytes 2. + * Proto Enums and Int64 */ @Test public void testProtoColumnsUpdateAndRead() { From 5e972feab04df54b747bc1805e4e97459dddf42e Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Wed, 24 Jan 2024 17:57:04 +0000 Subject: [PATCH 22/27] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- .../java/com/google/cloud/spanner/it/ITProtoColumnTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITProtoColumnTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITProtoColumnTest.java index c79e479eecb..8d9c58e02c4 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITProtoColumnTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITProtoColumnTest.java @@ -153,8 +153,8 @@ public void after() throws Exception { /** * Test to check data update and read queries on Proto Messages, Proto Enums and their arrays. - * Test also checks for compatability between following types: 1. Proto Messages and Bytes 2. Proto - * Enums and Int64 + * Test also checks for compatability between following types: 1. Proto Messages and Bytes 2. + * Proto Enums and Int64 */ @Test public void testProtoColumnsUpdateAndRead() { From be99f9495159c4edb1978ac96fd18350587b4282 Mon Sep 17 00:00:00 2001 From: Sri Harsha CH Date: Thu, 25 Jan 2024 05:11:34 +0000 Subject: [PATCH 23/27] feat(spanner): fix emulator skip --- .../com/google/cloud/spanner/it/ITProtoColumnTest.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITProtoColumnTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITProtoColumnTest.java index 8d9c58e02c4..5e23cdae490 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITProtoColumnTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITProtoColumnTest.java @@ -16,6 +16,7 @@ package com.google.cloud.spanner.it; +import static com.google.cloud.spanner.testing.EmulatorSpannerHelper.isUsingEmulator; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThrows; import static org.junit.Assume.assumeFalse; @@ -129,11 +130,11 @@ public static void createDatabase() throws Exception { @AfterClass public static void afterClass() throws Exception { - assumeFalse( - "Proto Column is not supported in the emulator", EmulatorSpannerHelper.isUsingEmulator()); try { - dbAdminClient.dropDatabase( - databaseID.getInstanceId().getInstance(), databaseID.getDatabase()); + if (!isUsingEmulator()) { + dbAdminClient.dropDatabase( + databaseID.getInstanceId().getInstance(), databaseID.getDatabase()); + } } catch (Exception e) { System.err.println( "Failed to drop database " From b8915b1840b164c1904a5a18958043b509ce59d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Knut=20Olav=20L=C3=B8ite?= Date: Thu, 25 Jan 2024 13:32:39 +0100 Subject: [PATCH 24/27] build: ignore all changes in v1 package --- google-cloud-spanner/clirr-ignored-differences.xml | 12 ------------ google-cloud-spanner/pom.xml | 9 +++++++++ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/google-cloud-spanner/clirr-ignored-differences.xml b/google-cloud-spanner/clirr-ignored-differences.xml index c8608c32e03..56e946eb3d4 100644 --- a/google-cloud-spanner/clirr-ignored-differences.xml +++ b/google-cloud-spanner/clirr-ignored-differences.xml @@ -331,12 +331,6 @@ com/google/cloud/spanner/spi/v1/GapicSpannerRpc com.google.cloud.spanner.spi.v1.SpannerRpc$StreamingCall read(com.google.spanner.v1.ReadRequest, com.google.cloud.spanner.spi.v1.SpannerRpc$ResultStreamConsumer, java.util.Map) - - 7005 - com/google/cloud/spanner/spi/v1/GapicSpannerRpc - com.google.api.gax.longrunning.OperationFuture updateDatabaseDdl(java.lang.String, java.lang.Iterable, java.lang.String) - com.google.api.gax.longrunning.OperationFuture updateDatabaseDdl(com.google.cloud.spanner.Database, java.lang.Iterable, java.lang.String) - 7005 com/google/cloud/spanner/spi/v1/GapicSpannerRpc @@ -387,12 +381,6 @@ com/google/cloud/spanner/spi/v1/SpannerRpc com.google.cloud.spanner.spi.v1.SpannerRpc$StreamingCall read(com.google.spanner.v1.ReadRequest, com.google.cloud.spanner.spi.v1.SpannerRpc$ResultStreamConsumer, java.util.Map) - - 7005 - com/google/cloud/spanner/spi/v1/SpannerRpc - com.google.api.gax.longrunning.OperationFuture updateDatabaseDdl(java.lang.String, java.lang.Iterable, java.lang.String) - com.google.api.gax.longrunning.OperationFuture updateDatabaseDdl(com.google.cloud.spanner.Database, java.lang.Iterable, java.lang.String) - 7005 com/google/cloud/spanner/spi/v1/SpannerRpc diff --git a/google-cloud-spanner/pom.xml b/google-cloud-spanner/pom.xml index 24abc0d2195..999f49b77f0 100644 --- a/google-cloud-spanner/pom.xml +++ b/google-cloud-spanner/pom.xml @@ -134,6 +134,15 @@ org.codehaus.mojo flatten-maven-plugin + + + org.codehaus.mojo + clirr-maven-plugin + + + com/google/cloud/spanner/spi/v1/** + + From 2f75cb07e1fba63bd901816517f0b4c3fd63574d Mon Sep 17 00:00:00 2001 From: Sri Harsha CH Date: Fri, 26 Jan 2024 09:17:11 +0000 Subject: [PATCH 25/27] feat(spanner): add optimizations to deserialize proto messages --- .../cloud/spanner/AbstractResultSet.java | 25 ++++++++++++----- .../java/com/google/cloud/spanner/Type.java | 4 +-- .../java/com/google/cloud/spanner/Value.java | 28 +++++++++++++++---- jitpack.yml | 2 -- 4 files changed, 42 insertions(+), 17 deletions(-) delete mode 100644 jitpack.yml diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AbstractResultSet.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AbstractResultSet.java index fe451898c60..c18e64165bc 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AbstractResultSet.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AbstractResultSet.java @@ -39,10 +39,10 @@ import com.google.common.collect.AbstractIterator; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; +import com.google.common.io.CharSource; import com.google.common.util.concurrent.Uninterruptibles; import com.google.protobuf.AbstractMessage; import com.google.protobuf.ByteString; -import com.google.protobuf.InvalidProtocolBufferException; import com.google.protobuf.ListValue; import com.google.protobuf.NullValue; import com.google.protobuf.ProtocolMessageEnum; @@ -61,6 +61,7 @@ import java.io.IOException; import java.io.Serializable; import java.math.BigDecimal; +import java.nio.charset.StandardCharsets; import java.util.AbstractList; import java.util.ArrayList; import java.util.Base64; @@ -726,10 +727,15 @@ protected T getProtoMessageInternal(int columnIndex, return (T) message .toBuilder() - .mergeFrom(((LazyByteArray) rowData.get(columnIndex)).getByteArray().toByteArray()) + .mergeFrom( + Base64.getDecoder() + .wrap( + CharSource.wrap(((LazyByteArray) rowData.get(columnIndex)).base64String) + .asByteSource(StandardCharsets.UTF_8) + .openStream())) .build(); - } catch (InvalidProtocolBufferException e) { - throw SpannerExceptionFactory.asSpannerException(e); + } catch (IOException ioException) { + throw SpannerExceptionFactory.asSpannerException(ioException); } } @@ -963,13 +969,18 @@ protected List getProtoMessageListInternal( (T) message .toBuilder() - .mergeFrom(protoMessageBytes.getByteArray().toByteArray()) + .mergeFrom( + Base64.getDecoder() + .wrap( + CharSource.wrap(protoMessageBytes.base64String) + .asByteSource(StandardCharsets.UTF_8) + .openStream())) .build()); } } return protoMessagesList; - } catch (InvalidProtocolBufferException e) { - throw SpannerExceptionFactory.asSpannerException(e); + } catch (IOException ioException) { + throw SpannerExceptionFactory.asSpannerException(ioException); } } diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Type.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Type.java index 02ef9945338..348db5d04ae 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Type.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Type.java @@ -130,7 +130,7 @@ public static Type pgJsonb() { /** * To get the descriptor for the {@code PROTO} type. * - * @param protoTypeFqn Proto full name + * @param protoTypeFqn Proto fully qualified name (ex: "spanner.examples.music.SingerInfo"). */ public static Type proto(String protoTypeFqn) { return new Type(Code.PROTO, protoTypeFqn); @@ -139,7 +139,7 @@ public static Type proto(String protoTypeFqn) { /** * To get the descriptor for the {@code ENUM} type. * - * @param protoTypeFqn Proto ENUM full name + * @param protoTypeFqn Proto ENUM fully qualified name (ex: "spanner.examples.music.Genre") */ public static Type protoEnum(String protoTypeFqn) { return new Type(Code.ENUM, protoTypeFqn); diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Value.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Value.java index e4379705296..7cc7b675780 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Value.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Value.java @@ -26,6 +26,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; +import com.google.common.io.CharSource; import com.google.protobuf.AbstractMessage; import com.google.protobuf.Descriptors.Descriptor; import com.google.protobuf.Descriptors.EnumDescriptor; @@ -37,8 +38,10 @@ import java.io.IOException; import java.io.Serializable; import java.math.BigDecimal; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; +import java.util.Base64; import java.util.BitSet; import java.util.Collection; import java.util.Collections; @@ -1684,9 +1687,17 @@ public T getProtoMessage(T m) { "Proto message may not be null. Use MyProtoClass.getDefaultInstance() as a parameter value."); checkNotNull(); try { - return (T) m.toBuilder().mergeFrom(value.getByteArray().toByteArray()).build(); - } catch (InvalidProtocolBufferException e) { - throw SpannerExceptionFactory.asSpannerException(e); + return (T) + m.toBuilder() + .mergeFrom( + Base64.getDecoder() + .wrap( + CharSource.wrap(value.getBase64String()) + .asByteSource(StandardCharsets.UTF_8) + .openStream())) + .build(); + } catch (IOException ioException) { + throw SpannerExceptionFactory.asSpannerException(ioException); } } @@ -2291,13 +2302,18 @@ public List getProtoMessageArray(T m) { protoMessagesList.add( (T) m.toBuilder() - .mergeFrom(protoMessageBytes.getByteArray().toByteArray()) + .mergeFrom( + Base64.getDecoder() + .wrap( + CharSource.wrap(protoMessageBytes.getBase64String()) + .asByteSource(StandardCharsets.UTF_8) + .openStream())) .build()); } } return protoMessagesList; - } catch (InvalidProtocolBufferException e) { - throw SpannerExceptionFactory.asSpannerException(e); + } catch (IOException e) { + throw new RuntimeException(e); } } diff --git a/jitpack.yml b/jitpack.yml deleted file mode 100644 index 46c85291995..00000000000 --- a/jitpack.yml +++ /dev/null @@ -1,2 +0,0 @@ -jdk: - - openjdk11 \ No newline at end of file From 63c720ded9a2a8df9cac9e55aa9371fba6f25847 Mon Sep 17 00:00:00 2001 From: Sri Harsha CH Date: Fri, 26 Jan 2024 09:17:46 +0000 Subject: [PATCH 26/27] feat(spanner): remove TODO --- .../cloud/spanner/connection/RandomResultSetGenerator.java | 1 - 1 file changed, 1 deletion(-) diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/RandomResultSetGenerator.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/RandomResultSetGenerator.java index ed79415fad3..69ae89b2ee9 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/RandomResultSetGenerator.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/RandomResultSetGenerator.java @@ -114,7 +114,6 @@ public static Type[] generateAllTypes(Dialect dialect) { .setArrayElementType(Type.newBuilder().setCode(TypeCode.TIMESTAMP)) .build())); - // TODO(harsha): add test corresponding to this in testGetAllTypesAsString() // appendProtoTypes(types, dialect); Type[] typeArray = new Type[types.size()]; typeArray = types.toArray(typeArray); From 42fafc036849179ab69f8829b0da45c1f5902453 Mon Sep 17 00:00:00 2001 From: Sri Harsha CH Date: Fri, 26 Jan 2024 10:19:34 +0000 Subject: [PATCH 27/27] feat(spanner): remove TODO --- .../google/cloud/spanner/it/ITProtoColumnTest.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITProtoColumnTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITProtoColumnTest.java index 5e23cdae490..c1e06f9ad7b 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITProtoColumnTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITProtoColumnTest.java @@ -18,6 +18,7 @@ import static com.google.cloud.spanner.testing.EmulatorSpannerHelper.isUsingEmulator; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThrows; import static org.junit.Assume.assumeFalse; @@ -43,6 +44,7 @@ import com.google.protobuf.InvalidProtocolBufferException.InvalidWireTypeException; import com.google.protobuf.ProtocolMessageEnum; import com.google.spanner.admin.database.v1.Backup; +import com.google.spanner.admin.database.v1.GetDatabaseDdlResponse; import java.io.InputStream; import java.util.Arrays; import java.util.Collections; @@ -58,7 +60,6 @@ import org.junit.runners.JUnit4; // Integration Tests to test DDL, DML and DQL for Proto Columns and Enums -// TODO(harsha): Check session leak warning @Category(ParallelIntegrationTest.class) @RunWith(JUnit4.class) public class ITProtoColumnTest { @@ -120,11 +121,10 @@ public static void createDatabase() throws Exception { assertEquals(databaseID.getDatabase(), createdDatabase.getId().getDatabase()); - // TODO(harsha): Check with backend team as this is not working for generated columns yet. - // GetDatabaseDdlResponse response = - // dbAdminClient.getDatabaseDdlResponse(databaseID.getInstanceId().getInstance(), - // databaseID.getDatabase()); - // assertNotNull(response.getProtoDescriptors()); + GetDatabaseDdlResponse response = + dbAdminClient.getDatabaseDdlResponse( + databaseID.getInstanceId().getInstance(), databaseID.getDatabase()); + assertNotNull(response.getProtoDescriptors()); in.close(); }