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

[Refactor](timezone) Refactor timezone docs and move it #810

Merged
merged 5 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Doris supports custom time zone settings
The following two time zone related parameters exist within Doris:

- `system_time_zone` : When the server starts up, it will be set automatically according to the time zone set by the machine, and cannot be modified after it is set.
- `time_zone` : The current time zone of the cluster.
- `time_zone` : The current time zone of the cluster. This variable will be set to the same as `system_time_zone` when the cluster starts and will not be changed again unless manually changed by the user.

## Specific operations

Expand All @@ -47,12 +47,7 @@ The following two time zone related parameters exist within Doris:

## Data source

The time zone data contains the name of the time zone, the corresponding time offset, and the change of daylight saving time. On the machine where the BE is located, the sources of the data are as follows:

1. the directory returned by command `TZDIR`. If was not supported, the directory `/usr/share/zoneinfo`.
2. the `zoneinfo` directory generated under the Doris BE deployment directory. The `resource/zoneinfo.tar.gz` directory from the Doris Repository.

Look up the above data sources in order and use the current item if found. If neither is found, the Doris BE will fail to start, please rebuild the BE correctly or get the distribution.
The time zone data contains the name of the time zone, the corresponding time offset, and the change of daylight saving time. On the machine where the BE is located, the source of the data is the directory returned by command `TZDIR`. If was not supported, the directory `/usr/share/zoneinfo`.

## Impact of time zone

Expand All @@ -78,7 +73,7 @@ Functions affected by time zone:

For `DATE` and `DATETIME` types, we support time zone conversion when importing data.

- If the data has a time zone, such as "2020-12-12 12:12:12+08:00", and the current Doris `time_zone = +00:00` or the header `timezone` specified by Stream Load is `+00: 00`, then the data is imported into Doris and the actual value is "2020-12-12 04:12:12".
- If the data has a time zone, such as "2020-12-12 12:12:12+08:00" with the current Doris `time_zone = +00:00`, then the data is imported into Doris and the actual value is "2020-12-12 04:12:12".

- If the data does not contain a time zone, such as "2020-12-12 12:12:12", the time is considered to be an absolute time and no conversion occurs.

