lucasnoetzold opened a new issue, #30850:
URL: https://github.com/apache/beam/issues/30850
### What happened?
We're gettig a `ClassCastException` when trying to write data to a BigQuery
table with the STORAGE_WRITE_API. This only happens with unknown fields on the
payload, both `ignoreUnknownValues` and `withAutoSchemaUpdate` options are
enabled and the field being written is a REPEATED RECORD.
**Conditions:**
- BigQuery table that contains a "RECORD" type field
- the record field must be on mode "repeated"
- `.ignoreUnknownValues()` option enabled
- `.withAutoSchemaUpdate(true)` option enabled
- payload that contains any unknown field inside the RECORD field that does
exist
**Expected Behavior:** unknown fields are ignored and the known payload is
sent to BigQuery.
---
I've managed to reproduce the error with this minimal code:
```java
var nested = List.of(Map.of("nested_field_that_exists", "something"));
var row = new TableRow().set("root_field", nested);
var pipeline = Pipeline.create();
pipeline.apply(Create.<TableRow>of(row))
.apply(BigQueryIO.<TableRow>write()
.ignoreUnknownValues()
.withAutoSchemaUpdate(true)
.withFormatFunction(identity())
.withMethod(BigQueryIO.Write.Method.STORAGE_WRITE_API)
.to(new TableReference()
.setProjectId("the_project_id")
.setDatasetId("the_dataset_id")
.setTableId("test_table")));
pipeline.run();
```
The BigQuery table schema used is the following:

Looking at the stack we can see that it happens when it's handling the
unknown fields. Since the unknown field is nested, and the field descriptor is
inherited from the root field, it expects it to be a list (since the root field
is at mode REPEATED):

### Issue Priority
Priority: 2 (default / most bugs should be filed as P2)
### Issue Components
- [ ] Component: Python SDK
- [X] Component: Java SDK
- [ ] Component: Go SDK
- [ ] Component: Typescript SDK
- [ ] Component: IO connector
- [ ] Component: Beam YAML
- [ ] Component: Beam examples
- [ ] Component: Beam playground
- [ ] Component: Beam katas
- [ ] Component: Website
- [ ] Component: Spark Runner
- [ ] Component: Flink Runner
- [ ] Component: Samza Runner
- [ ] Component: Twister2 Runner
- [ ] Component: Hazelcast Jet Runner
- [ ] Component: Google Cloud Dataflow Runner
--
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]