evanchen852 commented on issue #19866: URL: https://github.com/apache/beam/issues/19866#issuecomment-7204783497
I reproduced this on current master. With `FILE_LOADS` and `withAvroFormatFunction` (or `withAvroWriter`), writing user-supplied `GenericRecord`s fails with `UnresolvedUnionException` when the table has a NULLABLE RECORD column and the user's nested record has a different namespace than Beam's generated schema. This happens with records that already carry their own Avro schema, for example events read from Kafka or upstream Avro files. Cause: `BigQueryAvroUtils.toGenericAvroSchema` gives nested records the default namespace `org.apache.beam.sdk.io.gcp.bigquery` (`BigQueryAvroUtils.java` around lines 506–509). A NULLABLE RECORD becomes a `["null", record]` union, and Avro resolves union branches by full name. A structurally identical record named `com.example.events.address` matches neither branch, so `AvroRowWriter.write` throws at `writer.append` (line 59). The same record writes fine when the column is REQUIRED, because there is no union to resolve. The error message does not mention namespaces, which makes this hard to diagnose. I have a unit test that reproduces it (`BigQueryAvroUtilsTest`). Two possible fixes: 1. Make union resolution in Beam's Avro writer fall back to matching by record name when the namespace differs. 2. Keep the current behavior, but catch this case and throw a clear error that explains the namespace mismatch and points to `request.getSchema()` / `withAvroSchemaFactory`. I'd plan to do (2), since it does not change behavior for existing users, unless a maintainer prefers (1). Happy to take this on. -- 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]
