-
Notifications
You must be signed in to change notification settings - Fork 1.5k
PARQUET-660: Ignore extension fields in protobuf messages. #351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -156,7 +156,6 @@ class MessageWriter extends FieldWriter { | |
| List<Descriptors.FieldDescriptor> fields = descriptor.getFields(); | ||
| fieldWriters = (FieldWriter[]) Array.newInstance(FieldWriter.class, fields.size()); | ||
|
|
||
| int i = 0; | ||
| for (Descriptors.FieldDescriptor fieldDescriptor: fields) { | ||
| String name = fieldDescriptor.getName(); | ||
| Type type = schema.getType(name); | ||
|
|
@@ -169,8 +168,7 @@ class MessageWriter extends FieldWriter { | |
| writer.setFieldName(name); | ||
| writer.setIndex(schema.getFieldIndex(name)); | ||
|
|
||
| fieldWriters[i] = writer; | ||
| i++; | ||
| fieldWriters[fieldDescriptor.getIndex()] = writer; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -220,6 +218,13 @@ private void writeAllFields(MessageOrBuilder pb) { | |
|
|
||
| for (Map.Entry<Descriptors.FieldDescriptor, Object> entry : changedPbFields.entrySet()) { | ||
| Descriptors.FieldDescriptor fieldDescriptor = entry.getKey(); | ||
|
|
||
| if(fieldDescriptor.isExtension()) { | ||
| // Field index of an extension field might overlap with a base field. | ||
| throw new UnsupportedOperationException( | ||
| "Cannot convert Protobuf message with extension field(s)"); | ||
| } | ||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another option would be throw an Exception here and explicitly do not support messages with extensions. I could also log a warning here, somehow only once though, to avoid the noise.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the approach of throwing an exception. It is easy to add support for a special case later. It is harder to change behavior as it breaks existing applications. |
||
| int fieldIndex = fieldDescriptor.getIndex(); | ||
| fieldWriters[fieldIndex].writeField(entry.getValue()); | ||
| } | ||
|
|
@@ -276,7 +281,7 @@ final void writeRawValue(Object value) { | |
| } | ||
|
|
||
| class IntWriter extends FieldWriter { | ||
| @Override | ||
| @Override | ||
| final void writeRawValue(Object value) { | ||
| recordConsumer.addInteger((Integer) value); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this the same change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, fields in the list over which we're iterating are ordered by index. Here's how the list is built:
https://github.com/google/protobuf/blob/master/java/core/src/main/java/com/google/protobuf/Descriptors.java#L826