Skip to content
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

Copy timezone from response if differs from config server_time_zone #1738

Merged
merged 17 commits into from
Aug 13, 2024

Conversation

chernser
Copy link
Contributor

@chernser chernser commented Jul 18, 2024

Summary

By default java client will issue a pre-flight select serverTimezone() when creating a new connection and returned timezone will be used for conversion of returned DateTime values.
Server returns its timezone in X-ClickHouse-Timezone header. This timezone is most accurate because it respects session_timezone setting. But this header value is not always used what causes double convertion to incorrect value.

For example,
select now() returns 2024-07-18 20:30:58 for server in UTC timezone
select now() settings session_timezone='America/Los_Angeles' would return 2024-07-18 13:30:58 and X-ClickHouse-Timezone: America/Los_Angeles.
But java client will parse that value into LocalDateTime [2024-07-18 20:30:58] assuming that server timezone is UTC

This PR makes Client check timezone from the header and override it in config for current query (that config will be used later by deserializer to convert date/time).

Closes #1464

Checklist

Delete items not relevant to your PR:

  • Unit and integration tests covering the common scenarios were added
  • A human-readable description of the changes was provided to include in CHANGELOG
  • For significant changes, documentation in https://github.com/ClickHouse/clickhouse-docs was updated with further explanations or tutorials

@chernser chernser requested review from mzitnik and Paultagoras July 22, 2024 14:57
Assert.assertTrue(Duration.between(serverTimeNow, nowAtTimezone).abs().getSeconds() < 60,
"Server time (" + serverTimeNow + " ) should be close to the client time (" + nowAtTimezone + ")");
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add a daylight saving test as well

@chernser chernser added this to the 0.6.4 Release milestone Jul 23, 2024
@chernser chernser marked this pull request as draft July 23, 2024 21:02
@chernser chernser marked this pull request as ready for review July 31, 2024 20:51
@chernser chernser requested a review from slvrtrn July 31, 2024 20:51
@chernser chernser marked this pull request as draft July 31, 2024 22:05
@chernser chernser marked this pull request as ready for review August 13, 2024 14:08
ZonedDateTime serverNowZoned = rs.getObject(1, ZonedDateTime.class);


System.out.println("serverNow: " + serverNow + " tzTime: " + tzTime);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want these println messages?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to leave them, but I agree with you - tests should be clean.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

beside no assertions - shame on me

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
41.2% Coverage on New Code (required ≥ 80%)

See analysis details on SonarCloud

@chernser chernser requested a review from Paultagoras August 13, 2024 18:37
@chernser chernser merged commit 059fc07 into main Aug 13, 2024
65 of 66 checks passed
@chernser chernser deleted the fix_timezone_in_response_header branch August 13, 2024 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Query settings session_timezone not being applied
3 participants