diff --git a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/ProtoSchemaConverter.java b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/ProtoSchemaConverter.java index c55d4181a5..16e8e3425d 100644 --- a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/ProtoSchemaConverter.java +++ b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/ProtoSchemaConverter.java @@ -102,6 +102,17 @@ private static ProtoSchema convertInternal( enumTypes.add(enumFullName); } } + // The protobuf payload will be decoded as proto2 on the server side. The schema is also + // specified as proto2. Hence we must clear proto3-only features. This works since proto2 and + // proto3 are binary-compatible. + if (resultField.hasProto3Optional()) { + // Clear proto3-only features + resultField.clearProto3Optional(); + } + if (resultField.hasOneofIndex()) { + // Clear proto3-only features + resultField.clearOneofIndex(); + } resultProto.addField(resultField); } structTypes.add(protoFullName);