Merge pull request #63377 from zvonand/fix-x-clickhouse-timezone

Fix `X-ClickHouse-Timezone` header with `session_timezone`
This commit is contained in:
Alexander Gololobov 2024-05-07 06:10:28 +00:00 committed by GitHub
commit 0162395dd5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 30 additions and 0 deletions

View File

@ -1522,9 +1522,16 @@ void executeQuery(
if (output_format)
handle_exception_in_output_format(*output_format, format_name, context, output_format_settings);
}
/// The timezone was already set before query was processed,
/// But `session_timezone` setting could be modified in the query itself, so we update the value.
result_details.timezone = DateLUT::instance().getTimeZone();
throw;
}
/// The timezone was already set before query was processed,
/// But `session_timezone` setting could be modified in the query itself, so we update the value.
result_details.timezone = DateLUT::instance().getTimeZone();
auto & pipeline = streams.pipeline;
std::unique_ptr<WriteBuffer> compressed_buffer;

View File

@ -19,3 +19,9 @@
< Content-Type: application/octet-stream
< X-ClickHouse-Format: RowBinary
< X-ClickHouse-Timezone: CLICKHOUSE_TIMEZONE
< X-ClickHouse-Timezone: Europe/Berlin
< X-ClickHouse-Timezone: Africa/Cairo
< X-ClickHouse-Timezone: Europe/Berlin
< X-ClickHouse-Timezone: America/Denver
< X-ClickHouse-Timezone: Europe/Lisbon
< X-ClickHouse-Timezone: Europe/Lisbon

View File

@ -13,3 +13,16 @@ ${CLICKHOUSE_CURL} -vsS "${CLICKHOUSE_URL}" --data-binary @- <<< "SELECT 1 FORMA
${CLICKHOUSE_CURL} -vsS "${CLICKHOUSE_URL}" --data-binary @- <<< "SELECT 1 FORMAT Vertical" 2>&1 | grep -e '< Content-Type' -e '< X-ClickHouse-Format' -e '< X-ClickHouse-Timezone' | sed "s|$CLICKHOUSE_TIMEZONE_ESCAPED|CLICKHOUSE_TIMEZONE|" | sed 's/\r$//' | sort;
${CLICKHOUSE_CURL} -vsS "${CLICKHOUSE_URL}" --data-binary @- <<< "SELECT 1 FORMAT Native" 2>&1 | grep -e '< Content-Type' -e '< X-ClickHouse-Format' -e '< X-ClickHouse-Timezone' | sed "s|$CLICKHOUSE_TIMEZONE_ESCAPED|CLICKHOUSE_TIMEZONE|" | sed 's/\r$//' | sort;
${CLICKHOUSE_CURL} -vsS "${CLICKHOUSE_URL}" --data-binary @- <<< "SELECT 1 FORMAT RowBinary" 2>&1 | grep -e '< Content-Type' -e '< X-ClickHouse-Format' -e '< X-ClickHouse-Timezone' | sed "s|$CLICKHOUSE_TIMEZONE_ESCAPED|CLICKHOUSE_TIMEZONE|" | sed 's/\r$//' | sort;
${CLICKHOUSE_CURL} -vsS "${CLICKHOUSE_URL}" --data-binary @- <<< "SELECT timezone() SETTINGS session_timezone='Europe/Berlin'" 2>&1 | grep '< X-ClickHouse-Timezone' | grep -v 'GET' | tr -d '\r';
${CLICKHOUSE_CURL} -vsS "${CLICKHOUSE_URL}" --data-binary @- <<< "SELECT timezone() SETTINGS session_timezone='Africa/Cairo'" 2>&1 | grep '< X-ClickHouse-Timezone' | grep -v 'GET' | tr -d '\r';
# Not pretty but working way of removing randomized session_timezone for this part of test
CLICKHOUSE_URL_WO_SESSION_TZ=$(echo "${CLICKHOUSE_URL}" |sed 's/\&session_timezone\=[A-Za-z0-9\/\%\_\-\+\-]*//g' | sed 's/\?session_timezone\=[A-Za-z0-9\/\%\_\-\+\-]*\&/\?/g');
${CLICKHOUSE_CURL} -vsS "${CLICKHOUSE_URL_WO_SESSION_TZ}&session_timezone=Europe/Berlin&query=SELECT+timezone()" 2>&1 | grep '< X-ClickHouse-Timezone' | grep -v 'GET' | tr -d '\r';
${CLICKHOUSE_CURL} -vsS "${CLICKHOUSE_URL_WO_SESSION_TZ}&session_timezone=America/Denver&query=SELECT+timezone()" 2>&1 | grep '< X-ClickHouse-Timezone' | grep -v 'GET' | tr -d '\r';
# check that proper X-ClickHouse-Timezone returned on query fail
${CLICKHOUSE_CURL} -vsS "${CLICKHOUSE_URL_WO_SESSION_TZ}&session_timezone=UTC&query=SELECT+intDiv(1,+(3600-timeZoneOffset('2024-05-06+12:00:00'::DateTime)))+SETTINGS+session_timezone+=+'Europe/Lisbon'" 2>&1 | grep '< X-ClickHouse-Timezone' | grep -v 'GET' | tr -d '\r';
# main query's session_timezone shall be set in header
${CLICKHOUSE_CURL} -vsS "${CLICKHOUSE_URL_WO_SESSION_TZ}&session_timezone=America/New_York&query=SELECT+1,(SELECT+1+SETTINGS+session_timezone='UTC')+SETTINGS+session_timezone='Europe/Lisbon'" 2>&1 | grep '< X-ClickHouse-Timezone' | grep -v 'GET' | tr -d '\r';

View File

@ -2,6 +2,7 @@ Pacific/Pitcairn Pacific/Pitcairn
Asia/Novosibirsk Asia/Novosibirsk
2022-12-12 17:23:23
2022-12-13 07:23:23.123
2022-12-13 07:23:23 2022-12-13 07:23:23
2002-12-12 23:23:23 2002-12-12 23:23:23
2002-12-12 23:23:23.123 2002-12-12 23:23:23.123
2000-01-01 01:00:00

View File

@ -9,6 +9,9 @@ SELECT timezone(), timezoneOf(now());
SELECT toDateTime(toDateTime('2022-12-12 23:23:23'), 'Europe/Zurich');
SELECT toDateTime64(toDateTime64('2022-12-12 23:23:23.123', 3), 3, 'Europe/Zurich') SETTINGS session_timezone = 'America/Denver';
-- subquery shall use main query's session_timezone
SELECT toDateTime(toDateTime('2022-12-12 23:23:23'), 'Europe/Zurich'), (SELECT toDateTime(toDateTime('2022-12-12 23:23:23'), 'Europe/Zurich') SETTINGS session_timezone = 'Europe/Helsinki') SETTINGS session_timezone = 'America/Denver';
-- test proper serialization
SELECT toDateTime('2002-12-12 23:23:23') AS dt, toString(dt) SETTINGS session_timezone = 'Asia/Phnom_Penh';
SELECT toDateTime64('2002-12-12 23:23:23.123', 3) AS dt64, toString(dt64) SETTINGS session_timezone = 'Asia/Phnom_Penh';