Expand All @@ -93,9 +88,9 @@ If you do not want Daylight Saving Time to be turned on, set `time_zone` to `-08

Time zone values can be given in a variety of formats. The following standard formats are well supported in Doris:

1. standard named time zone formats, such as "Asia/Shanghai", "America/Los_Angeles".
1. standard named time zone formats, such as "Asia/Shanghai", "America/Los_Angeles". This format is derived from [time zone data on this machine](#data-source). "Etc/GMT+3" etc. also belongs to this category.

2. standard offset formats, such as "+02:30", "-10:00".
2. standard offset formats, such as "+02:30", "-10:00".(special offsets such as "+12:03" are not supported)

3. abbreviated time zone formats, currently only support:

Expand All @@ -105,6 +100,8 @@ Time zone values can be given in a variety of formats. The following standard fo

4. single letter Z, for Zulu time zone, equivalent to "+00:00" time zone

Besides, all parsing of alphabet is case insensitive.

Note: Some other formats are currently supported in some imports in Doris due to different implementations. **Production environments should not rely on these formats that are not listed here, and their behaviour may change at any time**, so keep an eye on the relevant changelog for version updates.

## Best Practices
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Doris 内部存在以下两个时区相关参数:

- system_time_zone : 当服务器启动时,会根据机器设置时区自动设置,设置后不可修改。

- time_zone : 集群当前时区,可以修改。
- time_zone : 集群当前时区,可以修改。集群启动时,该变量会设置为与 `system_time_zone` 相同,之后不再变动,除非用户手动修改。

## 具体操作

Expand All @@ -42,23 +42,17 @@ Doris 内部存在以下两个时区相关参数:

2. `SET [global] time_zone = 'Asia/Shanghai'`

该命令可以设置 session 级别的时区,如使用`global`关键字,则 Doris FE 会将参数持久化,之后对所有新 session 生效。
该命令可以设置 Session 级别的时区,如使用 `global` 关键字,则 Doris FE 会将参数持久化,之后对所有新 Session 生效。

## 数据来源

时区数据包含时区名、对应时间偏移量、夏令时变化情况等。在 BE 所在机器上,其数据来源依次为:

1. `TZDIR` 命令返回的目录,如不支持该命令,则为 `/usr/share/zoneinfo` 目录

2. Doris BE 部署目录下生成的 `zoneinfo` 目录。产生自 Doris Repository 下的 `resource/zoneinfo.tar.gz`

按顺序查找以上数据源,如果找到则使用当前项。如均未找到,则 Doris BE 将启动失败,请重新正确构建 BE 或获取发行版。
时区数据包含时区名、对应时间偏移量、夏令时变化情况等。在 BE 所在机器上,其数据来源为 `TZDIR` 命令返回的目录,如不支持该命令,则为 `/usr/share/zoneinfo` 目录。

## 时区的影响

### 1. 函数

包括`NOW()``CURTIME()`等时间函数显示的值,也包括`show load`, `show backends`中的时间值。
包括 `NOW()``CURTIME()` 等时间函数显示的值,也包括 `show load`, `show backends` 中的时间值。

但不会影响 `create table` 中时间类型分区列的 less than 值,也不会影响存储为 `date/datetime` 类型的值的显示。

Expand All @@ -78,7 +72,7 @@ Doris 内部存在以下两个时区相关参数:

对于`DATE`、`DATETIME`类型,我们支持导入数据时对时区进行转换。

- 如果数据带有时区,如 "2020-12-12 12:12:12+08:00",而当前 Doris `time_zone = +00:00` 或者 Stream Load 指定的 header `timezone` 为 `+00:00` ,则数据导入 Doris 得到实际值为 "2020-12-12 04:12:12"。
- 如果数据带有时区,如 "2020-12-12 12:12:12+08:00",Stream Load 指定的 Header `timezone` 为 `+00:00` ,则数据导入 Doris 得到实际值为 "2020-12-12 04:12:12"。

- 如果数据不带有时区,如 "2020-12-12 12:12:12",则认为该时间为绝对时间,不发生任何转换。

Expand All @@ -93,9 +87,9 @@ Doris 内部存在以下两个时区相关参数:

时区值可以使用多种格式给出,以下是 Doris 中完善支持的标准格式:

1. 标准具名时区格式,如 "Asia/Shanghai", "America/Los_Angeles"
1. 标准具名时区格式,如 "Asia/Shanghai", "America/Los_Angeles"。此类格式来源于[本机所带时区数据](#数据来源),如 "Etc/GMT+3" 等亦属此列。

2. 标准偏移格式,如 "+02:30", "-10:00"
2. 标准偏移格式,如 "+02:30", "-10:00"(不支持诸如 "+12:03" 等特殊偏移)

3. 缩写时区格式,当前仅支持:

Expand All @@ -105,6 +99,8 @@ Doris 内部存在以下两个时区相关参数:

4. 单字母 Z,代表 Zulu 时区,等同于 "+00:00" 时区

此外,对任何字母的解析不区分大小写。

注意:由于实现方式的不同,当前 Doris 存在部分其他格式在部分导入方式中得到了支持。**生产环境不应当依赖这些未列于此的格式,它们的行为随时可能发生变化**,请关注版本更新时的相关 changelog。

## 最佳实践
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Doris 内部存在以下两个时区相关参数:

- system_time_zone : 当服务器启动时,会根据机器设置时区自动设置,设置后不可修改。

- time_zone : 集群当前时区,可以修改。
- time_zone : 集群当前时区,可以修改。集群启动时,该变量会设置为与 `system_time_zone` 相同,之后不再变动,除非用户手动修改。

## 具体操作

Expand All @@ -42,43 +42,37 @@ Doris 内部存在以下两个时区相关参数:

2. `SET [global] time_zone = 'Asia/Shanghai'`

该命令可以设置 session 级别的时区,如使用`global`关键字,则 Doris FE 会将参数持久化,之后对所有新 session 生效。
该命令可以设置 Session 级别的时区,如使用 `global` 关键字,则 Doris FE 会将参数持久化,之后对所有新 Session 生效。

## 数据来源

时区数据包含时区名、对应时间偏移量、夏令时变化情况等。在 BE 所在机器上,其数据来源依次为:

1. `TZDIR` 命令返回的目录,如不支持该命令,则为 `/usr/share/zoneinfo` 目录

2. Doris BE 部署目录下生成的 `zoneinfo` 目录。产生自 Doris Repository 下的 `resource/zoneinfo.tar.gz`

按顺序查找以上数据源,如果找到则使用当前项。如均未找到,则 Doris BE 将启动失败,请重新正确构建 BE 或获取发行版。
时区数据包含时区名、对应时间偏移量、夏令时变化情况等。在 BE 所在机器上,其数据来源为 `TZDIR` 命令返回的目录,如不支持该命令,则为 `/usr/share/zoneinfo` 目录。

## 时区的影响

### 1. 函数

包括`NOW()``CURTIME()`等时间函数显示的值,也包括`show load`, `show backends`中的时间值。
包括 `NOW()``CURTIME()` 等时间函数显示的值,也包括 `show load`, `show backends` 中的时间值。

但不会影响 `create table` 中时间类型分区列的 less than 值,也不会影响存储为 `date/datetime` 类型的值的显示。

受时区影响的函数:

- `FROM_UNIXTIME`:给定一个 UTC 时间戳,返回其在 Doris session `time_zone` 指定时区的日期时间,如`time_zone`为`CST`时`FROM_UNIXTIME(0)`返回`1970-01-01 08:00:00`。
- `FROM_UNIXTIME`:给定一个 UTC 时间戳,返回其在 Doris Session `time_zone` 指定时区的日期时间,如`time_zone`为`CST`时`FROM_UNIXTIME(0)`返回`1970-01-01 08:00:00`。

- `UNIX_TIMESTAMP`:给定一个日期时间,返回其在 Doris session `time_zone` 指定时区下的 UTC 时间戳,如`time_zone`为`CST`时`UNIX_TIMESTAMP('1970-01-01 08:00:00')`返回`0`。
- `UNIX_TIMESTAMP`:给定一个日期时间,返回其在 Doris Session `time_zone` 指定时区下的 UTC 时间戳,如`time_zone`为`CST`时`UNIX_TIMESTAMP('1970-01-01 08:00:00')`返回`0`。

- `CURTIME`:返回当前 Doris session `time_zone` 指定时区的时间。
- `CURTIME`:返回当前 Doris Session `time_zone` 指定时区的时间。

- `NOW`:返回当前 Doris session `time_zone` 指定时区的日期时间。
- `NOW`:返回当前 Doris Session `time_zone` 指定时区的日期时间。

- `CONVERT_TZ`:将一个日期时间从一个指定时区转换到另一个指定时区。

### 2. 时间类型的值

对于`DATE`、`DATETIME`类型,我们支持导入数据时对时区进行转换。

- 如果数据带有时区,如 "2020-12-12 12:12:12+08:00",而当前 Doris `time_zone = +00:00` 或者 Stream Load 指定的 header `timezone` 为 `+00:00` ,则数据导入 Doris 得到实际值为 "2020-12-12 04:12:12"。
- 如果数据带有时区,如 "2020-12-12 12:12:12+08:00", Stream Load 指定的 header `timezone` 为 `+00:00` ,则数据导入 Doris 得到实际值为 "2020-12-12 04:12:12"。

- 如果数据不带有时区,如 "2020-12-12 12:12:12",则认为该时间为绝对时间,不发生任何转换。

Expand All @@ -93,9 +87,9 @@ Doris 内部存在以下两个时区相关参数:

时区值可以使用多种格式给出,以下是 Doris 中完善支持的标准格式:

1. 标准具名时区格式,如 "Asia/Shanghai", "America/Los_Angeles"
1. 标准具名时区格式,如 "Asia/Shanghai", "America/Los_Angeles"。此类格式来源于[本机所带时区数据](#数据来源),如 "Etc/GMT+3" 等亦属此列。

2. 标准偏移格式,如 "+02:30", "-10:00"
2. 标准偏移格式,如 "+02:30", "-10:00"(不支持诸如 "+12:03" 等特殊偏移)

3. 缩写时区格式,当前仅支持:

Expand All @@ -105,6 +99,8 @@ Doris 内部存在以下两个时区相关参数:

4. 单字母 Z,代表 Zulu 时区,等同于 "+00:00" 时区

此外,对任何字母的解析不区分大小写。

注意:由于实现方式的不同,当前 Doris 存在部分其他格式在部分导入方式中得到了支持。**生产环境不应当依赖这些未列于此的格式,它们的行为随时可能发生变化**,请关注版本更新时的相关 changelog。

## 最佳实践
Expand All @@ -113,7 +109,7 @@ Doris 内部存在以下两个时区相关参数:

时区问题主要涉及三个影响因素:

1. session variable `time_zone` —— 集群时区
1. Session Variable `time_zone` —— 集群时区

2. Stream Load、Broker Load 等导入时指定的 header `timezone` —— 导入时区

Expand Down Expand Up @@ -162,7 +158,7 @@ Doris 目前兼容各时区下的数据向 Doris 中进行导入。而由于 Dor
+---------------------+
```

* 对于 Stream Load、Broker Load 等导入方式,我们可以通过指定 header `timezone` 来实现。例如,对于 Stream Load,我们可以通过以下例子来说明:
* 对于 Stream Load、Broker Load 等导入方式,我们可以通过指定 Header `timezone` 来实现。例如,对于 Stream Load,我们可以通过以下例子来说明:

```shell
cat dt.csv
Expand Down
Loading
Loading