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
NIFI-8023 Added toLocalDate() and updated toDate() in DataTypeUtils #4734
Conversation
Enhanced toDate() string parsing with conditional time zone adjustment
d8ca41f
to
0a099a8
Compare
@exceptionfactory I ran some test flows and there is a regression in ConvertRecord. ConvertRecord setup:
If I run it in a UTC+ time zone, the output is one day earlier ("1970-01-04"). The other PR on this jira (#4677 by @adenes) has the same issue so I think it needs to be fixed somewhere else in the codebase (I guess where the java.sql.Date value is written from the record to string). There is one more use case which is not working. This is not a regression and might have never worked but it would be great to fix it also: ExecuteSQLRecord with Json/CSV/XML record writer (the date is one day earlier then in the database if NiFi is running in a UTC+ time zone) |
@exceptionfactory , thanks for the PR. I ran the unit tests in CET timezone, and one of the newly added tests fails:
I'll do some debugging to see what goes wrong. |
@adenes Thanks for the feedback. After looking more closely at |
Thanks for the feedback and testing @turcsanyip. I will run some additional tests using the flow configuration described. |
@turcsanyip The other use of |
6a95ff6
to
492c189
Compare
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 @exceptionfactory for improving the timezone handling here! I think there are a few additional cases that need to be taken into account. Commented inline.
...mmons/nifi-record/src/main/java/org/apache/nifi/serialization/record/util/DataTypeUtils.java
Outdated
Show resolved
Hide resolved
if (dateFormat instanceof SimpleDateFormat) { | ||
final SimpleDateFormat simpleDateFormat = (SimpleDateFormat) dateFormat; | ||
final String pattern = simpleDateFormat.toPattern(); | ||
adjustmentRequired = !pattern.contains(TIME_ZONE_PATTERN); |
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.
I don't believe this is sufficient. According to https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html, the timezone can be represented using z
, Z
, or X
, each having a different meaning. I think we have to account for all of these.
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, I adjusted the check to use a regular expression pattern for all three characters.
@markap14 Thanks for the review and additional feedback, I pushed an update to address your comments. There still appear to be some edge cases for some record-oriented processors when running NiFi in different time zones, based on running some test flows from @turcsanyip. The PR as it stands addresses the test failures for certain time zones as described in NIFI-8023 through the use of the new Additional work is probably necessary to address system time zone issues when using some of the JSON Record Readers and Writers, but perhaps it would be better to create a new issue to resolve those problems. Any additional feedback @turcsanyip or @adenes? |
@exceptionfactory , thanks for the follow-up commits. I ran the tests with CET system TZ and unfortunately some test cases fail:
Could you please have a look at them? |
Thanks @adenes I will take a look at those tests. |
@adenes After evaluating the unit tests mentioned, I found that each one was performing date conversion in order to compare the expected results. The conversion changed the expected value, which was throwing off the tests. I updated the tests and confirmed successful test completion with the CET time zone. |
9201d96
to
d943e92
Compare
…prior to comparing expected results
d943e92
to
e6b45b7
Compare
Closing in favor of implementation in #4781 |
Description of PR
NIFI-8023 Added
DataTypeUtils.toLocalDate()
method for use inAvroTypeUtil
to determine epoch days when logical date types enabled.Updated
DataTypeUtils.toDate()
with newparseDate()
method that evaluates the format pattern ofjava.text.SimpleDateFormat
to determine whether a Time Zone fieldZ
is present in the pattern. This conditional adjustment is necessary because absence of the Time Zone Field in ajava.text.SimpleDateFormat
pattern definition produces different results depending on the system time zone configuration.This approach resolves a latent issue when using the
DataTypeUtils.toDate()
method to parse a string that does not contain any time zone information. Changes toDataTypeUtils.toDate()
and updates to unit tests in referencing classes indicate the expected behavior.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
main
)?Is your initial contribution a single, squashed commit? Additional commits in response to PR reviewer feedback should be made on this branch and pushed to allow change tracking. Do not
squash
or use--force
when pushing to allow for clean monitoring of changes.For code changes:
mvn -Pcontrib-check clean install
at the rootnifi
folder?LICENSE
file, including the mainLICENSE
file undernifi-assembly
?NOTICE
file, including the mainNOTICE
file found undernifi-assembly
?.displayName
in addition to .name (programmatic access) for each of the new properties?For documentation related changes:
Note:
Please ensure that once the PR is submitted, you check GitHub Actions CI for build issues and submit an update to your PR as soon as possible.