emkornfield commented on code in PR #995:
URL: https://github.com/apache/parquet-mr/pull/995#discussion_r984237501
##########
parquet-protobuf/src/main/java/org/apache/parquet/proto/ProtoSchemaConverter.java:
##########
@@ -124,35 +164,61 @@ private <T> Builder<? extends Builder<?,
GroupBuilder<T>>, GroupBuilder<T>> addR
.named("list");
}
- private <T> GroupBuilder<GroupBuilder<T>> addRepeatedMessage(FieldDescriptor
descriptor, GroupBuilder<T> builder) {
- GroupBuilder<GroupBuilder<GroupBuilder<GroupBuilder<T>>>> result =
- builder
+ private <T> GroupBuilder<GroupBuilder<T>> addRepeatedMessage(FieldDescriptor
descriptor, GroupBuilder<T> builder, ImmutableSetMultimap<String, Integer>
seen, int depth) {
+ GroupBuilder<GroupBuilder<GroupBuilder<GroupBuilder<T>>>> result = builder
.group(Type.Repetition.OPTIONAL).as(listType())
.group(Type.Repetition.REPEATED)
.group(Type.Repetition.OPTIONAL);
- convertFields(result, descriptor.getMessageType().getFields());
+ convertFields(result, descriptor.getMessageType().getFields(), seen,
depth);
return result.named("element").named("list");
}
- private <T> GroupBuilder<GroupBuilder<T>> addMessageField(FieldDescriptor
descriptor, final GroupBuilder<T> builder) {
+ private <T> Builder<? extends Builder<?, GroupBuilder<T>>, GroupBuilder<T>>
addMessageField(FieldDescriptor descriptor, final GroupBuilder<T> builder,
ImmutableSetMultimap<String, Integer> seen, int depth) {
+ // Prevent recursion by terminating with optional proto bytes.
+ depth += 1;
+ String typeName = getInnerTypeName(descriptor);
+ LOG.trace("addMessageField: " + descriptor.getFullName() + " type: " +
typeName + " depth: " + depth);
+ if (typeName != null) {
+ if (seen.get(typeName).size() > maxRecursion) {
+ return builder.primitive(BINARY,
Type.Repetition.OPTIONAL).as((LogicalTypeAnnotation) null);
+ }
+ }
+
if (descriptor.isMapField() && parquetSpecsCompliant) {
// the old schema style did not include the MAP wrapper around map groups
- return addMapField(descriptor, builder);
+ return addMapField(descriptor, builder, seen, depth);
}
+
+ seen = ImmutableSetMultimap.<String,
Integer>builder().putAll(seen).put(typeName, depth).build();
Review Comment:
if this gets modified every time through this method, is immutability useful?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]