ahmedabu98 commented on code in PR #26873:
URL: https://github.com/apache/beam/pull/26873#discussion_r1204765040
##########
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryUtils.java:
##########
@@ -694,7 +694,7 @@ public static Row toBeamRow(Schema rowSchema, TableSchema
bqSchema, TableRow jso
if (jsonBQValue instanceof List) {
return ((List<Object>) jsonBQValue)
.stream()
- .map(v -> ((Map<String, Object>) v).get("v"))
+ .map(v -> v instanceof Map ? ((Map<String, Object>) v).get("v")
: v)
Review Comment:
The Map refers to the Beam Schema type, I think the equivalent for BigQuery
schema might be a struct
##########
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryUtils.java:
##########
@@ -694,7 +694,16 @@ public static Row toBeamRow(Schema rowSchema, TableSchema
bqSchema, TableRow jso
if (jsonBQValue instanceof List) {
return ((List<Object>) jsonBQValue)
.stream()
- .map(v -> ((Map<String, Object>) v).get("v"))
+ .map(
+ v -> {
+ if (v instanceof Map) {
+ Map<String, Object> m = (Map<String, Object>) v;
+ if (m.size() == 1 && m.containsKey("v")) {
+ return m.get("v");
+ }
+ }
+ return v;
+ })
Review Comment:
I was thinking something like this, just to check if the user is
intentionally converting a list of maps.
```suggestion
.map(v -> (v instanceof Map &&
!fieldType.getCollectionElementType().getTypeName().equals(TypeName.MAP)) ?
((Map<String, Object>) v).get("v") : v)
```
--
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]