renamed setting

This commit is contained in:
zvonand 2023-04-18 02:42:30 +02:00
parent 089306820f
commit 22be85d976
12 changed files with 48 additions and 38 deletions

View File

@ -4008,9 +4008,9 @@ Default value: `0`.
Use this setting only for backward compatibility if your use cases depend on old syntax.
:::
## timezone {#timezone}
## session_timezone {#session_timezone}
If specified, sets a implicit timezone (instead of server-default). All DateTime/DateTime64 values (and/or functions results) that have no explicit timezone specified are treated as having this timezone instead of default.
If specified, sets an implicit timezone (instead of server-default). All DateTime/DateTime64 values (and/or functions results) that have no explicit timezone specified are treated as having this timezone instead of default.
Examples:
```clickhouse
@ -4020,13 +4020,13 @@ Europe/Berlin Europe/Berlin
```
```clickhouse
SELECT timeZone(), serverTimezone() SETTINGS timezone = 'Asia/Novosibirsk' FORMAT TSV
SELECT timeZone(), serverTimezone() SETTINGS session_timezone = 'Asia/Novosibirsk' FORMAT TSV
Asia/Novosibirsk Europe/Berlin
```
```clickhouse
SELECT toDateTime64(toDateTime64('1999-12-12 23:23:23.123', 3), 3, 'Europe/Zurich') SETTINGS timezone = 'America/Denver' FORMAT TSV
SELECT toDateTime64(toDateTime64('1999-12-12 23:23:23.123', 3), 3, 'Europe/Zurich') SETTINGS session_timezone = 'America/Denver' FORMAT TSV
1999-12-13 07:23:23.123
```

View File

@ -26,7 +26,7 @@ SELECT
## timeZone
Returns the default timezone of the server for current session. This can be modified using `SET timezone = 'New/Value'`
Returns the default timezone of the server for current session. This can be modified using `SET session_timezone = 'New/Value'`
If it is executed in the context of a distributed table, then it generates a normal column with values relevant to each shard. Otherwise it produces a constant value.
**Syntax**

View File

@ -4075,9 +4075,9 @@ SELECT sum(number) FROM numbers(10000000000) SETTINGS partial_result_on_first_ca
Значение по умолчанию: `false`
## timezone {#timezone}
## session_timezone {#session_timezone}
Задаёт значение часового пояса (timezone) по умолчанию для текущей сессии вместо часового пояса сервера. То есть, все значения DateTime/DateTime64, для которых явно не задан параметр timezone, будут интерпретированы как относящиеся к указанной зоне.
Задаёт значение часового пояса (session_timezone) по умолчанию для текущей сессии вместо часового пояса сервера. То есть, все значения DateTime/DateTime64, для которых явно не задан параметр timezone, будут интерпретированы как относящиеся к указанной зоне.
Примеры:
```clickhouse
@ -4087,13 +4087,13 @@ Europe/Berlin Europe/Berlin
```
```clickhouse
SELECT timeZone(), serverTimezone() SETTINGS timezone = 'Asia/Novosibirsk' FORMAT TSV
SELECT timeZone(), serverTimezone() SETTINGS session_timezone = 'Asia/Novosibirsk' FORMAT TSV
Asia/Novosibirsk Europe/Berlin
```
```clickhouse
SELECT toDateTime64(toDateTime64('1999-12-12 23:23:23.123', 3), 3, 'Europe/Zurich') SETTINGS timezone = 'America/Denver' FORMAT TSV
SELECT toDateTime64(toDateTime64('1999-12-12 23:23:23.123', 3), 3, 'Europe/Zurich') SETTINGS session_timezone = 'America/Denver' FORMAT TSV
1999-12-13 07:23:23.123
```

View File

@ -26,7 +26,7 @@ SELECT
## timeZone {#timezone}
Возвращает часовой пояс сервера, считающийся умолчанием для текущей сессии.
Возвращает часовой пояс сервера, считающийся умолчанием для текущей сессии. Можно изменить значение с помощью `SET session_timezone = 'New/Timezone''`
Если функция вызывается в контексте распределенной таблицы, то она генерирует обычный столбец со значениями, актуальными для каждого шарда. Иначе возвращается константа.
**Синтаксис**

View File

