diff --git a/metadata-integration/java/datahub-protobuf/src/main/java/datahub/protobuf/model/ProtobufField.java b/metadata-integration/java/datahub-protobuf/src/main/java/datahub/protobuf/model/ProtobufField.java index 48748a0540186..a87594b89c649 100644 --- a/metadata-integration/java/datahub-protobuf/src/main/java/datahub/protobuf/model/ProtobufField.java +++ b/metadata-integration/java/datahub-protobuf/src/main/java/datahub/protobuf/model/ProtobufField.java @@ -76,8 +76,8 @@ public String getNativeType() { return nativeType(); } - public int getNumber() { - return fieldProto.getNumber(); + public int getNumber() { + return fieldProto.getNumber(); } @Override @@ -151,7 +151,7 @@ public String fieldPathType() { public boolean isMessage() { return Optional.ofNullable(isMessageType).orElseGet(() -> - fieldProto.getType().equals(FieldDescriptorProto.Type.TYPE_MESSAGE)); + fieldProto.getType().equals(FieldDescriptorProto.Type.TYPE_MESSAGE)); } public int sortWeight() { @@ -250,7 +250,11 @@ private FieldDescriptorProto getNestedTypeFields(List pathList, Descrip messageType = messageType.getNestedType(value); } - return messageType.getField(pathList.get(pathList.size() - 1)); + if (pathList.get(pathSize - 2) == DescriptorProto.FIELD_FIELD_NUMBER) { + return messageType.getField(pathList.get(pathSize - 1)); + } else { + return null; + } } private boolean isEnumType(List pathList) { diff --git a/metadata-integration/java/datahub-protobuf/src/test/java/datahub/protobuf/model/ProtobufFieldTest.java b/metadata-integration/java/datahub-protobuf/src/test/java/datahub/protobuf/model/ProtobufFieldTest.java index 692e83885550a..a21acf7f6c113 100644 --- a/metadata-integration/java/datahub-protobuf/src/test/java/datahub/protobuf/model/ProtobufFieldTest.java +++ b/metadata-integration/java/datahub-protobuf/src/test/java/datahub/protobuf/model/ProtobufFieldTest.java @@ -43,7 +43,7 @@ public class ProtobufFieldTest { @Test public void fieldTest() { - FieldDescriptorProto expectedField = FieldDescriptorProto.newBuilder() + FieldDescriptorProto expectedField = FieldDescriptorProto.newBuilder() .setName("field1") .setNumber(1) .setType(FieldDescriptorProto.Type.TYPE_BYTES) @@ -83,7 +83,7 @@ public void fieldTest() { @Test public void fieldPathTypeTest() { Arrays.stream(FieldDescriptorProto.Type.values()).forEach(type -> { - final FieldDescriptorProto expectedField; + final FieldDescriptorProto expectedField; if (type == FieldDescriptorProto.Type.TYPE_MESSAGE) { expectedField = FieldDescriptorProto.newBuilder() .setName("field1") @@ -121,7 +121,7 @@ public void fieldPathTypeTest() { @Test public void fieldPathTypeArrayTest() { Arrays.stream(FieldDescriptorProto.Type.values()).forEach(type -> { - final FieldDescriptorProto expectedField; + final FieldDescriptorProto expectedField; if (type == FieldDescriptorProto.Type.TYPE_MESSAGE) { expectedField = FieldDescriptorProto.newBuilder() @@ -162,7 +162,7 @@ public void fieldPathTypeArrayTest() { @Test public void schemaFieldTypeTest() { Arrays.stream(FieldDescriptorProto.Type.values()).forEach(type -> { - final FieldDescriptorProto expectedField; + final FieldDescriptorProto expectedField; if (type == FieldDescriptorProto.Type.TYPE_MESSAGE) { expectedField = FieldDescriptorProto.newBuilder() .setName("field1") @@ -206,7 +206,7 @@ public void schemaFieldTypeTest() { @Test public void schemaFieldTypeArrayTest() { Arrays.stream(FieldDescriptorProto.Type.values()).forEach(type -> { - final FieldDescriptorProto expectedField; + final FieldDescriptorProto expectedField; if (type == FieldDescriptorProto.Type.TYPE_MESSAGE) { expectedField = FieldDescriptorProto.newBuilder() .setName("field1") @@ -255,5 +255,14 @@ public void nestedTypeFieldTest() throws IOException { .orElseThrow(); assertEquals("profile url info", profileUrlField.getDescription()); + + SchemaField addressField = testMetadata.getFields() + .stream().filter(f -> f.getFieldPath() + .equals("[version=2.0].[type=extended_protobuf_UserMsg]." + + "[type=extended_protobuf_UserMsg_AddressMsg].address.[type=google_protobuf_StringValue].zipcode")) + .findFirst() + .orElseThrow(); + + assertEquals("Zip code, alphanumeric", addressField.getDescription()); } } diff --git a/metadata-integration/java/datahub-protobuf/src/test/resources/extended_protobuf/messageC.proto b/metadata-integration/java/datahub-protobuf/src/test/resources/extended_protobuf/messageC.proto index 7ff5320525125..337c9f9c658a8 100644 --- a/metadata-integration/java/datahub-protobuf/src/test/resources/extended_protobuf/messageC.proto +++ b/metadata-integration/java/datahub-protobuf/src/test/resources/extended_protobuf/messageC.proto @@ -1,6 +1,8 @@ syntax = "proto3"; package extended_protobuf; +import "google/protobuf/wrappers.proto"; + message UserMsg { message UserInfo { @@ -8,7 +10,16 @@ message UserMsg { string profile_url = 2; // profile url info } + message AddressMsg { + google.protobuf.StringValue zipcode = 1; // Zip code, alphanumeric + google.protobuf.StringValue city = 2; // City corresponding to zip code + google.protobuf.StringValue country = 3; // County + } + string id = 1; // user id string name = 2; // user name UserInfo user_info = 3; // user info + + // address + AddressMsg address = 4; } \ No newline at end of file diff --git a/metadata-integration/java/datahub-protobuf/src/test/resources/extended_protobuf/messageC.protoc b/metadata-integration/java/datahub-protobuf/src/test/resources/extended_protobuf/messageC.protoc index e87d4e7aaa646..a45de9bd8a3e9 100644 Binary files a/metadata-integration/java/datahub-protobuf/src/test/resources/extended_protobuf/messageC.protoc and b/metadata-integration/java/datahub-protobuf/src/test/resources/extended_protobuf/messageC.protoc differ