-
Notifications
You must be signed in to change notification settings - Fork 1.7k
AVRO-2123: Duration logical type Java conversion #1263
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
AVRO-2123: Duration logical type Java conversion #1263
Conversation
|
assign to me |
|
|
||
| public static class DurationConversion extends Conversion<Duration> { | ||
|
|
||
| private static final int MONTH_DAYS = 30; |
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.
A month has 28, 29, 30 or 31 days. Hardcoding a single value (31 days/month occurs more often) is basically a bug. Note that this cannot be fixed if we choose to support all possible duration values (see the conversation comments for more info).
opwvhk
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.
A Java Duration is a fixed amount of time, and cannot compensate for the varying number of days per month. A Java Period can, but cannot consider fractions of a day.
To "fix" the underlying incompatibility between an Avro duration and the Java Duration/Period classes, and also to avoid bugs with respect to leap seconds (avoided by Java because it doesn't mix days & day fractions), the conversion must disallow the combination of non-zero milliseconds with any other non-zero field. This means that either the milliseconds field must be 0, or all other fields must be 0.
Also, the conversion should accept both java.time.Duration and java.time.Period to convert to an Avro duration, and return the most appropriate one converting back (throwing an exception when both the milliseconds field and one of the other fields is non-zero).
|
Hi @robvadai |
|
As an alternative to this PR, I've opened #2520. This implements a new Java Time class |
|
Closing, as there is now an alternative implementation. |
Implementation of http://avro.apache.org/docs/current/spec.html#Duration
Can be used to serialize/deserialize to/from Java POJOs and Generic Fixed type.
Make sure you have checked all steps below.
Jira
Tests
lang/java/avro/src/test/java/org/apache/avro/TestDurationConversion.javaCommits
Documentation