@ -451,12 +451,9 @@ void ClientBase::onData(Block & block, ASTPtr parsed_query)
/// Also do not output too much data if we're fuzzing.
if (block.rows() == 0 || (query_fuzzer_runs != 0 && processed_rows >= 100))
{
// LogContextes("ClientBase::onData header", global_context);
return;
}
// LogContextes("ClientBase::onData DATA block", global_context);
/// If results are written INTO OUTFILE, we can avoid clearing progress to avoid flicker.
if (need_render_progress && tty_buf && (!select_into_file || select_into_file_and_stdout))
progress_indication.clearProgressOutput(*tty_buf);
@ -1075,7 +1072,7 @@ void ClientBase::onProgress(const Progress & value)
void ClientBase::onTimezoneUpdate(const String & tz)
{
Settings settings;
settings.timezone = tz;
settings.session_timezone = tz;
global_context->applySettingsChanges(settings.changes());
}

View File

@ -167,5 +167,5 @@ DateLUT & DateLUT::getInstance()
std::string DateLUT::extractTimezoneFromContext(const DB::ContextPtr query_context)
{
return query_context->getSettingsRef().timezone.value;
return query_context->getSettingsRef().session_timezone.value;
}

View File

@ -734,7 +734,7 @@ class IColumn;
M(Bool, keeper_map_strict_mode, false, "Enforce additional checks during operations on KeeperMap. E.g. throw an exception on an insert for already existing key", 0) \
M(Bool, function_json_value_return_type_allow_nullable, false, "Allow function to return nullable type.", 0) \
M(Bool, function_json_value_return_type_allow_complex, false, "Allow function to return complex type, such as: struct, array, map.", 0) \
M(Timezone, timezone, "", "Use specified timezone for interpreting Date and DateTime instead of server's timezone.", 0) \
M(Timezone, session_timezone, "", "Use specified timezone for interpreting Date and DateTime instead of server's timezone in current session.", 0) \
// End of COMMON_SETTINGS
// Please add settings related to formats into the FORMAT_FACTORY_SETTINGS and move obsolete settings to OBSOLETE_SETTINGS.

View File

