ibzib commented on a change in pull request #14974:
URL: https://github.com/apache/beam/pull/14974#discussion_r687139294



##########
File path: 
sdks/java/extensions/protobuf/src/main/java/org/apache/beam/sdk/extensions/protobuf/ProtoSchemaTranslator.java
##########
@@ -172,17 +173,24 @@ static Schema getSchema(Descriptors.Descriptor 
descriptor) {
             enumIds.putIfAbsent(fieldDescriptor.getName(), 
fieldDescriptor.getNumber()) == null);
       }
       FieldType oneOfType = FieldType.logicalType(OneOfType.create(subFields, 
enumIds));
-      fields.add(Field.of(oneofDescriptor.getName(), oneOfType));
+      oneOfFieldLocationMap.put(
+          oneofDescriptor.getFields().get(0).getNumber(),
+          Field.of(oneofDescriptor.getName(), oneOfType));
     }
 
     for (Descriptors.FieldDescriptor fieldDescriptor : descriptor.getFields()) 
{
-      if (!oneOfFields.contains(fieldDescriptor.getNumber())) {
+      int fieldDescriptorNumber = fieldDescriptor.getNumber();
+      if (!oneOfFields.contains(fieldDescriptorNumber)) {
         // Store proto field number in metadata.
         FieldType fieldType = beamFieldTypeFromProtoField(fieldDescriptor);
         fields.add(
-            withFieldNumber(
-                    Field.of(fieldDescriptor.getName(), fieldType), 
fieldDescriptor.getNumber())
+            withFieldNumber(Field.of(fieldDescriptor.getName(), fieldType), 
fieldDescriptorNumber)
                 .withOptions(getFieldOptions(fieldDescriptor)));
+      } else if (oneOfFieldLocationMap.containsKey(fieldDescriptorNumber)) {
+        Field oneOfField = oneOfFieldLocationMap.get(fieldDescriptorNumber);
+        if (oneOfField != null) {

Review comment:
       oneOfField should never be null. Is the null checker not able to tell?

##########
File path: 
sdks/java/extensions/protobuf/src/main/java/org/apache/beam/sdk/extensions/protobuf/ProtoSchemaTranslator.java
##########
@@ -157,6 +157,7 @@ static Schema getSchema(Class<? extends Message> clazz) {
 
   static Schema getSchema(Descriptors.Descriptor descriptor) {
     Set<Integer> oneOfFields = Sets.newHashSet();
+    Map<Integer, Field> oneOfFieldLocationMap = Maps.newHashMap();

Review comment:
       Nit: don't include the name of the type in the variable name.
   ```suggestion
       Map<Integer, Field> oneOfFieldLocation = Maps.newHashMap();
   ```

##########
File path: 
sdks/java/extensions/protobuf/src/main/java/org/apache/beam/sdk/extensions/protobuf/ProtoSchemaTranslator.java
##########
@@ -157,6 +157,7 @@ static Schema getSchema(Class<? extends Message> clazz) {
 
   static Schema getSchema(Descriptors.Descriptor descriptor) {
     Set<Integer> oneOfFields = Sets.newHashSet();

Review comment:
       Since the variable names oneOfFields and oneOfFieldLocationMap are very 
similar, we should disambiguate them somehow. Maybe emphasize that this one 
refers to the components of a oneof field, not the oneof field itself.
   
   We should also add comments explaining the meaning of these variables.
   ```suggestion
       Set<Integer> oneOfComponentFields = Sets.newHashSet();
   ```




-- 
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]


Reply via email to