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

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

GitHub user bbende opened a pull request:

    https://github.com/apache/nifi/pull/1896

    NIFI-4030 Populating default values on GenericRecord from Avro schema…

    … if not present in RecordSchema
    
    Thank you for submitting a contribution to Apache NiFi.
    
    In order to streamline the review of the contribution we ask you
    to ensure the following steps have been taken:
    
    ### For all changes:
    - [ ] Is there a JIRA ticket associated with this PR? Is it referenced 
         in the commit message?
    
    - [ ] Does your PR title start with NIFI-XXXX where XXXX is the JIRA number 
you are trying to resolve? Pay particular attention to the hyphen "-" character.
    
    - [ ] Has your PR been rebased against the latest commit within the target 
branch (typically master)?
    
    - [ ] Is your initial contribution a single, squashed commit?
    
    ### For code changes:
    - [ ] Have you ensured that the full suite of tests is executed via mvn 
-Pcontrib-check clean install at the root nifi folder?
    - [ ] Have you written or updated unit tests to verify your changes?
    - [ ] If adding new dependencies to the code, are these dependencies 
licensed in a way that is compatible for inclusion under [ASF 
2.0](http://www.apache.org/legal/resolved.html#category-a)? 
    - [ ] If applicable, have you updated the LICENSE file, including the main 
LICENSE file under nifi-assembly?
    - [ ] If applicable, have you updated the NOTICE file, including the main 
NOTICE file found under nifi-assembly?
    - [ ] If adding new Properties, have you added .displayName in addition to 
.name (programmatic access) for each of the new properties?
    
    ### For documentation related changes:
    - [ ] Have you ensured that format looks appropriate for the output in 
which it is rendered?
    
    ### Note:
    Please ensure that once the PR is submitted, you check travis-ci for build 
issues and submit an update to your PR as soon as possible.


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/bbende/nifi NIFI-4030

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/nifi/pull/1896.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #1896
    
----
commit 1b9f5d8d40d211e8ee2ecfeca64e9e6eccc24ba8
Author: Bryan Bende <[email protected]>
Date:   2017-06-07T17:00:13Z

    NIFI-4030 Populating default values on GenericRecord from Avro schema if 
not present in RecordSchema

----


> Avro Schema with default values can cause NPE
> ---------------------------------------------
>
>                 Key: NIFI-4030
>                 URL: https://issues.apache.org/jira/browse/NIFI-4030
>             Project: Apache NiFi
>          Issue Type: Bug
>    Affects Versions: 1.2.0, 1.3.0
>            Reporter: Bryan Bende
>            Priority: Minor
>         Attachments: Convert_Avro_Short_to_Full.xml
>
>
> While coming up with an example to convert between Avro schemas, I ran into 
> the following scenario...
> I created two schemas like the following:
> {code}
> {
>   "name": "shortSchema",
>   "namespace": "nifi",
>   "type": "record",
>   "fields": [
>     { "name": "a", "type": "string" },
>     { "name": "b", "type": "string" }
>   ]
> }
> {code}
> {code}
> {
>   "name": "fullSchema",
>   "namespace": "nifi",
>   "type": "record",
>   "fields": [
>     { "name": "c", "type": "string", "default" : "default value for field c" 
> },
>     { "name": "d", "type": "string", "default" : "default value for field d" 
> },
>     { "name": "a", "type": "string" },
>     { "name": "b", "type": "string" }
>   ]
> }
> {code}
> Then I created a flow with a ConvertRecord processor that read a flow file 
> which had Avro created with the shortSchema, and used a writer configured to 
> write with the fullSchema.
> This produced the following exception, even though the fullSchema has default 
> values for additional fields:
> {code}
> ERROR [Timer-Driven Process Thread-1] o.a.n.processors.standard.ConvertRecord 
> ConvertRecord[id=ec373b3a-5704-1c6b-f501-0977a332d513] Failed to process 
> StandardFlowFileRecord[uuid=a8e604a9-1e15-4b9b-a4b7-fdbd441d3f2a,claim=StandardContentClaim
>  [resourceClaim=StandardResourceClaim[id=1496842800576-10, container=default, 
> section=10], offset=40141, 
> length=196],offset=0,name=128518448076937,size=196]: 
> org.apache.avro.file.DataFileWriter$AppendWriteException: 
> java.lang.NullPointerException: null of string in field c of nifi.fullSchema
> org.apache.avro.file.DataFileWriter$AppendWriteException: 
> java.lang.NullPointerException: null of string in field c of nifi.fullSchema
>       at org.apache.avro.file.DataFileWriter.append(DataFileWriter.java:308)
>       at 
> org.apache.nifi.avro.WriteAvroResultWithSchema.writeRecord(WriteAvroResultWithSchema.java:59)
>       at 
> org.apache.nifi.serialization.AbstractRecordSetWriter.write(AbstractRecordSetWriter.java:59)
>       at 
> org.apache.nifi.processors.standard.AbstractRecordProcessor$1.process(AbstractRecordProcessor.java:130)
>       at 
> org.apache.nifi.controller.repository.StandardProcessSession.write(StandardProcessSession.java:2785)
>       at 
> org.apache.nifi.processors.standard.AbstractRecordProcessor.onTrigger(AbstractRecordProcessor.java:118)
>       at 
> org.apache.nifi.processor.AbstractProcessor.onTrigger(AbstractProcessor.java:27)
>       at 
> org.apache.nifi.controller.StandardProcessorNode.onTrigger(StandardProcessorNode.java:1120)
>       at 
> org.apache.nifi.controller.tasks.ContinuallyRunProcessorTask.call(ContinuallyRunProcessorTask.java:147)
>       at 
> org.apache.nifi.controller.tasks.ContinuallyRunProcessorTask.call(ContinuallyRunProcessorTask.java:47)
>       at 
> org.apache.nifi.controller.scheduling.TimerDrivenSchedulingAgent$1.run(TimerDrivenSchedulingAgent.java:132)
>       at 
> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
>       at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
>       at 
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
>       at 
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
>       at 
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
>       at 
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
>       at java.lang.Thread.run(Thread.java:745)
> Caused by: java.lang.NullPointerException: null of string in field c of 
> nifi.fullSchema
>       at 
> org.apache.avro.generic.GenericDatumWriter.npe(GenericDatumWriter.java:132)
>       at 
> org.apache.avro.generic.GenericDatumWriter.writeWithoutConversion(GenericDatumWriter.java:126)
>       at 
> org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:73)
>       at 
> org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:60)
>       at org.apache.avro.file.DataFileWriter.append(DataFileWriter.java:302)
>       ... 17 common frames omitted
> Caused by: java.lang.NullPointerException: null
> {code}
> I worked around this by changing the type of the new fields from "string" to 
> ["null", "string"] and then Avro seems to fill in the default value.
> We should be able to work around this and give the default value to Avro 
> before it gets to the point of a NPE.
> Template attached.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to