@ -13,6 +13,7 @@
#include <cmath>
extern const char * auto_time_zones[];
namespace DB
{
@ -26,6 +27,14 @@ namespace ErrorCodes
namespace
{
bool checkIsExitingTimeZone(const std::string_view timezone)
{
for (auto * it = auto_time_zones; *it; ++it)
if (timezone == *it)
return true;
return false;
}
template <typename T>
T stringToNumber(const String & str)
{
@ -463,6 +472,12 @@ void SettingFieldTimezone::readBinary(ReadBuffer & in)
*this = std::move(str);
}
void SettingFieldTimezone::validateTimezone(std::string_view str)
{
if (str != "" && !checkIsExitingTimeZone(str))
throw DB::Exception(DB::ErrorCodes::BAD_ARGUMENTS, "Invalid time zone: {}", str);
}
String SettingFieldCustom::toString() const
{
return value.dump();

View File

@ -2,7 +2,6 @@
#include <Poco/Timespan.h>
#include <Poco/URI.h>
#include <cctz/time_zone.h>
#include <base/types.h>
#include <Core/Field.h>
#include <Core/MultiEnum.h>
@ -553,13 +552,16 @@ struct SettingFieldTimezone
String value;
bool changed = false;
explicit SettingFieldTimezone(std::string_view str = {}) { validateTimezone(std::string(str)); value = str; }
explicit SettingFieldTimezone(std::string_view str = {}) { validateTimezone(str); value = str; }
// explicit SettingFieldTimezone(std::string_view str = {}) { validateTimezone(std::string(str)); value = str; }
explicit SettingFieldTimezone(const String & str) { validateTimezone(str); value = str; }
explicit SettingFieldTimezone(String && str) { validateTimezone(std::string(str)); value = std::move(str); }
// explicit SettingFieldTimezone(String && str) { validateTimezone(std::string(str)); value = std::move(str); }
explicit SettingFieldTimezone(String && str) { validateTimezone(str); value = std::move(str); }
explicit SettingFieldTimezone(const char * str) { validateTimezone(str); value = str; }
explicit SettingFieldTimezone(const Field & f) { const String & str = f.safeGet<const String &>(); validateTimezone(str); value = str; }
SettingFieldTimezone & operator =(std::string_view str) { validateTimezone(std::string(str)); value = str; changed = true; return *this; }
// SettingFieldTimezone & operator =(std::string_view str) { validateTimezone(std::string(str)); value = str; changed = true; return *this; }
SettingFieldTimezone & operator =(std::string_view str) { validateTimezone(str); value = str; changed = true; return *this; }
SettingFieldTimezone & operator =(const String & str) { *this = std::string_view{str}; return *this; }
SettingFieldTimezone & operator =(String && str) { validateTimezone(str); value = std::move(str); changed = true; return *this; }
SettingFieldTimezone & operator =(const char * str) { *this = std::string_view{str}; return *this; }
@ -575,12 +577,13 @@ struct SettingFieldTimezone
void readBinary(ReadBuffer & in);
private:
cctz::time_zone validated_tz;
void validateTimezone(const std::string & tz_str)
{
if (!tz_str.empty() && !cctz::load_time_zone(tz_str, &validated_tz))
throw DB::Exception(DB::ErrorCodes::BAD_ARGUMENTS, "Invalid time zone: {}", tz_str);
}
static void validateTimezone(std::string_view str);
// cctz::time_zone validated_tz;
// void validateTimezone(const std::string & tz_str)
// {
// if (!tz_str.empty() && !cctz::load_time_zone(tz_str, &validated_tz))
// throw DB::Exception(DB::ErrorCodes::BAD_ARGUMENTS, "Invalid time zone: {}", tz_str);
// }
};
/// Can keep a value of any type. Used for user-defined settings.

View File

@ -1680,7 +1680,6 @@ void Context::applySettingChange(const SettingChange & change)
void Context::applySettingsChanges(const SettingsChanges & changes)
{
auto lock = getLock();
for (const SettingChange & change : changes)
applySettingChange(change);
applySettingsQuirks(settings);

View File

@ -183,11 +183,8 @@ void TCPHandler::runImpl()
/// User will be authenticated here. It will also set settings from user profile into connection_context.
try
{
LOG_DEBUG(log, "Before receiveHello");
receiveHello();
LOG_DEBUG(log, "Before sendHello");
sendHello();
LOG_DEBUG(log, "Before receiveAddendum");
if (client_tcp_protocol_version >= DBMS_MIN_PROTOCOL_VERSION_WITH_ADDENDUM)
receiveAddendum();
@ -465,7 +462,6 @@ void TCPHandler::runImpl()
sendSelectProfileEvents();
sendLogs();
return false;
};
@ -1072,7 +1068,7 @@ void TCPHandler::sendTimezone()
if (client_tcp_protocol_version < DBMS_MIN_PROTOCOL_VERSION_WITH_TIMEZONE_UPDATES)
return;
const String & tz = query_context->getSettingsRef().timezone.toString();
const String & tz = query_context->getSettingsRef().session_timezone.toString();
LOG_DEBUG(log, "TCPHandler::sendTimezone(): {}", tz);
writeVarUInt(Protocol::Server::TimezoneUpdate, *out);

View File

@ -1,11 +1,11 @@
SET timezone = 'Абырвалг'; -- { serverError BAD_ARGUMENTS}
SET session_timezone = 'Абырвалг'; -- { serverError BAD_ARGUMENTS}
SET timezone = 'Asia/Novosibirsk';
SET session_timezone = 'Asia/Novosibirsk';
SELECT toDateTime64(toDateTime64('2022-12-12 23:23:23.123', 3), 3, 'Europe/Zurich');
SELECT toDateTime64(toDateTime64('2022-12-12 23:23:23.123', 3), 3, 'Europe/Zurich') SETTINGS timezone = 'Europe/Zurich';
SELECT toDateTime64(toDateTime64('2022-12-12 23:23:23.123', 3), 3, 'Europe/Zurich') SETTINGS session_timezone = 'Europe/Zurich';
SET timezone = 'Asia/Manila';
SET session_timezone = 'Asia/Manila';
SELECT toDateTime64(toDateTime64('2022-12-12 23:23:23.123', 3), 3, 'Asia/Novosibirsk');
SELECT timezone(), timezoneOf(now()) SETTINGS timezone = 'Europe/Zurich' FORMAT TSV;
SELECT timezone(), timezoneOf(now()) SETTINGS timezone = 'Pacific/Pitcairn' FORMAT TSV;
SELECT timezone(), timezoneOf(now()) SETTINGS session_timezone = 'Europe/Zurich' FORMAT TSV;
SELECT timezone(), timezoneOf(now()) SETTINGS session_timezone = 'Pacific/Pitcairn' FORMAT TSV;