Skip to content

Commit a6bad6a

Browse files
authored
GH-3175: support protobuf library version 4 (#3352)
* support protobuf library version 4 The getSyntax method on messageDescriptor.getFile() got removed in protobuf version 4. This change gets the syntax information directly from the proto, this works in protobuf v3 and v4. fixes #3175 see also #3182 * fix formatting
1 parent 8e740f0 commit a6bad6a

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

parquet-protobuf/src/main/java/org/apache/parquet/proto/ProtoWriteSupport.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -445,10 +445,13 @@ final void writeField(Object value) {
445445

446446
private void writeAllFields(MessageOrBuilder pb) {
447447
Descriptor messageDescriptor = pb.getDescriptorForType();
448-
Descriptors.FileDescriptor.Syntax syntax =
449-
messageDescriptor.getFile().getSyntax();
448+
String syntax = messageDescriptor.getFile().toProto().getSyntax();
449+
if ("editions".equals(syntax)) {
450+
throw new UnsupportedOperationException("protocol buffers 'editions' not supported");
451+
}
452+
boolean isProto2 = !"proto3".equals(syntax);
450453

451-
if (Descriptors.FileDescriptor.Syntax.PROTO2.equals(syntax)) {
454+
if (isProto2) {
452455
// Returns changed fields with values. Map is ordered by id.
453456
Map<FieldDescriptor, Object> changedPbFields = pb.getAllFields();
454457

@@ -464,7 +467,7 @@ private void writeAllFields(MessageOrBuilder pb) {
464467
int fieldIndex = fieldDescriptor.getIndex();
465468
fieldWriters[fieldIndex].writeField(entry.getValue());
466469
}
467-
} else if (Descriptors.FileDescriptor.Syntax.PROTO3.equals(syntax)) {
470+
} else {
468471
List<FieldDescriptor> fieldDescriptors = messageDescriptor.getFields();
469472
for (FieldDescriptor fieldDescriptor : fieldDescriptors) {
470473
FieldDescriptor.Type type = fieldDescriptor.getType();

0 commit comments

Comments
 (0)