robertwb commented on code in PR #32512:
URL: https://github.com/apache/beam/pull/32512#discussion_r1804071314


##########
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BeamRowToStorageApiProto.java:
##########
@@ -289,25 +307,44 @@ private static Object toProtoValue(
       case ROW:
         return messageFromBeamRow(fieldDescriptor.getMessageType(), (Row) 
value, null, -1);
       case ARRAY:
-        List<Object> list = (List<Object>) value;
-        @Nullable FieldType arrayElementType = 
beamFieldType.getCollectionElementType();
-        if (arrayElementType == null) {
-          throw new RuntimeException("Unexpected null element type!");
-        }
-        return list.stream()
-            .map(v -> toProtoValue(fieldDescriptor, arrayElementType, v))
-            .collect(Collectors.toList());
       case ITERABLE:
         Iterable<Object> iterable = (Iterable<Object>) value;
         @Nullable FieldType iterableElementType = 
beamFieldType.getCollectionElementType();
         if (iterableElementType == null) {
-          throw new RuntimeException("Unexpected null element type!");
+          throw new RuntimeException("Unexpected null element type: " + 
fieldDescriptor.getName());
         }
-        return StreamSupport.stream(iterable.spliterator(), false)
-            .map(v -> toProtoValue(fieldDescriptor, iterableElementType, v))
-            .collect(Collectors.toList());
+        // We currently only support maps as non-row or non-scalar element 
types
+        // given that BigQuery does not support nested arrays. If the element 
type is of map type
+        // we should flatten it given how is being translated (as a list of 
proto(key, value).

Review Comment:
   For Maps it's fine as there's no surprise on the user side (e.g. seeing 
key-value records) plus it can be losslessly translated back if read as a MAP 
type. But the same cannot be said of the flattening that's done. 
   
   If we are concerned about convenience for users, a separate explicit 
transform that flattens nested structures could be provided (which would be the 
identity if there are no required unnestings). This should have comparable 
performance to doing it as part of the write, and likely negligible to the cost 
of actually talking to the services in question. 



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