reuvenlax commented on a change in pull request #10413: [BEAM-9035] Typed 
options for Row Schema and Field
URL: https://github.com/apache/beam/pull/10413#discussion_r387969786
 
 

 ##########
 File path: 
sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/SchemaTranslation.java
 ##########
 @@ -299,59 +314,147 @@ private static FieldType 
fieldTypeFromProtoWithoutNullable(SchemaApi.FieldType p
     }
   }
 
+  static Object fieldValueFromProto(FieldType fieldType, SchemaApi.FieldValue 
value) {
+    switch (fieldType.getTypeName()) {
+      case ARRAY:
+        return arrayValueFromProto(fieldType.getCollectionElementType(), 
value.getArrayValue());
+      case ITERABLE:
+        return iterableValueFromProto(
+            fieldType.getCollectionElementType(), value.getIterableValue());
+      case MAP:
+        return mapFromProto(
+            fieldType.getMapKeyType(), fieldType.getMapValueType(), 
value.getMapValue());
+      case ROW:
+        return rowFromProto(value.getRowValue(), fieldType);
+      case LOGICAL_TYPE:
+      default:
+        return primitiveFromProto(fieldType, value.getAtomicValue());
+    }
+  }
+
   private static SchemaApi.ArrayTypeValue arrayValueToProto(
       FieldType elementType, Iterable values) {
     return ArrayTypeValue.newBuilder()
-        .addAllElement(Iterables.transform(values, e -> 
rowFieldToProto(elementType, e)))
+        .addAllElement(Iterables.transform(values, e -> 
fieldValueToProto(elementType, e)))
         .build();
   }
 
+  private static Iterable arrayValueFromProto(
+      FieldType elementType, SchemaApi.ArrayTypeValue values) {
+    return values.getElementList().stream()
+        .map(e -> fieldValueFromProto(elementType, e))
+        .collect(Collectors.toList());
+  }
+
   private static SchemaApi.IterableTypeValue iterableValueToProto(
       FieldType elementType, Iterable values) {
     return IterableTypeValue.newBuilder()
-        .addAllElement(Iterables.transform(values, e -> 
rowFieldToProto(elementType, e)))
+        .addAllElement(Iterables.transform(values, e -> 
fieldValueToProto(elementType, e)))
         .build();
   }
 
+  private static Object iterableValueFromProto(FieldType elementType, 
IterableTypeValue values) {
+    return values.getElementList().stream()
+        .map(e -> fieldValueFromProto(elementType, e))
+        .collect(Collectors.toList());
+  }
 
 Review comment:
   this is the same as arrayValueFromProto.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to