-
Notifications
You must be signed in to change notification settings - Fork 2.9k
NIFI-15308 Time record field converters handle time offset #10617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
exceptionfactory
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing this issue @turcsanyip. The implementation in the Field Converter looks good, following the same basic strategy as the converter for LocalDateTime.
Although the TimeZone.setDefault() approach for testing is used in some other modules, it should be possible to avoid that and instead compare expected values.
The ObjectTimestampFieldConverterTest has a getDateTimeZoneOffset method that builds a string with a specific offset based on the current system default timezone, which is one way to evaluate the conversion, without having to call TimeZone.setOffset(). I recommend looking at that approach as opposed to changing the default TimeZone in the test method.
|
Thanks for your feedback @exceptionfactory. I updated the tests to avoid setting the default time zone at the JVM level. Actually, I was focusing on the use case where the same input data is processed in environments with different time zone settings. But the issue can also be tested by using the same runtime time zone with different input data offsets. The main point is that the JVM’s system time zone needs to be different from the input data’s offset. It does not matter in what way. I added several different time zone offsets to the tests in order to cover various cases (not only system default and UTC that can overlap and might not reveal the current issue). |
exceptionfactory
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update @turcsanyip. The tests look better without the TimeZone changes. However, the construction of the expected value is still a bit difficult to follow. In past experience, I have found this to be important when reviewing conversion code and associated expectations.
| final LocalTime expected = ZonedDateTime.of(LocalDate.EPOCH, LocalTime.parse(timeString, DateTimeFormatter.ofPattern(TIME_WITH_OFFSET_PATTERN)), ZoneId.of(offset)) | ||
| .withZoneSameInstant(ZoneId.systemDefault()) | ||
| .toLocalTime(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The levels of nesting make this declaration rather hard to follow.
On closer analysis, I think a different approach is needed.
The parsing and conversion from LocalTime to ZonedDateTime and back to LocalTime effectively do something similar to what the FieldConverter itself is doing.
The challenge is LocalTime is different based on where it is running. However, the main goal of the comparison should be that the FieldConverter shifts the hours forward or backward, based on the relative offset. The issue is that the number of hours is different based on the JVM system default zone. That's the reason for limiting the test to the offset of the system default zone, versus attempting to test other offsets.
With that background, it would help break up the declaration of each variable, as opposed to nesting the parsing and construction of different values. That should make it somewhat easier to understand how the expected value is being constructed.
I can take a closer look at providing an alternative if that would be helpful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Time-related code is not easy to read, and I actually spent a lot of time getting familiar with the existing code as well. I created an updated version in which the result of each step is assigned to variables with explicit, descriptive names. I’m wondering what you think of it.
exceptionfactory
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates @turcsanyip, I pushed a minor update to the test classes, adjusting the ordering, naming, and breaking out the ZoneOffset variable from the input string. If those changes look good to you, I will proceed with merging.
|
@exceptionfactory The code looks good. Please go ahead with merging. |
exceptionfactory
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again @turcsanyip! +1 merging
Summary
NIFI-15308
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
./mvnw clean install -P contrib-checkLicensing
LICENSEandNOTICEfilesDocumentation