Uploaded image for project: 'Apache NiFi'
  1. Apache NiFi
  2. NIFI-3861

AvroReader logical date and time conversion does not work with nullable type

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 1.2.0
    • 1.3.0
    • Extensions
    • None

    Description

      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):

      {"name":"date","type":{"type":"int","logicalType":"date"}}
      

      When AvroReader reads the logical date value, it converts the int back to java.sql.Date at AvroTypeUtil.normalizeValue 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:

      input.json
      {"date": "2017-05-10", "time": "19:55:34"}
      
      input.json
       -> ConvertRecord (JsonTreeReader/AvroRecordSetWriter)
       -> ConvertRecord (AvroRecordReader/JsonRecordSetWriter): this avro reader fails to convert with a nullable logical date.
      
      result-not_null
      [{"date":"2017-05-10","time":"19:55:34"}]
      
      result-nullable
      [{"date":"1970-01-01","time":"19:55:34"}]
      

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            ijokarumawak Koji Kawamura
            ijokarumawak Koji Kawamura
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment