NIFI-12885 Add convenience method to Record to parse DateTime objects#8502
Conversation
…ateTime` to `Record`
…-to-Record-to-parse-datetime-objects
exceptionfactory
left a comment
There was a problem hiding this comment.
Thanks for putting this together @knguyen1.
The general approach looks good on initial review. I will take a closer look soon.
Can you revert the import reordering changes? Thanks!
exceptionfactory
left a comment
There was a problem hiding this comment.
@knguyen1 The test failures on MacOS and Windows indicate a problem with the expectations for timestamp conversion across time zones.
It can be difficult to set proper expectations that will work regardless of local machine time zone, but it is very important to get these tests correct to avoid confusing runtime problems.
For example, converting from OffsetDateTime to Instant and then comparing the values is not an ideal approach due to time zone differences.
It may be helpful to scope down the number of timestamps in the provideTimestamps method to focus on differences. It is not necessary to exercise every variation of formatting, but it is more important to exercise different types of time fields in terms of year, month, day, hour, minute, second and time zone.
@exceptionfactory Okay. I scoped it down to 2 formats: |
Thanks for making the updates, unfortunately the tests are still failing: The problem is not a race condition, but the fact of the different GitHub Runners have different local time zones. Converting between UTC and local time changes the expected epoch values, so the expectations need to be written such that they work across all time zones. |
exceptionfactory
left a comment
There was a problem hiding this comment.
Thanks for the recent updates @knguyen1. Taking a closer look at getOffsetDateTime() highlights a potential problem with the helper function doing too much. It seems better to throw an exception, as opposed to defaulting the time zone. This raises a wider question about the usefulness of this particular helper method, as opposed to putting the responsibility back on the caller to know the appropriate time class to use.
nifi-commons/nifi-record/src/main/java/org/apache/nifi/serialization/record/MapRecord.java
Outdated
Show resolved
Hide resolved
…ord-to-parse-datetime-objects
|
@exceptionfactory Hopefully we are close. I added
in their own tests. In addition, the Tests should now pass regardless of system default timezones. I checked against |
exceptionfactory
left a comment
There was a problem hiding this comment.
Thanks for working through the feedback @knguyen1, the latest version looks good, and removes the ambiguity around the legacy getAsDate() method. +1 merging
Signed-off-by: David Handermann <exceptionfactory@apache.org>
Signed-off-by: David Handermann <exceptionfactory@apache.org>
Summary
NIFI-12885
Tracking
Please complete the following tracking steps prior to pull request creation.
Issue Tracking
Pull Request Tracking
NIFI-00000NIFI-00000Pull Request Formatting
mainbranchVerification
Please indicate the verification steps performed prior to pull request creation.
Build
mvn clean install -P contrib-checkLicensing
LICENSEandNOTICEfilesDocumentation