-
Notifications
You must be signed in to change notification settings - Fork 3
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
Timezone support #5
Conversation
There have been requests from users to support date/time partition in the S3/GCP/Azure sink with a specific timezone. The code changes brings the timezone configuration as an optional setting. When epoch configuration is involved, changing the timezone to non-UTC yields an error. Removes the check plugin since the jar dependency is built with a newer JVM version and fails the build.
src/main/java/io/lenses/connect/smt/header/InsertWallclock.java
Outdated
Show resolved
Hide resolved
src/main/java/io/lenses/connect/smt/header/InsertWallclockDateTimePart.java
Show resolved
Hide resolved
@@ -81,7 +92,9 @@ public R apply(R r) { | |||
return null; | |||
} | |||
|
|||
final String value = valueExtractorF.apply(instantF.get()); | |||
Instant now = instantF.get(); |
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.
how about nowSupplier
or nowFunction
instead of instantF
?
src/main/java/io/lenses/connect/smt/header/InsertWallclockDateTimePart.java
Outdated
Show resolved
Hide resolved
src/main/java/io/lenses/connect/smt/header/InsertRollingWallclock.java
Outdated
Show resolved
Hide resolved
src/main/java/io/lenses/connect/smt/header/TimestampConverter.java
Outdated
Show resolved
Hide resolved
result.set(Calendar.SECOND, 0); | ||
result.set(Calendar.MILLISECOND, 0); | ||
return result.getTime(); | ||
ZonedDateTime truncated = |
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 may be missing a point here but why not just:
ZonedDateTime.ofInstant(orig.toInstant(), config.targetTimeZoneId);
or ZoneOffset.UTC.normalized()
when you need UTC? Cause here you pass two zones - one from config and second is UTC.
But it's still much better than what was there before the change ;)
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 translator is responsible for only taking the date part of the incoming Date.
So:
- orig.toInstant().atZone(config.targetTimeZoneId).toLocalDate(): extracts the date based on the configured timezone
- LocalTime.MIDNIGHT: it's all about the 0 hour, 0 minute, 0 second, etc
- UTC: at this point we don't want another timezone translation because on 01-01 2024 0:0:0 Chicago time would be still in 2023
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 see the point now, thanks! But IMO it's still too much of a hassle and could be more readable. My proposition:
ZonedDateTime truncated = ZonedDateTime.ofInstant(orig.toInstant(), config.targetTimeZoneId).truncatedTo(ChronoUnit.DAYS);
return Date.from(truncated.toInstant());
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 option you shared yields incorrect results. in this case it will return the data as of 7am 01/01/1970 - see test testSchemalessTimestampToDateOnNonUTC
result.set(Calendar.MILLISECOND, origCalendar.get(Calendar.MILLISECOND)); | ||
return result.getTime(); | ||
ZonedDateTime zonedDateTime = orig.toInstant().atZone(config.targetTimeZoneId); | ||
return Date.from( |
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.
same as above :)
ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(orig.toInstant(), config.targetTimeZoneId);
return Date.from(zonedDateTime.toInstant());
src/main/java/io/lenses/connect/smt/header/TimestampConverter.java
Outdated
Show resolved
Hide resolved
Map<String, String> configs = new HashMap<>(); | ||
configs.put("header.name", "wallclock"); | ||
configs.put("date.time.part", "year"); | ||
configs.put("timezone", "Asia/Kolkata"); |
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.
MINOR: it's nice to pass comment with time difference for better understanding e.g.
String kolkataTimezone = "Asia/Kolkata"; // Kolkata is GMT+5:30 which makes it 2021 there.
configs.put("timezone", kolkataTimezone);
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.
Wouldn't the code assertion infer:
Kolkata is GMT+5:30 which makes it 2021 there.
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 corrected my code :) Comment is one way to make developer know that TimeZone difference will cause Year to flip. Another is to add message to assertion e.g.
assertEquals("2021", transformed.headers().lastWithName("wallclock").value(), "Year should flip as we calculate it for Kolkata Timezone");
There have been requests from users to support date/time partition in the S3/GCP/Azure sink with a specific timezone. The code changes brings the timezone configuration as an optional setting. When epoch configuration is involved, changing the timezone to non-UTC yields an error.
Removes the check plugin since the jar dependency is built with a newer JVM version and fails the build.