Skip to content

Commit

Permalink
fix(ingest): fix logic error of google protobuf wrapper type. (datahu…
Browse files Browse the repository at this point in the history
…b-project#7076)

Co-authored-by: david-leifker <[email protected]>
  • Loading branch information
2 people authored and Eric Yomi committed Feb 8, 2023
1 parent f503902 commit a5107fa
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public String getNativeType() {
return nativeType();
}

public int getNumber() {
return fieldProto.getNumber();
public int getNumber() {
return fieldProto.getNumber();
}

@Override
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -250,7 +250,11 @@ private FieldDescriptorProto getNestedTypeFields(List<Integer> 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<Integer> pathList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
syntax = "proto3";
package extended_protobuf;

import "google/protobuf/wrappers.proto";


message UserMsg {
message UserInfo {
string nickname = 1; // nickname info
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;
}
Binary file not shown.

0 comments on commit a5107fa

Please sign in to comment.