You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "m1a2st (via GitHub)" <gi...@apache.org> on 2025/01/18 16:04:33 UTC
[PR] KAFKA-18585 Fix fail test ValuesTest#shouldConvertDateValues [kafka]
m1a2st opened a new pull request, #18611:
URL: https://github.com/apache/kafka/pull/18611
Jira: https://issues.apache.org/jira/browse/KAFKA-18585
### Committer Checklist (excluded from commit message)
- [ ] Verify design and implementation
- [ ] Verify test coverage and CI build status
- [ ] Verify documentation (including upgrade notes)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18585 Fix fail test ValuesTest#shouldConvertDateValues [kafka]
Posted by "AndrewJSchofield (via GitHub)" <gi...@apache.org>.
AndrewJSchofield commented on code in PR #18611:
URL: https://github.com/apache/kafka/pull/18611#discussion_r1923511981
##########
connect/api/src/test/java/org/apache/kafka/connect/data/ValuesTest.java:
##########
@@ -901,8 +902,12 @@ public void shouldConvertDateValues() {
assertEquals(currentDate, d2);
// ISO8601 strings - accept a string matching pattern "yyyy-MM-dd"
+ // Values.convertToDate convert the "yyyy-MM-dd" string will miss the time and timezone information,
+ // so we need to adjust the date from the current timezone to UTC0
+ TimeZone tz = TimeZone.getDefault();
+ java.util.Date currentDate3 = new java.util.Date(current.getTime() - currentMillis - tz.getOffset(current.getTime()));
java.util.Date d3 = Values.convertToDate(Date.SCHEMA, LocalDate.ofEpochDay(days).format(DateTimeFormatter.ISO_LOCAL_DATE));
- assertEquals(currentDate, d3);
Review Comment:
@divijvaidya is correct that `java.util.Date` is timezone-agnostic. However, the `LocalDate` here is timezone-ignorant and the timezone offset is not accounted for. The methods available for manipulating dates and times with timezones are a bit limited, and I think that it's best to stop using `LocalDate.ofEpochDay(long)` and moving to `LocalDateTime.ofInstant(Instant, ZoneId)`.
I suggest replacing the first line of the method with:
```
LocalDateTime localTime = LocalDateTime.now();
LocalDateTime localTimeTruncated = localTime.truncatedTo(ChronoUnit.DAYS);
ZoneOffset zoneOffset = ZoneId.systemDefault().getRules().getOffset(localTime);
java.util.Date current = new java.util.Date(localTime.toEpochSecond(zoneOffset) * 1000);
```
And then the check becomes:
```
// ISO8601 strings - accept a string matching pattern "yyyy-MM-dd"
java.util.Date d3 = Values.convertToDate(Date.SCHEMA, LocalDate.ofEpochDay(days).format(DateTimeFormatter.ISO_LOCAL_DATE));
LocalDateTime date3 = LocalDateTime.ofInstant(Instant.ofEpochMilli(d3.getTime()), ZoneId.systemDefault());
assertEquals(localTimeTruncated, date3);
```
I tried this with various timezones locally and it seems to work properly. Essentially, the time information is discarded in a way that a person in the timezone would expect looking at a clock.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18585 Fix fail test ValuesTest#shouldConvertDateValues [kafka]
Posted by "m1a2st (via GitHub)" <gi...@apache.org>.
m1a2st commented on code in PR #18611:
URL: https://github.com/apache/kafka/pull/18611#discussion_r1923514351
##########
connect/api/src/test/java/org/apache/kafka/connect/data/ValuesTest.java:
##########
@@ -901,8 +902,12 @@ public void shouldConvertDateValues() {
assertEquals(currentDate, d2);
// ISO8601 strings - accept a string matching pattern "yyyy-MM-dd"
+ // Values.convertToDate convert the "yyyy-MM-dd" string will miss the time and timezone information,
+ // so we need to adjust the date from the current timezone to UTC0
+ TimeZone tz = TimeZone.getDefault();
+ java.util.Date currentDate3 = new java.util.Date(current.getTime() - currentMillis - tz.getOffset(current.getTime()));
java.util.Date d3 = Values.convertToDate(Date.SCHEMA, LocalDate.ofEpochDay(days).format(DateTimeFormatter.ISO_LOCAL_DATE));
- assertEquals(currentDate, d3);
Review Comment:
We can observe that when `java.util.Date` performs equals comparison, it takes timezone into account. Therefore, the equals comparison will yield different results under different timezones. In my case, being in UTC+8, it results in an 8-hour difference.
https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/util/Date.java#L1210
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18585 Fix fail test ValuesTest#shouldConvertDateValues [kafka]
Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on code in PR #18611:
URL: https://github.com/apache/kafka/pull/18611#discussion_r2337551534
##########
connect/api/src/test/java/org/apache/kafka/connect/data/ValuesTest.java:
##########
@@ -901,8 +903,10 @@ public void shouldConvertDateValues() {
assertEquals(currentDate, d2);
// ISO8601 strings - accept a string matching pattern "yyyy-MM-dd"
+ LocalDateTime localTimeTruncated = localTime.truncatedTo(ChronoUnit.DAYS);
java.util.Date d3 = Values.convertToDate(Date.SCHEMA, LocalDate.ofEpochDay(days).format(DateTimeFormatter.ISO_LOCAL_DATE));
Review Comment:
#20520
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18585 Fix fail test ValuesTest#shouldConvertDateValues [kafka]
Posted by "AndrewJSchofield (via GitHub)" <gi...@apache.org>.
AndrewJSchofield commented on code in PR #18611:
URL: https://github.com/apache/kafka/pull/18611#discussion_r2333801620
##########
connect/api/src/test/java/org/apache/kafka/connect/data/ValuesTest.java:
##########
@@ -901,8 +903,10 @@ public void shouldConvertDateValues() {
assertEquals(currentDate, d2);
// ISO8601 strings - accept a string matching pattern "yyyy-MM-dd"
+ LocalDateTime localTimeTruncated = localTime.truncatedTo(ChronoUnit.DAYS);
java.util.Date d3 = Values.convertToDate(Date.SCHEMA, LocalDate.ofEpochDay(days).format(DateTimeFormatter.ISO_LOCAL_DATE));
Review Comment:
I suggest the mentee does it and then I'll review. Thanks for following up on this.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18585 Fix fail test ValuesTest#shouldConvertDateValues [kafka]
Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on code in PR #18611:
URL: https://github.com/apache/kafka/pull/18611#discussion_r2333759126
##########
connect/api/src/test/java/org/apache/kafka/connect/data/ValuesTest.java:
##########
@@ -901,8 +903,10 @@ public void shouldConvertDateValues() {
assertEquals(currentDate, d2);
// ISO8601 strings - accept a string matching pattern "yyyy-MM-dd"
+ LocalDateTime localTimeTruncated = localTime.truncatedTo(ChronoUnit.DAYS);
java.util.Date d3 = Values.convertToDate(Date.SCHEMA, LocalDate.ofEpochDay(days).format(DateTimeFormatter.ISO_LOCAL_DATE));
Review Comment:
yes! we are on the same page!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18585 Fix fail test ValuesTest#shouldConvertDateValues [kafka]
Posted by "AndrewJSchofield (via GitHub)" <gi...@apache.org>.
AndrewJSchofield merged PR #18611:
URL: https://github.com/apache/kafka/pull/18611
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18585 Fix fail test ValuesTest#shouldConvertDateValues [kafka]
Posted by "m1a2st (via GitHub)" <gi...@apache.org>.
m1a2st commented on code in PR #18611:
URL: https://github.com/apache/kafka/pull/18611#discussion_r1923759576
##########
connect/api/src/test/java/org/apache/kafka/connect/data/ValuesTest.java:
##########
@@ -901,8 +902,12 @@ public void shouldConvertDateValues() {
assertEquals(currentDate, d2);
// ISO8601 strings - accept a string matching pattern "yyyy-MM-dd"
+ // Values.convertToDate convert the "yyyy-MM-dd" string will miss the time and timezone information,
+ // so we need to adjust the date from the current timezone to UTC0
+ TimeZone tz = TimeZone.getDefault();
+ java.util.Date currentDate3 = new java.util.Date(current.getTime() - currentMillis - tz.getOffset(current.getTime()));
java.util.Date d3 = Values.convertToDate(Date.SCHEMA, LocalDate.ofEpochDay(days).format(DateTimeFormatter.ISO_LOCAL_DATE));
- assertEquals(currentDate, d3);
Review Comment:
Sure, using `LocalDateTime` makes sense to me.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18585 Fix fail test ValuesTest#shouldConvertDateValues [kafka]
Posted by "divijvaidya (via GitHub)" <gi...@apache.org>.
divijvaidya commented on code in PR #18611:
URL: https://github.com/apache/kafka/pull/18611#discussion_r1922774801
##########
connect/api/src/test/java/org/apache/kafka/connect/data/ValuesTest.java:
##########
@@ -901,8 +902,12 @@ public void shouldConvertDateValues() {
assertEquals(currentDate, d2);
// ISO8601 strings - accept a string matching pattern "yyyy-MM-dd"
+ // Values.convertToDate convert the "yyyy-MM-dd" string will miss the time and timezone information,
+ // so we need to adjust the date from the current timezone to UTC0
+ TimeZone tz = TimeZone.getDefault();
+ java.util.Date currentDate3 = new java.util.Date(current.getTime() - currentMillis - tz.getOffset(current.getTime()));
java.util.Date d3 = Values.convertToDate(Date.SCHEMA, LocalDate.ofEpochDay(days).format(DateTimeFormatter.ISO_LOCAL_DATE));
- assertEquals(currentDate, d3);
Review Comment:
I must be missing something here so please help me understand the following:
Java's util.Date is timezone agnostic (it's always epochs in UTC timezone) until you want to print it (where you can format it). Hence, the currentDate here should already be in UTC timezone. And the actual value from `LocalDate.ofEpochDay(days).format(DateTimeFormatter.ISO_LOCAL_DATE)` should also be in UTC. So, where is the disconnect here?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18585 Fix fail test ValuesTest#shouldConvertDateValues [kafka]
Posted by "AndrewJSchofield (via GitHub)" <gi...@apache.org>.
AndrewJSchofield commented on code in PR #18611:
URL: https://github.com/apache/kafka/pull/18611#discussion_r2333529829
##########
connect/api/src/test/java/org/apache/kafka/connect/data/ValuesTest.java:
##########
@@ -901,8 +903,10 @@ public void shouldConvertDateValues() {
assertEquals(currentDate, d2);
// ISO8601 strings - accept a string matching pattern "yyyy-MM-dd"
+ LocalDateTime localTimeTruncated = localTime.truncatedTo(ChronoUnit.DAYS);
java.util.Date d3 = Values.convertToDate(Date.SCHEMA, LocalDate.ofEpochDay(days).format(DateTimeFormatter.ISO_LOCAL_DATE));
Review Comment:
Were you thinking something like this?
```
java.util.Date d3 = Values.convertToDate(Date.SCHEMA, localTime.format(DateTimeFormatter.ISO_LOCAL_DATE));
LocalDateTime date3 = LocalDateTime.ofInstant(Instant.ofEpochMilli(d3.getTime()), ZoneId.systemDefault());
LocalDateTime localTimeTruncated = localTime.truncatedTo(ChronoUnit.DAYS);
assertEquals(localTimeTruncated, date3);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18585 Fix fail test ValuesTest#shouldConvertDateValues [kafka]
Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on code in PR #18611:
URL: https://github.com/apache/kafka/pull/18611#discussion_r2318146619
##########
connect/api/src/test/java/org/apache/kafka/connect/data/ValuesTest.java:
##########
@@ -901,8 +903,10 @@ public void shouldConvertDateValues() {
assertEquals(currentDate, d2);
// ISO8601 strings - accept a string matching pattern "yyyy-MM-dd"
+ LocalDateTime localTimeTruncated = localTime.truncatedTo(ChronoUnit.DAYS);
java.util.Date d3 = Values.convertToDate(Date.SCHEMA, LocalDate.ofEpochDay(days).format(DateTimeFormatter.ISO_LOCAL_DATE));
Review Comment:
Sorry for raising this question on the merged PR. This test case is intended to ensure the parser works for `ISO8601`. That said, is it really necessary to use `days` here? It seems to me that relying on `days` could introduce a risk: since the granularity is at the "day" level, it my case an off-by-one issue if the local time falls on a different "day" than UTC. For example, when the local time is 9/1 01:00 (UTC+8)
Perhaps we could instead use `localTime.format(DateTimeFormatter.ISO_LOCAL_DATE)` to avoid the conversion risk
@AndrewJSchofield WDYT?
@AndrewJSchofield WDYT?
##########
connect/api/src/test/java/org/apache/kafka/connect/data/ValuesTest.java:
##########
@@ -901,8 +903,10 @@ public void shouldConvertDateValues() {
assertEquals(currentDate, d2);
// ISO8601 strings - accept a string matching pattern "yyyy-MM-dd"
+ LocalDateTime localTimeTruncated = localTime.truncatedTo(ChronoUnit.DAYS);
java.util.Date d3 = Values.convertToDate(Date.SCHEMA, LocalDate.ofEpochDay(days).format(DateTimeFormatter.ISO_LOCAL_DATE));
Review Comment:
Sorry for raising this question on the merged PR. This test case is intended to ensure the parser works for `ISO8601`. That said, is it really necessary to use `days` here? It seems to me that relying on `days` could introduce a risk: since the granularity is at the "day" level, it my case an off-by-one issue if the local time falls on a different "day" than UTC. For example, when the local time is 9/1 01:00 (UTC+8)
Perhaps we could instead use `localTime.format(DateTimeFormatter.ISO_LOCAL_DATE)` to avoid the conversion risk
@AndrewJSchofield WDYT?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18585 Fix fail test ValuesTest#shouldConvertDateValues [kafka]
Posted by "AndrewJSchofield (via GitHub)" <gi...@apache.org>.
AndrewJSchofield commented on PR #18611:
URL: https://github.com/apache/kafka/pull/18611#issuecomment-2604193018
Digging into this further, I would say that the behaviour for some of these tests with respect to timezones is incorrect, or at least unwise. I am not convinced by this patch, but I will dig into it further and give a more concrete answer shortly.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18585 Fix fail test ValuesTest#shouldConvertDateValues [kafka]
Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on code in PR #18611:
URL: https://github.com/apache/kafka/pull/18611#discussion_r2333762523
##########
connect/api/src/test/java/org/apache/kafka/connect/data/ValuesTest.java:
##########
@@ -901,8 +903,10 @@ public void shouldConvertDateValues() {
assertEquals(currentDate, d2);
// ISO8601 strings - accept a string matching pattern "yyyy-MM-dd"
+ LocalDateTime localTimeTruncated = localTime.truncatedTo(ChronoUnit.DAYS);
java.util.Date d3 = Values.convertToDate(Date.SCHEMA, LocalDate.ofEpochDay(days).format(DateTimeFormatter.ISO_LOCAL_DATE));
Review Comment:
Do you have a free cycle? If not, my mentee can file a minor patch based on your approach.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18585 Fix fail test ValuesTest#shouldConvertDateValues [kafka]
Posted by "AndrewJSchofield (via GitHub)" <gi...@apache.org>.
AndrewJSchofield commented on code in PR #18611:
URL: https://github.com/apache/kafka/pull/18611#discussion_r2333362219
##########
connect/api/src/test/java/org/apache/kafka/connect/data/ValuesTest.java:
##########
@@ -901,8 +903,10 @@ public void shouldConvertDateValues() {
assertEquals(currentDate, d2);
// ISO8601 strings - accept a string matching pattern "yyyy-MM-dd"
+ LocalDateTime localTimeTruncated = localTime.truncatedTo(ChronoUnit.DAYS);
java.util.Date d3 = Values.convertToDate(Date.SCHEMA, LocalDate.ofEpochDay(days).format(DateTimeFormatter.ISO_LOCAL_DATE));
Review Comment:
@chia7712 Yes, I think you are totally right. There will be an off-by-one issue if the local time falls on a different day than UTC.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18585 Fix fail test ValuesTest#shouldConvertDateValues [kafka]
Posted by "m1a2st (via GitHub)" <gi...@apache.org>.
m1a2st commented on code in PR #18611:
URL: https://github.com/apache/kafka/pull/18611#discussion_r1923514351
##########
connect/api/src/test/java/org/apache/kafka/connect/data/ValuesTest.java:
##########
@@ -901,8 +902,12 @@ public void shouldConvertDateValues() {
assertEquals(currentDate, d2);
// ISO8601 strings - accept a string matching pattern "yyyy-MM-dd"
+ // Values.convertToDate convert the "yyyy-MM-dd" string will miss the time and timezone information,
+ // so we need to adjust the date from the current timezone to UTC0
+ TimeZone tz = TimeZone.getDefault();
+ java.util.Date currentDate3 = new java.util.Date(current.getTime() - currentMillis - tz.getOffset(current.getTime()));
java.util.Date d3 = Values.convertToDate(Date.SCHEMA, LocalDate.ofEpochDay(days).format(DateTimeFormatter.ISO_LOCAL_DATE));
- assertEquals(currentDate, d3);
Review Comment:
We can observe that when java.util.Date performs equals comparison, it takes timezone into account. Therefore, the equals comparison will yield different results under different timezones. In my case, being in UTC+8, it results in an 8-hour difference.
https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/util/Date.java#L1210
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18585 Fix fail test ValuesTest#shouldConvertDateValues [kafka]
Posted by "AndrewJSchofield (via GitHub)" <gi...@apache.org>.
AndrewJSchofield commented on code in PR #18611:
URL: https://github.com/apache/kafka/pull/18611#discussion_r1922780851
##########
connect/api/src/test/java/org/apache/kafka/connect/data/ValuesTest.java:
##########
@@ -901,8 +902,12 @@ public void shouldConvertDateValues() {
assertEquals(currentDate, d2);
// ISO8601 strings - accept a string matching pattern "yyyy-MM-dd"
+ // Values.convertToDate convert the "yyyy-MM-dd" string will miss the time and timezone information,
+ // so we need to adjust the date from the current timezone to UTC0
+ TimeZone tz = TimeZone.getDefault();
+ java.util.Date currentDate3 = new java.util.Date(current.getTime() - currentMillis - tz.getOffset(current.getTime()));
java.util.Date d3 = Values.convertToDate(Date.SCHEMA, LocalDate.ofEpochDay(days).format(DateTimeFormatter.ISO_LOCAL_DATE));
- assertEquals(currentDate, d3);
Review Comment:
Yes, I'm not sure either. But I can believe it's possible to write a test that is timezone-dependent.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18585 Fix fail test ValuesTest#shouldConvertDateValues [kafka]
Posted by "m1a2st (via GitHub)" <gi...@apache.org>.
m1a2st commented on PR #18611:
URL: https://github.com/apache/kafka/pull/18611#issuecomment-2602726756
Hello @AndrewJSchofield, if you have free cycle, PTAL
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org