prodriguezdefino commented on code in PR #32512:
URL: https://github.com/apache/beam/pull/32512#discussion_r1805340290
##########
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:
Sounds good, I will remove the flattening here.
I noticed that we are not checking for maps types
[here](https://github.com/apache/beam/blob/master/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BeamRowToStorageApiProto.java#L227),
I will the check and improve the messaging for users to understand what's
going on.
Also I will try to work, on a separated PR, on a more general flattening
configuration. Probably in the form of a lambda, so we can delegate the users
what to do in the case of encountering a nested container type in the
translation process.
--
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]