You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "Lars Francke (JIRA)" <ji...@apache.org> on 2019/04/10 22:46:00 UTC
[jira] [Created] (NIFI-6204) Avro with a default field of type long
fails with ClassCastException
Lars Francke created NIFI-6204:
----------------------------------
Summary: Avro with a default field of type long fails with ClassCastException
Key: NIFI-6204
URL: https://issues.apache.org/jira/browse/NIFI-6204
Project: Apache NiFi
Issue Type: Bug
Reporter: Lars Francke
Attachments: Avro-issue.xml, Screen Shot 2019-04-11 at 00.33.51.png, Screen Shot 2019-04-11 at 00.38.31.png
I get this error:
{code}org.apache.avro.file.DataFileWriter$AppendWriteException: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long{code}
I've attached an example workflow plus screenshots.
Basically: Converting a schema like this
{code}
{
"name": "foobar",
"type": "record",
"fields": [
{ "name": "a", "type": "string" }
]
}
{code}
into this
{code}
{
"name": "foobar",
"type": "record",
"fields": [
{ "name": "a", "type": "string" },
{ "name": "b", "type": "long", "default": 100 }
]
}
{code}
fails because of this snippet in {{AvroTypeUtil}}:
{code}
// see if the Avro schema has any fields that aren't in the RecordSchema, and if those fields have a default
// value then we want to populate it in the GenericRecord being produced
for (final Field field : avroSchema.getFields()) {
final Optional<RecordField> recordField = recordSchema.getField(field.name());
if (!recordField.isPresent() && rec.get(field.name()) == null && field.defaultVal() != null) {
rec.put(field.name(), field.defaultVal());
}
}
{code}
This relies on {{field.defaultVal()}} returning the correct type.
The field that this relies on is a {{JsonNode}} from Jackson. So it parses the Schema and the "default" field is parsed into an {{IntNode}} which is then put into the record and that is not a Long so the cast fails when Avro tries to write it later.
Now Jackson has no way of knowing that this is supposed to be a LongNode instead of an IntNode. I'm not sure if Avro should catch this or NiFi and I also have no good idea on how to fix this.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)