Julien Tournay created BEAM-6742:
------------------------------------

             Summary: `AvroRecordSchema().toRowFunction` throws an NPE when 
avro record contain nulls
                 Key: BEAM-6742
                 URL: https://issues.apache.org/jira/browse/BEAM-6742
             Project: Beam
          Issue Type: Bug
          Components: sdk-java-core
    Affects Versions: 2.9.0
            Reporter: Julien Tournay


When generating a {{SerializableFunction[SomeClass, Row]}}
 where {{Someclass}} was generated and has nullable fields, the generated 
function will throw a NPE.

For example given the following avro schema:
{code:java}
{
    "type": "record",
    "name": "TestRecord",
    "namespace": "com.spotify.scio.avro",
    "doc": "Record for testing",
    "fields": [
        {"name": "int_field", "type": ["null", "int"], "default": null},
        {"name": "long_field", "type": ["null", "long"], "default": null},
        {"name": "float_field", "type": ["null", "float"], "default": null},
        {"name": "double_field", "type": ["null", "double"], "default": null},
        {"name": "boolean_field", "type": ["null", "boolean"], "default": null},
        {"name": "string_field", "type": ["null", "string"], "default": null},
        {"name": "array_field", "type": {"type": "array", "items": "string"}, 
"default": null}
    ]
}
{code}
the following code witl throw:
{code:java}
    val clazz = 
classTag[avro.TestRecord].runtimeClass.asInstanceOf[Class[avro.TestRecord]]
    val toRow = new AvroRecordSchema().toRowFunction(TypeDescriptor.of(clazz))
    avroWithNullable.map(x => toRow(x)).foreach(println)
{code}
Stacktrace:
{code:java}
[info]   java.lang.NullPointerException:
[info]   at 
com.spotify.scio.avro.FieldValueGetter$SchemaCodeGen$4CLQpLwl.get(Unknown 
Source)
[info]   at 
com.spotify.scio.avro.FieldValueGetter$SchemaCodeGen$4CLQpLwl.get(Unknown 
Source)
[info]   at 
org.apache.beam.sdk.values.RowWithGetters.lambda$getValues$2(RowWithGetters.java:117)
[info]   at 
java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
[info]   at 
java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
{code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to