Skip to content
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

fix(ingest): add message proto check #7130

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ default Stream<SourceCodeInfo.Location> messageLocations() {
List<SourceCodeInfo.Location> fileLocations = fileProto().getSourceCodeInfo().getLocationList();
return fileLocations.stream()
.filter(loc -> loc.getPathCount() > 1
&& loc.getPath(0) == FileDescriptorProto.MESSAGE_TYPE_FIELD_NUMBER);
&& loc.getPath(0) == FileDescriptorProto.MESSAGE_TYPE_FIELD_NUMBER
&& messageProto() == fileProto().getMessageType(loc.getPath(1)));
}

<T> Stream<T> accept(ProtobufModelVisitor<T> v, VisitContext context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.google.protobuf.DescriptorProtos.FieldDescriptorProto;
import com.google.protobuf.DescriptorProtos.FileDescriptorProto;
import com.google.protobuf.DescriptorProtos.OneofDescriptorProto;
import com.google.protobuf.DescriptorProtos.SourceCodeInfo;
import com.linkedin.data.template.StringArray;
import com.linkedin.schema.ArrayType;
import com.linkedin.schema.BooleanType;
Expand Down Expand Up @@ -208,6 +209,14 @@ public SchemaFieldDataType schemaFieldDataType() throws IllegalStateException {
});
}

@Override
public Stream<SourceCodeInfo.Location> messageLocations() {
List<SourceCodeInfo.Location> fileLocations = fileProto().getSourceCodeInfo().getLocationList();
return fileLocations.stream()
.filter(loc -> loc.getPathCount() > 1
&& loc.getPath(0) == FileDescriptorProto.MESSAGE_TYPE_FIELD_NUMBER);
}

@Override
public String comment() {
return messageLocations()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public static ProtobufGraph getTestProtobufGraph(String protoPackage, String fil
return new ProtobufGraph(getTestProtobufFileSet(protoPackage, filename));
}

public static ProtobufGraph getTestProtobufGraph(String protoPackage, String filename, String messageName) throws IOException {
return new ProtobufGraph(getTestProtobufFileSet(protoPackage, filename), messageName);
}

public static Object extractAspect(MetadataChangeProposalWrapper<? extends RecordTemplate> mcp, String aspect) {
return mcp.getAspect().data().get(aspect);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ public class DescriptionVisitorTest {

@Test
public void visitorTest() throws IOException {
ProtobufGraph graph = getTestProtobufGraph("protobuf", "messageB");
ProtobufGraph graph = getTestProtobufGraph("protobuf", "messageC2", "protobuf.MessageC2");

DescriptionVisitor test = new DescriptionVisitor();

assertEquals(Set.of("This contains nested types.\n\nOwned by TeamB"),
graph.accept(getVisitContextBuilder("protobuf.MessageB"), List.of(test)).collect(Collectors.toSet()));
assertEquals(Set.of("This contains nested type\n\nDescription for MessageC2"),
graph.accept(getVisitContextBuilder("protobuf.MessageC2"), List.of(test)).collect(Collectors.toSet()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ message MessageC1 {
MessageC2 messageList = 1;
}

/*
This contains nested type

Description for MessageC2
*/
message MessageC2 {
repeated MessageC3 list = 1;
}
Expand Down
Binary file not shown.