You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2022/06/03 23:47:20 UTC

[GitHub] [beam] kennknowles opened a new issue, #19329: AvroRecordSchema().toRowFunction throws a NPE when avro record contain nulls

kennknowles opened a new issue, #19329:
URL: https://github.com/apache/beam/issues/19329

   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:
   ```
   
   {
       "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}
       ]
   }
   
   ```
   
   the following code witl throw:
   ```
   
       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)
   
   ```
   
   Stacktrace:
   ```
   
   [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)
   
   ```
   
   
   Imported from Jira [BEAM-6742](https://issues.apache.org/jira/browse/BEAM-6742). Original Jira may contain additional context.
   Reported by: jto.


-- 
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: github-unsubscribe@beam.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org