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

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

GitHub user ijokarumawak opened a pull request:

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

    NIFI-3861: AvroTypeUtil used different constant.

    Previous fix #1779 refactored the way to check Logical type to use string 
constants.
    One of those refactoring used wrong constant mistakenly in normalizeValue 
method.
    
    Fortunately, this defect is harmless since even though normalizeValue did 
not convert int to Time, DataTypeUtils.convertType does the same conversion.
    
    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:
    - [x] Is there a JIRA ticket associated with this PR? Is it referenced 
         in the commit message?
    
    - [x] 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.
    
    - [x] Has your PR been rebased against the latest commit within the target 
branch (typically master)?
    
    - [x] 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/ijokarumawak/nifi nifi-3861-2

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

    https://github.com/apache/nifi/pull/1782.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 #1782
    
----

----


> AvroReader logical date and time conversion does not work with nullable type
> ----------------------------------------------------------------------------
>
>                 Key: NIFI-3861
>                 URL: https://issues.apache.org/jira/browse/NIFI-3861
>             Project: Apache NiFi
>          Issue Type: Bug
>          Components: Extensions
>            Reporter: Koji Kawamura
>            Assignee: Koji Kawamura
>         Attachments: NIFI-3861.xml
>
>
> A Date field can be defined as logical 'date' type in Avro schema like this, 
> the value is stored as int physically, but logically annotated this is a 
> date. The stored value represents days after Unix epoch (1970-01-01):
> {code}
> {"name":"date","type":{"type":"int","logicalType":"date"}}
> {code}
> When AvroReader reads the logical date value, it converts the int back to 
> java.sql.Date at 
> [AvroTypeUtil.normalizeValue|https://github.com/apache/nifi/blob/master/nifi-nar-bundles/nifi-extension-utils/nifi-record-utils/nifi-avro-record-utils/src/main/java/org/apache/nifi/avro/AvroTypeUtil.java#L441]
>  method. However, if the field is also a nullable (union with null), the 
> conversion is skipped and the original int is returned.
> Then the int will be treated as milliseconds from Unix epoch by other 
> RecordWriter such as JsonRecordSetWriter.
> Here is a reproducible flow:
> {code: title=input.json}
> {"date": "2017-05-10", "time": "19:55:34"}
> {code}
> {code}
> input.json
>  -> ConvertRecord (JsonTreeReader/AvroRecordSetWriter)
>  -> ConvertRecord (AvroRecordReader/JsonRecordSetWriter): this avro reader 
> fails to convert with a nullable logical date.
> {code}
> {code: title=result-not_null}
> [{"date":"2017-05-10","time":"19:55:34"}]
> {code}
> {code: title=result-nullable}
> [{"date":"1970-01-01","time":"19:55:34"}]
> {code}



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

Reply via email to