use of com.google.protobuf.DescriptorProtos.FieldDescriptorProto in project beam by apache.
the class TableRowToStorageApiProtoTest method testDescriptorFromTableSchema.
@Test
public void testDescriptorFromTableSchema() {
DescriptorProto descriptor = TableRowToStorageApiProto.descriptorSchemaFromTableSchema(BASE_TABLE_SCHEMA);
Map<String, Type> types = descriptor.getFieldList().stream().collect(Collectors.toMap(FieldDescriptorProto::getName, FieldDescriptorProto::getType));
Map<String, Type> expectedTypes = BASE_TABLE_SCHEMA_PROTO.getFieldList().stream().collect(Collectors.toMap(FieldDescriptorProto::getName, FieldDescriptorProto::getType));
assertEquals(expectedTypes, types);
}
use of com.google.protobuf.DescriptorProtos.FieldDescriptorProto in project beam by apache.
the class TableRowToStorageApiProtoTest method testNestedFromTableSchema.
@Test
public void testNestedFromTableSchema() {
DescriptorProto descriptor = TableRowToStorageApiProto.descriptorSchemaFromTableSchema(NESTED_TABLE_SCHEMA);
Map<String, Type> expectedBaseTypes = BASE_TABLE_SCHEMA_PROTO.getFieldList().stream().collect(Collectors.toMap(FieldDescriptorProto::getName, FieldDescriptorProto::getType));
Map<String, Type> expectedBaseTypesNoF = BASE_TABLE_SCHEMA_NO_F_PROTO.getFieldList().stream().collect(Collectors.toMap(FieldDescriptorProto::getName, FieldDescriptorProto::getType));
Map<String, Type> types = descriptor.getFieldList().stream().collect(Collectors.toMap(FieldDescriptorProto::getName, FieldDescriptorProto::getType));
Map<String, String> typeNames = descriptor.getFieldList().stream().collect(Collectors.toMap(FieldDescriptorProto::getName, FieldDescriptorProto::getTypeName));
assertEquals(4, types.size());
Map<String, DescriptorProto> nestedTypes = descriptor.getNestedTypeList().stream().collect(Collectors.toMap(DescriptorProto::getName, Functions.identity()));
assertEquals(4, nestedTypes.size());
assertEquals(Type.TYPE_MESSAGE, types.get("nestedvalue1"));
String nestedTypeName1 = typeNames.get("nestedvalue1");
Map<String, Type> nestedTypes1 = nestedTypes.get(nestedTypeName1).getFieldList().stream().collect(Collectors.toMap(FieldDescriptorProto::getName, FieldDescriptorProto::getType));
assertEquals(expectedBaseTypes, nestedTypes1);
assertEquals(Type.TYPE_MESSAGE, types.get("nestedvalue2"));
String nestedTypeName2 = typeNames.get("nestedvalue2");
Map<String, Type> nestedTypes2 = nestedTypes.get(nestedTypeName2).getFieldList().stream().collect(Collectors.toMap(FieldDescriptorProto::getName, FieldDescriptorProto::getType));
assertEquals(expectedBaseTypes, nestedTypes2);
assertEquals(Type.TYPE_MESSAGE, types.get("nestedvaluenof1"));
String nestedTypeNameNoF1 = typeNames.get("nestedvaluenof1");
Map<String, Type> nestedTypesNoF1 = nestedTypes.get(nestedTypeNameNoF1).getFieldList().stream().collect(Collectors.toMap(FieldDescriptorProto::getName, FieldDescriptorProto::getType));
assertEquals(expectedBaseTypesNoF, nestedTypesNoF1);
assertEquals(Type.TYPE_MESSAGE, types.get("nestedvaluenof2"));
String nestedTypeNameNoF2 = typeNames.get("nestedvaluenof2");
Map<String, Type> nestedTypesNoF2 = nestedTypes.get(nestedTypeNameNoF2).getFieldList().stream().collect(Collectors.toMap(FieldDescriptorProto::getName, FieldDescriptorProto::getType));
assertEquals(expectedBaseTypesNoF, nestedTypesNoF2);
}
use of com.google.protobuf.DescriptorProtos.FieldDescriptorProto in project beam by apache.
the class BeamRowToStorageApiProtoTest method testDescriptorFromSchema.
@Test
public void testDescriptorFromSchema() {
DescriptorProto descriptor = BeamRowToStorageApiProto.descriptorSchemaFromBeamSchema(BASE_SCHEMA);
Map<String, Type> types = descriptor.getFieldList().stream().collect(Collectors.toMap(FieldDescriptorProto::getName, FieldDescriptorProto::getType));
Map<String, Type> expectedTypes = BASE_SCHEMA_PROTO.getFieldList().stream().collect(Collectors.toMap(FieldDescriptorProto::getName, FieldDescriptorProto::getType));
assertEquals(expectedTypes, types);
Map<String, String> nameMapping = BASE_SCHEMA.getFields().stream().collect(Collectors.toMap(f -> f.getName().toLowerCase(), Field::getName));
descriptor.getFieldList().forEach(p -> {
FieldType schemaFieldType = BASE_SCHEMA.getField(nameMapping.get(p.getName())).getType();
Label label = schemaFieldType.getTypeName().isCollectionType() ? Label.LABEL_REPEATED : schemaFieldType.getNullable() ? Label.LABEL_OPTIONAL : Label.LABEL_REQUIRED;
assertEquals(label, p.getLabel());
});
}
use of com.google.protobuf.DescriptorProtos.FieldDescriptorProto in project beam by apache.
the class BeamRowToStorageApiProtoTest method testNestedFromSchema.
@Test
public void testNestedFromSchema() {
DescriptorProto descriptor = BeamRowToStorageApiProto.descriptorSchemaFromBeamSchema(NESTED_SCHEMA);
Map<String, Type> expectedBaseTypes = BASE_SCHEMA_PROTO.getFieldList().stream().collect(Collectors.toMap(FieldDescriptorProto::getName, FieldDescriptorProto::getType));
Map<String, Type> types = descriptor.getFieldList().stream().collect(Collectors.toMap(FieldDescriptorProto::getName, FieldDescriptorProto::getType));
Map<String, String> typeNames = descriptor.getFieldList().stream().collect(Collectors.toMap(FieldDescriptorProto::getName, FieldDescriptorProto::getTypeName));
Map<String, Label> typeLabels = descriptor.getFieldList().stream().collect(Collectors.toMap(FieldDescriptorProto::getName, FieldDescriptorProto::getLabel));
assertEquals(3, types.size());
Map<String, DescriptorProto> nestedTypes = descriptor.getNestedTypeList().stream().collect(Collectors.toMap(DescriptorProto::getName, Functions.identity()));
assertEquals(3, nestedTypes.size());
assertEquals(Type.TYPE_MESSAGE, types.get("nested"));
assertEquals(Label.LABEL_OPTIONAL, typeLabels.get("nested"));
String nestedTypeName1 = typeNames.get("nested");
Map<String, Type> nestedTypes1 = nestedTypes.get(nestedTypeName1).getFieldList().stream().collect(Collectors.toMap(FieldDescriptorProto::getName, FieldDescriptorProto::getType));
assertEquals(expectedBaseTypes, nestedTypes1);
assertEquals(Type.TYPE_MESSAGE, types.get("nestedarray"));
assertEquals(Label.LABEL_REPEATED, typeLabels.get("nestedarray"));
String nestedTypeName2 = typeNames.get("nestedarray");
Map<String, Type> nestedTypes2 = nestedTypes.get(nestedTypeName2).getFieldList().stream().collect(Collectors.toMap(FieldDescriptorProto::getName, FieldDescriptorProto::getType));
assertEquals(expectedBaseTypes, nestedTypes2);
assertEquals(Type.TYPE_MESSAGE, types.get("nestediterable"));
assertEquals(Label.LABEL_REPEATED, typeLabels.get("nestediterable"));
String nestedTypeName3 = typeNames.get("nestediterable");
Map<String, Type> nestedTypes3 = nestedTypes.get(nestedTypeName3).getFieldList().stream().collect(Collectors.toMap(FieldDescriptorProto::getName, FieldDescriptorProto::getType));
assertEquals(expectedBaseTypes, nestedTypes3);
}
Aggregations