-
Notifications
You must be signed in to change notification settings - Fork 2.9k
NIFI-15305 Fix Date Time conversion for floating point as string #10697
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
- Added check for integral numbers greater than expected number of seconds for year 10,000 and handled as milliseconds
pvillard31
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.
LGTM, left some minor comments, not blockers.
| private static final long MICROSECOND_MULTIPLIER = 1_000; | ||
| private static final long MILLISECOND_MULTIPLIER = 1_000_000; |
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.
Thoughts about using something like MICROS_TO_NANOS and FRACTION_TO_MICROS_SECONDS to be more self-explanatory?
|
|
||
| private LocalDateTime toLocalDateTime(final long epochSeconds, final long nanosPastSecond) { | ||
| final Instant instant = Instant.ofEpochSecond(epochSeconds).plusNanos(nanosPastSecond); | ||
| private LocalDateTime convertIntegralFractional(final long integral, final double fractional) { |
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'd add a comment to explain the dual case logic. Could also be an in-line comment.
| private LocalDateTime convertIntegralFractional(final long integral, final double fractional) { | |
| /** | |
| * Convert integral and fractional components to LocalDateTime. | |
| * | |
| * Large integral values (beyond year 10,000 in seconds) indicate the input | |
| * is in milliseconds, with the fractional part representing microseconds. | |
| * Smaller integral values are treated as seconds, with the fractional part | |
| * representing the fraction of a second (converted to microseconds). | |
| * | |
| * Example: 1765056655230.746 → 1765056655230 ms + 746 µs | |
| * Example: 1707238288.351567 → 1707238288 s + 351567 µs | |
| */ | |
| private LocalDateTime convertIntegralFractional(final long integral, final double fractional) { |
|
Thanks for the review @pvillard31, I pushed an update adjusting the variable naming and adding some clarifying comments on the implementation. |
Summary
NIFI-15305 Corrects
StringtoLocalDateTimeconversion for floating point numbers represented as strings.The current implementation checks
longnumbers for values larger than the year 10,000, but does not implement a similar check for floating point numbers represented as strings.The corrected approach checks the integral part of a floating point number for values larger than the year 10,000 in seconds, and then handles the number as epoch milliseconds. The parsing strategy also handles the fractional part as either the number of microseconds or the number of milliseconds.
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