Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BigQueryType#fromAvro throws an error populating empty Optional fields when using Avro 1.11 #5713

@clairemcginty

Description

@clairemcginty

Given an Avro record with schema:

[{
    "type": "record",
    "name": "MyRecord",
    "fields": [
        {
          "name": "foo",
          "type": "string"
        }
    ]
}]

On Avro 1.8, invoking GenericRecord#get("bar") returns null.

On Avro 1.11+, invoking GenericRecord#get("bar") throws an org.apache.avro.AvroRuntimeException: Not a valid schema field: bar.

This has a consequence for BigQueryType classes that include an optional field that's not guaranteed to exist in the BQ table. Typed BQ that specifies BigQueryIO's GenericRecord format and invokes BigQueryType#fromAvro on the resulting record will throw the AvroRuntimeException on Avro 1.11.

We could fix it by updating BigQueryType#fromAvro to check for the existence of the field in the schema before calling GenericRecord#get, if the corresponding case class field is an Option: https://github.com/spotify/scio/blob/v0.14.17/scio-google-cloud-platform/src/main/scala/com/spotify/scio/bigquery/types/ConverterProvider.scala#L134-L136

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions