Skip to content

Commit a814e33

Browse files
committed
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 apache#3175 see also apache#3182
1 parent 44701aa commit a814e33

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -445,10 +445,14 @@ 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 =
449+
messageDescriptor.getFile().toProto().getSyntax();
450+
if ("editions".equals(syntax)) {
451+
throw new UnsupportedOperationException("protocol buffers 'editions' not supported");
452+
}
453+
boolean isProto2 = !"proto3".equals(syntax);
450454

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

@@ -464,7 +468,7 @@ private void writeAllFields(MessageOrBuilder pb) {
464468
int fieldIndex = fieldDescriptor.getIndex();
465469
fieldWriters[fieldIndex].writeField(entry.getValue());
466470
}
467-
} else if (Descriptors.FileDescriptor.Syntax.PROTO3.equals(syntax)) {
471+
} else {
468472
List<FieldDescriptor> fieldDescriptors = messageDescriptor.getFields();
469473
for (FieldDescriptor fieldDescriptor : fieldDescriptors) {
470474
FieldDescriptor.Type type = fieldDescriptor.getType();

0 commit comments

Comments
 (0)