clickhouse-java icon indicating copy to clipboard operation
clickhouse-java copied to clipboard

Query settings session_timezone not being applied

Open tecpcarrier opened this issue 1 year ago • 3 comments

Describe the bug

Clickhouse allows user to set query to multiple level including at the query level. When the setting session_timezone is set in dbeaver , the setting is not being picked up. I have looked at this issue #604 where the timezone is set correctly for toDateTime but it does not seem to be the case when using this setting. Whenever I use session_timezone, the datetime uses the wrong timezone.

image

In this query, the date should be identical to the second column not the third. Running it directly using clickhouse-client, the result of this query should be the following:

image

By changing the session_timezone, the value in the first column should change to adapt to the new timezone.

Configuration

ClickHouse server

  • ClickHouse Server version: 23.8.2.7
  • Statement:
WITH temp AS
    (
        SELECT 1696431276 AS date
    )
SELECT
    toDateTime(date),
    toDateTime(date, 'America/New_York'),
    toDateTime(date, 'UTC')
FROM temp
SETTINGS session_timezone = 'America/Vancouver'

tecpcarrier avatar Oct 04 '23 15:10 tecpcarrier

Hey any workaround @tecpcarrier ? I am having the same issue, and it's quite confusing since the following test is doing just fine with the JDBC...

SELECT toDateTime('2023-01-01 10:15:20') SETTINGS session_timezone = 'Etc/GMT+5'

image

mohaidoss avatar Feb 29 '24 11:02 mohaidoss

We are experiencing same issue. Seems like SETTINGS session_timezone = 'Etc/GMT+5' has no effect on result.

vladaman avatar May 02 '24 12:05 vladaman

The reason is in Clickhouse server

  • https://github.com/ClickHouse/ClickHouse/issues/63359

den-crane avatar May 03 '24 20:05 den-crane

@den-crane seems like the bug is fixed on versions >= 23.8 ?

mohaidoss avatar Jul 15 '24 07:07 mohaidoss

@mohaidoss There is a bug on client side - value from the server timezone header is not applied to results (only for RowBinary*) I'm working on the fix.

chernser avatar Jul 22 '24 19:07 chernser

Client today doesn't read X-Server-Timezone from a response. The toDateTime('2023-10-04 10:54:36') will be in server or session timezone and thus no conversion should be:

SELECT
    toDateTime('2023-10-04 10:54:36'),
    serverTimezone(),
    timezone(),
    toDateTime('2023-10-04 10:54:36', 'UTC')
SETTINGS session_timezone = 'America/Los_Angeles'

Query id: d78c4447-fe88-40e4-9a61-7033f2069cb2

   ┌─toDateTime('2023-10-04 10:54:36')─┬─serverTimezone()─┬─timezone()──────────┬─toDateTime('2023-10-04 10:54:36', 'UTC')─┐
1. │               2023-10-04 10:54:36 │ UTC              │ America/Los_Angeles │                      2023-10-04 10:54:36 │
   └───────────────────────────────────┴──────────────────┴─────────────────────┴──────────────────────────────────────────┘

After the fix about the header client would convert all DateTime values that come without an offset into server timezone that is returned in response. However it will not affect values that have timezone already. And this behavior will work only if client is configured to use server timezone.

chernser avatar Jul 23 '24 20:07 chernser

Thats Exciting @chernser. Let le know if I can be of help :)

mohaidoss avatar Jul 23 '24 20:07 mohaidoss