[ 
https://issues.apache.org/jira/browse/NIFI-4893?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16382050#comment-16382050
 ] 

ASF GitHub Bot commented on NIFI-4893:
--------------------------------------

Github user markap14 commented on the issue:

    https://github.com/apache/nifi/pull/2480
  
    @gardellajuanpablo I think for this case we should avoid making any changes 
to RecordField or DataTypeUtils at all. This is an oddity of Avro specifically. 
I do think that it makes sense to honor the way that Avro deals with this case, 
but I think this should be done purely by addressing the issue in AvroTypeUtil. 
I think we can just update the AvroTypeUtil#createSchema(Schema, String, 
SchemaIdentifier) with something like this:
    ```
                    Object defaultValue = field.defaultVal();
                    if (fieldSchema.getType() == Schema.Type.ARRAY && 
!DataTypeUtils.isArrayTypeCompatible(defaultValue)) {
                        defaultValue = new Object[0];
                    }
                    recordFields.add(new RecordField(fieldName, dataType, 
defaultValue, field.aliases(), nullable));
    ```
    And I think that will address the issue without breaking anything else. 
Thoughts?


> Cannot convert Avro schemas to Record schemas with default value in arrays
> --------------------------------------------------------------------------
>
>                 Key: NIFI-4893
>                 URL: https://issues.apache.org/jira/browse/NIFI-4893
>             Project: Apache NiFi
>          Issue Type: Bug
>          Components: Core Framework
>    Affects Versions: 1.5.0, 1.6.0
>         Environment: ALL
>            Reporter: Gardella Juan Pablo
>            Priority: Major
>         Attachments: issue1.zip
>
>
> Given an Avro Schema that has a default array defined, it is not possible to 
> be converted to a Nifi Record Schema.
> To reproduce the bug, try to convert the following Avro schema to Record 
> Schema:
> {code}
> {
>     "type": "record",
>     "name": "Foo1",
>     "namespace": "foo.namespace",
>     "fields": [
>         {
>             "name": "listOfInt",
>             "type": {
>                 "type": "array",
>                 "items": "int"
>             },
>             "doc": "array of ints",
>             "default": 0
>         }
>     ]
> }
> {code}
>  
> Using org.apache.nifi.avro.AvroTypeUtil class. Attached a maven project to 
> reproduce the issue and also the fix.
> * To reproduce the bug, run "mvn clean test"
> * To test the fix, run "mvn clean test -Ppatch".
>  



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

Reply via email to