StorageKafka (topic-name): [rdk:CONFWARN] [thrd:app]: Configuration property group.id is a consumer property and will be ignored by this producer instance ```. [#37228](https://github.com/ClickHouse/ClickHouse/pull/37228) ([Mark Andreev](https://github.com/mrk-andreev)).
+* fix MySQL database engine to compatible with binary(0) dataType. [#37232](https://github.com/ClickHouse/ClickHouse/pull/37232) ([zzsmdfj](https://github.com/zzsmdfj)).
+* Fix execution of mutations in tables, in which there exist columns of type `Object`. Using subcolumns of type `Object` in `WHERE` expression of `UPDATE` or `DELETE` queries is now allowed yet, as well as manipulating (`DROP`, `MODIFY`) of separate subcolumns. Fixes [#37205](https://github.com/ClickHouse/ClickHouse/issues/37205). [#37266](https://github.com/ClickHouse/ClickHouse/pull/37266) ([Anton Popov](https://github.com/CurtizJ)).
+* Fix Nullable(String) to Nullable(Bool/IPv4/IPv6) conversion Closes [#37221](https://github.com/ClickHouse/ClickHouse/issues/37221). [#37270](https://github.com/ClickHouse/ClickHouse/pull/37270) ([Kruglov Pavel](https://github.com/Avogar)).
+* Fix system.opentelemetry_span_log attribute.values alias to values instead of keys. [#37275](https://github.com/ClickHouse/ClickHouse/pull/37275) ([Aleksandr Razumov](https://github.com/ernado)).
+* Fix possible deadlock in OvercommitTracker during logging. cc @alesapin @tavplubix Fixes [#37272](https://github.com/ClickHouse/ClickHouse/issues/37272). [#37299](https://github.com/ClickHouse/ClickHouse/pull/37299) ([Dmitry Novik](https://github.com/novikd)).
+
+#### Bug Fix (user-visible misbehaviour in official stable or prestable release)
+
+* - fix substring function range error length when `offset` and `length` is negative constant and `s` is not constant. [#33861](https://github.com/ClickHouse/ClickHouse/pull/33861) ([RogerYK](https://github.com/RogerYK)).
+* Accidentally ZSTD support for Arrow was not being built. This fixes [#35283](https://github.com/ClickHouse/ClickHouse/issues/35283). [#35486](https://github.com/ClickHouse/ClickHouse/pull/35486) ([Sean Lafferty](https://github.com/seanlaff)).
+* Fix ALTER DROP COLUMN of nested column with compact parts (i.e. `ALTER TABLE x DROP COLUMN n`, when there is column `n.d`). [#35797](https://github.com/ClickHouse/ClickHouse/pull/35797) ([Azat Khuzhin](https://github.com/azat)).
+* Fix insertion of complex JSONs with nested arrays to columns of type `Object`. [#36077](https://github.com/ClickHouse/ClickHouse/pull/36077) ([Anton Popov](https://github.com/CurtizJ)).
+* Queries with aliases inside special operators returned parsing error (was broken in 22.1). Example: `SELECT substring('test' AS t, 1, 1)`. [#36167](https://github.com/ClickHouse/ClickHouse/pull/36167) ([Maksim Kita](https://github.com/kitaisreal)).
+* - Fix assertion in JOIN, close [#36199](https://github.com/ClickHouse/ClickHouse/issues/36199). [#36201](https://github.com/ClickHouse/ClickHouse/pull/36201) ([Vladimir C](https://github.com/vdimir)).
+* Fix dictionary reload for `ClickHouseDictionarySource` if it contains scalar subqueries. [#36390](https://github.com/ClickHouse/ClickHouse/pull/36390) ([lthaooo](https://github.com/lthaooo)).
+* Fix nullptr dereference in JOIN and COLUMNS matcher. This fixes [#36416](https://github.com/ClickHouse/ClickHouse/issues/36416) . This is for https://github.com/ClickHouse/ClickHouse/pull/36417. [#36430](https://github.com/ClickHouse/ClickHouse/pull/36430) ([Amos Bird](https://github.com/amosbird)).
+* Fix bug in s3Cluster schema inference that let to the fact that not all data was read in the select from s3Cluster. The bug appeared in https://github.com/ClickHouse/ClickHouse/pull/35544. [#36434](https://github.com/ClickHouse/ClickHouse/pull/36434) ([Kruglov Pavel](https://github.com/Avogar)).
+* Server might fail to start if it cannot resolve hostname of external ClickHouse dictionary. It's fixed. Fixes [#36451](https://github.com/ClickHouse/ClickHouse/issues/36451). [#36463](https://github.com/ClickHouse/ClickHouse/pull/36463) ([Alexander Tokmakov](https://github.com/tavplubix)).
+* This code segment can prove bug. ``` int main() { RangeGenerator g{1230, 100}; std::cout << g.totalRanges() << std::endl; int count = 0; while(g.nextRange()) ++count; std::cout << "count:" << count << std::endl; return 0; }. [#36469](https://github.com/ClickHouse/ClickHouse/pull/36469) ([李扬](https://github.com/taiyang-li)).
+* Fix clickhouse-benchmark json report results. [#36473](https://github.com/ClickHouse/ClickHouse/pull/36473) ([Tian Xinhui](https://github.com/xinhuitian)).
+* Add missing enum values in system.session_log table. Closes [#36474](https://github.com/ClickHouse/ClickHouse/issues/36474). [#36480](https://github.com/ClickHouse/ClickHouse/pull/36480) ([Memo](https://github.com/Joeywzr)).
+* Fix possible exception with unknown packet from server in client. [#36481](https://github.com/ClickHouse/ClickHouse/pull/36481) ([Kseniia Sumarokova](https://github.com/kssenii)).
+* Fix usage of executable user defined functions in GROUP BY. Before executable user defined functions cannot be used as expressions in GROUP BY. Closes [#36448](https://github.com/ClickHouse/ClickHouse/issues/36448). [#36486](https://github.com/ClickHouse/ClickHouse/pull/36486) ([Maksim Kita](https://github.com/kitaisreal)).
+* close [#33906](https://github.com/ClickHouse/ClickHouse/issues/33906). [#36489](https://github.com/ClickHouse/ClickHouse/pull/36489) ([awakeljw](https://github.com/awakeljw)).
+* Fix hostname sanity checks for Keeper cluster configuration. Add `keeper_server.host_checks_enabled` config to enable/disable those checks. [#36492](https://github.com/ClickHouse/ClickHouse/pull/36492) ([Antonio Andelic](https://github.com/antonio2368)).
+* Fix offset update ReadBufferFromEncryptedFile, which could cause undefined behaviour. [#36493](https://github.com/ClickHouse/ClickHouse/pull/36493) ([Kseniia Sumarokova](https://github.com/kssenii)).
+* - Fix potential error with literals in `WHERE` for join queries. Close [#36279](https://github.com/ClickHouse/ClickHouse/issues/36279). [#36542](https://github.com/ClickHouse/ClickHouse/pull/36542) ([Vladimir C](https://github.com/vdimir)).
+* Fix `Missing column` exception which could happen while using `INTERPOLATE` with `ENGINE = MergeTree` table. [#36549](https://github.com/ClickHouse/ClickHouse/pull/36549) ([Yakov Olkhovskiy](https://github.com/yakov-olkhovskiy)).
+* Fix format crash when default expression follow EPHEMERAL not literal. Closes [#36618](https://github.com/ClickHouse/ClickHouse/issues/36618). [#36633](https://github.com/ClickHouse/ClickHouse/pull/36633) ([flynn](https://github.com/ucasfl)).
+* Fix merges of wide parts with type `Object`. [#36637](https://github.com/ClickHouse/ClickHouse/pull/36637) ([Anton Popov](https://github.com/CurtizJ)).
+* Fixed parsing of query settings in `CREATE` query when engine is not specified. Fixes https://github.com/ClickHouse/ClickHouse/pull/34187#issuecomment-1103812419. [#36642](https://github.com/ClickHouse/ClickHouse/pull/36642) ([Alexander Tokmakov](https://github.com/tavplubix)).
+* Fix possible heap-use-after-free in schema inference. Closes [#36661](https://github.com/ClickHouse/ClickHouse/issues/36661). [#36679](https://github.com/ClickHouse/ClickHouse/pull/36679) ([Kruglov Pavel](https://github.com/Avogar)).
+* Fix server restart if cache configuration changed. [#36685](https://github.com/ClickHouse/ClickHouse/pull/36685) ([Kseniia Sumarokova](https://github.com/kssenii)).
+* In the previous [PR](https://github.com/ClickHouse/ClickHouse/pull/36376), I found that testing **(stateless tests, flaky check (address, actions))** is timeout. Moreover, testing locally can also trigger unstable system deadlocks. This problem still exists when using the latest source code of master. [#36697](https://github.com/ClickHouse/ClickHouse/pull/36697) ([Han Shukai](https://github.com/KinderRiven)).
+* Fix server reload on port change (do not wait for current connections from query context). [#36700](https://github.com/ClickHouse/ClickHouse/pull/36700) ([Azat Khuzhin](https://github.com/azat)).
+* Fix vertical merges in wide parts. Previously an exception `There is no column` can be thrown during merge. [#36707](https://github.com/ClickHouse/ClickHouse/pull/36707) ([Anton Popov](https://github.com/CurtizJ)).
+* During the [test](https://s3.amazonaws.com/clickhouse-test-reports/36376/1cb1c7275cb53769ab826772db9b71361bb3e413/stress_test__thread__actions_/clickhouse-server.clean.log) in [PR](https://github.com/ClickHouse/ClickHouse/pull/36376), I found that the one cache class was initialized twice, it throws a exception. Although the cause of this problem is not clear, there should be code logic of repeatedly loading disk in ClickHouse, so we need to make special judgment for this situation. [#36737](https://github.com/ClickHouse/ClickHouse/pull/36737) ([Han Shukai](https://github.com/KinderRiven)).
+* Fix a bug of `groupBitmapAndState`/`groupBitmapOrState`/`groupBitmapXorState` on distributed table. [#36739](https://github.com/ClickHouse/ClickHouse/pull/36739) ([Zhang Yifan](https://github.com/zhangyifan27)).
+* Fix timeouts in Hedged requests. Connection hang right after sending remote query could lead to eternal waiting. [#36749](https://github.com/ClickHouse/ClickHouse/pull/36749) ([Kruglov Pavel](https://github.com/Avogar)).
+* Fix insertion to columns of type `Object` from multiple files, e.g. via table function `file` with globs. [#36762](https://github.com/ClickHouse/ClickHouse/pull/36762) ([Anton Popov](https://github.com/CurtizJ)).
+* Fix some issues with async reads from remote filesystem which happened when reading low cardinality. [#36763](https://github.com/ClickHouse/ClickHouse/pull/36763) ([Kseniia Sumarokova](https://github.com/kssenii)).
+* Fix creation of tables with `flatten_nested = 0`. Previously unflattened `Nested` columns could be flattened after server restart. [#36803](https://github.com/ClickHouse/ClickHouse/pull/36803) ([Anton Popov](https://github.com/CurtizJ)).
+* Fix incorrect cast in cached buffer from remote fs. [#36809](https://github.com/ClickHouse/ClickHouse/pull/36809) ([Kseniia Sumarokova](https://github.com/kssenii)).
+* Remove function `groupArraySorted` which has a bug. [#36822](https://github.com/ClickHouse/ClickHouse/pull/36822) ([Alexey Milovidov](https://github.com/alexey-milovidov)).
+* Fix fire in window view with hop window [#34044](https://github.com/ClickHouse/ClickHouse/issues/34044). [#36861](https://github.com/ClickHouse/ClickHouse/pull/36861) ([vxider](https://github.com/Vxider)).
+* Fix `current_size` count in cache. [#36887](https://github.com/ClickHouse/ClickHouse/pull/36887) ([Kseniia Sumarokova](https://github.com/kssenii)).
+* Fix incorrect query result when doing constant aggregation. This fixes [#36728](https://github.com/ClickHouse/ClickHouse/issues/36728) . [#36888](https://github.com/ClickHouse/ClickHouse/pull/36888) ([Amos Bird](https://github.com/amosbird)).
+* Fix bug in clickhouse-keeper which can lead to corrupted compressed log files in case of small load and restarts. [#36910](https://github.com/ClickHouse/ClickHouse/pull/36910) ([alesapin](https://github.com/alesapin)).
+* Fix bugs when using multiple columns in WindowView by adding converting actions to make it possible to call`writeIntoWindowView` with a slightly different schema. [#36928](https://github.com/ClickHouse/ClickHouse/pull/36928) ([vxider](https://github.com/Vxider)).
+* Fix issue: [#36671](https://github.com/ClickHouse/ClickHouse/issues/36671). [#36929](https://github.com/ClickHouse/ClickHouse/pull/36929) ([李扬](https://github.com/taiyang-li)).
+* Fix stuck when dropping source table in WindowView. Closes [#35678](https://github.com/ClickHouse/ClickHouse/issues/35678). [#36967](https://github.com/ClickHouse/ClickHouse/pull/36967) ([vxider](https://github.com/Vxider)).
+* Fixed logical error on `TRUNCATE` query in `Replicated` database. Fixes [#33747](https://github.com/ClickHouse/ClickHouse/issues/33747). [#36976](https://github.com/ClickHouse/ClickHouse/pull/36976) ([Alexander Tokmakov](https://github.com/tavplubix)).
+* Fix sending external tables data in HedgedConnections with max_parallel_replicas != 1. [#36981](https://github.com/ClickHouse/ClickHouse/pull/36981) ([Kruglov Pavel](https://github.com/Avogar)).
+* Fixed problem with infs in `quantileTDigest`. Fixes [#32107](https://github.com/ClickHouse/ClickHouse/issues/32107). [#37021](https://github.com/ClickHouse/ClickHouse/pull/37021) ([Vladimir Chebotarev](https://github.com/excitoon)).
+* Fix LowCardinality->ArrowDictionary invalid output when type of indexes is not UInt8. Closes [#36832](https://github.com/ClickHouse/ClickHouse/issues/36832). [#37043](https://github.com/ClickHouse/ClickHouse/pull/37043) ([Kruglov Pavel](https://github.com/Avogar)).
+* Fix in-order `GROUP BY` (`optimize_aggregation_in_order=1`) with `*Array` (`groupArrayArray`/...) aggregate functions. [#37046](https://github.com/ClickHouse/ClickHouse/pull/37046) ([Azat Khuzhin](https://github.com/azat)).
+* Fixed performance degradation of some INSERT SELECT queries with implicit aggregation. Fixes [#36792](https://github.com/ClickHouse/ClickHouse/issues/36792). [#37047](https://github.com/ClickHouse/ClickHouse/pull/37047) ([Alexander Tokmakov](https://github.com/tavplubix)).
+* Fix optimize_aggregation_in_order with prefix GROUP BY and *Array aggregate functions. [#37050](https://github.com/ClickHouse/ClickHouse/pull/37050) ([Azat Khuzhin](https://github.com/azat)).
+
+#### NO CL ENTRY
+
+* NO CL ENTRY: 'Revert "Minor refactor to prefer C++ Standard Algorithms"'. [#36511](https://github.com/ClickHouse/ClickHouse/pull/36511) ([Alexey Milovidov](https://github.com/alexey-milovidov)).
+* NO CL ENTRY: 'Revert "Strict taskstats parser"'. [#36591](https://github.com/ClickHouse/ClickHouse/pull/36591) ([Alexey Milovidov](https://github.com/alexey-milovidov)).
+* NO CL ENTRY: 'Revert "Translate docs/zh/sql-reference/data-types/map.md"'. [#36594](https://github.com/ClickHouse/ClickHouse/pull/36594) ([Alexey Milovidov](https://github.com/alexey-milovidov)).
+* NO CL ENTRY: 'Revert "Update setting.md"'. [#36595](https://github.com/ClickHouse/ClickHouse/pull/36595) ([Alexey Milovidov](https://github.com/alexey-milovidov)).
+* NO CL ENTRY: 'Documentation: Add a missing **ESTIMATE** in explain syntax'. [#36717](https://github.com/ClickHouse/ClickHouse/pull/36717) ([小蝌蚪](https://github.com/kayhaw)).
+* NO CL ENTRY: '[Snyk] Security upgrade numpy from 1.16.6 to 1.22.2'. [#36729](https://github.com/ClickHouse/ClickHouse/pull/36729) ([Mikhail f. Shiryaev](https://github.com/Felixoid)).
+* NO CL ENTRY: 'Translate playground.md to Chinese'. [#36821](https://github.com/ClickHouse/ClickHouse/pull/36821) ([小蝌蚪](https://github.com/kayhaw)).
+* NO CL ENTRY: 'Revert "Memory overcommit: continue query execution if memory is available"'. [#36858](https://github.com/ClickHouse/ClickHouse/pull/36858) ([alesapin](https://github.com/alesapin)).
+* NO CL ENTRY: 'Revert "Revert "Memory overcommit: continue query execution if memory is available""'. [#36859](https://github.com/ClickHouse/ClickHouse/pull/36859) ([Dmitry Novik](https://github.com/novikd)).
+* NO CL ENTRY: 'Revert "BLAKE3 hash function documentation"'. [#37092](https://github.com/ClickHouse/ClickHouse/pull/37092) ([Rich Raposa](https://github.com/rfraposa)).
+* NO CL ENTRY: 'Revert "Remove height restrictions from the query div in play web tool."'. [#37261](https://github.com/ClickHouse/ClickHouse/pull/37261) ([Alexey Milovidov](https://github.com/alexey-milovidov)).
+
diff --git a/docs/en/development/build.md b/docs/en/development/build.md
index c043e21c0b1..ef744b57608 100644
--- a/docs/en/development/build.md
+++ b/docs/en/development/build.md
@@ -19,7 +19,7 @@ The following tutorial is based on the Ubuntu Linux system. With appropriate cha
### Install Git, CMake, Python and Ninja {#install-git-cmake-python-and-ninja}
``` bash
-$ sudo apt-get install git cmake python ninja-build
+sudo apt-get install git cmake python ninja-build
```
Or cmake3 instead of cmake on older systems.
@@ -37,8 +37,8 @@ For other Linux distribution - check the availability of the [prebuild packages]
#### Use the latest clang for Builds
``` bash
-$ export CC=clang-14
-$ export CXX=clang++-14
+export CC=clang-14
+export CXX=clang++-14
```
In this example we use version 14 that is the latest as of Feb 2022.
@@ -48,23 +48,23 @@ Gcc can also be used though it is discouraged.
### Checkout ClickHouse Sources {#checkout-clickhouse-sources}
``` bash
-$ git clone --recursive git@github.com:ClickHouse/ClickHouse.git
+git clone --recursive git@github.com:ClickHouse/ClickHouse.git
```
or
``` bash
-$ git clone --recursive https://github.com/ClickHouse/ClickHouse.git
+git clone --recursive https://github.com/ClickHouse/ClickHouse.git
```
### Build ClickHouse {#build-clickhouse}
``` bash
-$ cd ClickHouse
-$ mkdir build
-$ cd build
-$ cmake ..
-$ ninja
+cd ClickHouse
+mkdir build
+cd build
+cmake ..
+ninja
```
To create an executable, run `ninja clickhouse`.
@@ -114,13 +114,13 @@ make -j $(nproc)
Here is an example of how to build `clang` and all the llvm infrastructure from sources:
```
- git clone git@github.com:llvm/llvm-project.git
- mkdir llvm-build && cd llvm-build
- cmake -DCMAKE_BUILD_TYPE:STRING=Release -DLLVM_ENABLE_PROJECTS=all ../llvm-project/llvm/
- make -j16
- sudo make install
- hash clang
- clang --version
+git clone git@github.com:llvm/llvm-project.git
+mkdir llvm-build && cd llvm-build
+cmake -DCMAKE_BUILD_TYPE:STRING=Release -DLLVM_ENABLE_PROJECTS=all ../llvm-project/llvm/
+make -j16
+sudo make install
+hash clang
+clang --version
```
You can install the older clang like clang-11 from packages and then use it to build the new clang from sources.
@@ -140,21 +140,21 @@ hash cmake
### Install Git {#install-git}
``` bash
-$ sudo apt-get update
-$ sudo apt-get install git python debhelper lsb-release fakeroot sudo debian-archive-keyring debian-keyring
+sudo apt-get update
+sudo apt-get install git python debhelper lsb-release fakeroot sudo debian-archive-keyring debian-keyring
```
### Checkout ClickHouse Sources {#checkout-clickhouse-sources-1}
``` bash
-$ git clone --recursive --branch master https://github.com/ClickHouse/ClickHouse.git
-$ cd ClickHouse
+git clone --recursive --branch master https://github.com/ClickHouse/ClickHouse.git
+cd ClickHouse
```
### Run Release Script {#run-release-script}
``` bash
-$ ./release
+./release
```
## You Don’t Have to Build ClickHouse {#you-dont-have-to-build-clickhouse}
diff --git a/docs/en/development/cmake-in-clickhouse.md b/docs/en/development/cmake-in-clickhouse.md
index 14b98b136b3..65d280df902 100644
--- a/docs/en/development/cmake-in-clickhouse.md
+++ b/docs/en/development/cmake-in-clickhouse.md
@@ -420,12 +420,6 @@ Note that ClickHouse uses forks of these libraries, see https://github.com/Click
Using system libs can cause a lot of warnings in includes (on macro expansion). |
-WEVERYTHING |
-ON |
-Enable -Weverything option with some exceptions. |
-Add some warnings that are not available even with -Wall -Wextra -Wpedantic. Intended for exploration of new compiler warnings that may be found useful. Applies to clang only |
-
-
WITH_COVERAGE |
OFF |
Profile the resulting binary/binaries |
diff --git a/docs/en/development/tests.md b/docs/en/development/tests.md
index 4aba0506c2e..f9c7ae37157 100644
--- a/docs/en/development/tests.md
+++ b/docs/en/development/tests.md
@@ -12,7 +12,7 @@ Functional tests are the most simple and convenient to use. Most of ClickHouse f
Each functional test sends one or multiple queries to the running ClickHouse server and compares the result with reference.
-Tests are located in `queries` directory. There are two subdirectories: `stateless` and `stateful`. Stateless tests run queries without any preloaded test data - they often create small synthetic datasets on the fly, within the test itself. Stateful tests require preloaded test data from CLickHouse and it is available to general public.
+Tests are located in `queries` directory. There are two subdirectories: `stateless` and `stateful`. Stateless tests run queries without any preloaded test data - they often create small synthetic datasets on the fly, within the test itself. Stateful tests require preloaded test data from ClickHouse and it is available to general public.
Each test can be one of two types: `.sql` and `.sh`. `.sql` test is the simple SQL script that is piped to `clickhouse-client --multiquery`. `.sh` test is a script that is run by itself. SQL tests are generally preferable to `.sh` tests. You should use `.sh` tests only when you have to test some feature that cannot be exercised from pure SQL, such as piping some input data into `clickhouse-client` or testing `clickhouse-local`.
diff --git a/docs/en/engines/table-engines/integrations/kafka.md b/docs/en/engines/table-engines/integrations/kafka.md
index 620b2057f83..a9d13194a59 100644
--- a/docs/en/engines/table-engines/integrations/kafka.md
+++ b/docs/en/engines/table-engines/integrations/kafka.md
@@ -189,6 +189,8 @@ Example:
- `_timestamp` — Timestamp of the message.
- `_timestamp_ms` — Timestamp in milliseconds of the message.
- `_partition` — Partition of Kafka topic.
+- `_headers.name` — Array of message's headers keys.
+- `_headers.value` — Array of message's headers values.
**See Also**
diff --git a/docs/en/engines/table-engines/mergetree-family/mergetree.md b/docs/en/engines/table-engines/mergetree-family/mergetree.md
index 1029cceb28a..d59b07b5dd6 100644
--- a/docs/en/engines/table-engines/mergetree-family/mergetree.md
+++ b/docs/en/engines/table-engines/mergetree-family/mergetree.md
@@ -669,6 +669,7 @@ Storage policies configuration markup:
disk_name_from_disks_configuration
1073741824
+ round_robin
@@ -695,6 +696,8 @@ Tags:
- `max_data_part_size_bytes` — the maximum size of a part that can be stored on any of the volume’s disks. If the a size of a merged part estimated to be bigger than `max_data_part_size_bytes` then this part will be written to a next volume. Basically this feature allows to keep new/small parts on a hot (SSD) volume and move them to a cold (HDD) volume when they reach large size. Do not use this setting if your policy has only one volume.
- `move_factor` — when the amount of available space gets lower than this factor, data automatically starts to move on the next volume if any (by default, 0.1). ClickHouse sorts existing parts by size from largest to smallest (in descending order) and selects parts with the total size that is sufficient to meet the `move_factor` condition. If the total size of all parts is insufficient, all parts will be moved.
- `prefer_not_to_merge` — Disables merging of data parts on this volume. When this setting is enabled, merging data on this volume is not allowed. This allows controlling how ClickHouse works with slow disks.
+- `perform_ttl_move_on_insert` — Disables TTL move on data part INSERT. By default if we insert a data part that already expired by the TTL move rule it immediately goes to a volume/disk declared in move rule. This can significantly slowdown insert in case if destination volume/disk is slow (e.g. S3).
+- `load_balancing` - Policy for disk balancing, `round_robin` or `least_used`.
Cofiguration examples:
@@ -724,7 +727,7 @@ Cofiguration examples:
0.2
-
+
jbod1
diff --git a/docs/en/getting-started/install.md b/docs/en/getting-started/install.md
index f31a78bc1c4..12775749a25 100644
--- a/docs/en/getting-started/install.md
+++ b/docs/en/getting-started/install.md
@@ -238,7 +238,7 @@ To start the server as a daemon, run:
$ sudo clickhouse start
```
-There are also another ways to run ClickHouse:
+There are also other ways to run ClickHouse:
``` bash
$ sudo service clickhouse-server start
diff --git a/docs/en/operations/system-tables/tables.md b/docs/en/operations/system-tables/tables.md
index 8286d51aed6..6cf1490f14e 100644
--- a/docs/en/operations/system-tables/tables.md
+++ b/docs/en/operations/system-tables/tables.md
@@ -12,11 +12,13 @@ Columns:
- `name` ([String](../../sql-reference/data-types/string.md)) — Table name.
+- `uuid` ([UUID](../../sql-reference/data-types/uuid.md)) — Table uuid (Atomic database).
+
- `engine` ([String](../../sql-reference/data-types/string.md)) — Table engine name (without parameters).
- `is_temporary` ([UInt8](../../sql-reference/data-types/int-uint.md)) - Flag that indicates whether the table is temporary.
-- `data_path` ([String](../../sql-reference/data-types/string.md)) - Path to the table data in the file system.
+- `data_paths` ([Array](../../sql-reference/data-types/array.md)([String](../../sql-reference/data-types/string.md))) - Paths to the table data in the file systems.
- `metadata_path` ([String](../../sql-reference/data-types/string.md)) - Path to the table metadata in the file system.
@@ -60,6 +62,14 @@ Columns:
- `has_own_data` ([UInt8](../../sql-reference/data-types/int-uint.md)) — Flag that indicates whether the table itself stores some data on disk or only accesses some other source.
+- `loading_dependencies_database` ([Array](../../sql-reference/data-types/array.md)([String](../../sql-reference/data-types/string.md))) - Database loading dependencies (list of objects which should be loaded before the current object).
+
+- `loading_dependencies_table` ([Array](../../sql-reference/data-types/array.md)([String](../../sql-reference/data-types/string.md))) - Table loading dependencies (list of objects which should be loaded before the current object).
+
+- `loading_dependent_database` ([Array](../../sql-reference/data-types/array.md)([String](../../sql-reference/data-types/string.md))) - Dependent loading database.
+
+- `loading_dependent_table` ([Array](../../sql-reference/data-types/array.md)([String](../../sql-reference/data-types/string.md))) - Dependent loading table.
+
The `system.tables` table is used in `SHOW TABLES` query implementation.
**Example**
@@ -95,6 +105,10 @@ lifetime_rows: ᴺᵁᴸᴸ
lifetime_bytes: ᴺᵁᴸᴸ
comment:
has_own_data: 0
+loading_dependencies_database: []
+loading_dependencies_table: []
+loading_dependent_database: []
+loading_dependent_table: []
Row 2:
──────
@@ -122,4 +136,8 @@ lifetime_rows: ᴺᵁᴸᴸ
lifetime_bytes: ᴺᵁᴸᴸ
comment:
has_own_data: 0
+loading_dependencies_database: []
+loading_dependencies_table: []
+loading_dependent_database: []
+loading_dependent_table: []
```
diff --git a/docs/en/sql-reference/data-types/boolean.md b/docs/en/sql-reference/data-types/boolean.md
index a21b1c41a21..7b61579c4a9 100644
--- a/docs/en/sql-reference/data-types/boolean.md
+++ b/docs/en/sql-reference/data-types/boolean.md
@@ -3,10 +3,38 @@ sidebar_position: 43
sidebar_label: Boolean
---
-# Boolean Values {#boolean-values}
+# Boolean Values bool (boolean) {#boolean-values}
-Since https://github.com/ClickHouse/ClickHouse/commit/4076ae77b46794e73594a9f400200088ed1e7a6e , there be a separate type for boolean values.
+Type `bool` is stored as UInt8. Possible values `true` (1), `false` (0).
-For versions before that, there is no separate type for boolean values. Use UInt8 type, restricted to the values 0 or 1.
+
+```sql
+select true as col, toTypeName(col);
+┌─col──┬─toTypeName(true)─┐
+│ true │ Bool │
+└──────┴──────────────────┘
+
+select true == 1 as col, toTypeName(col);
+┌─col─┬─toTypeName(equals(true, 1))─┐
+│ 1 │ UInt8 │
+└─────┴─────────────────────────────┘
+```
+
+```sql
+CREATE TABLE test_bool
+(
+ `A` Int64,
+ `B` Bool
+)
+ENGINE = Memory;
+
+INSERT INTO test_bool VALUES (1, true),(2,0);
+
+SELECT * FROM test_bool;
+┌─A─┬─B─────┐
+│ 1 │ true │
+│ 2 │ false │
+└───┴───────┘
+```
[Original article](https://clickhouse.com/docs/en/data_types/boolean/)
diff --git a/docs/en/sql-reference/data-types/json.md b/docs/en/sql-reference/data-types/json.md
new file mode 100644
index 00000000000..41235d17cdb
--- /dev/null
+++ b/docs/en/sql-reference/data-types/json.md
@@ -0,0 +1,76 @@
+---
+sidebar_position: 54
+sidebar_label: JSON
+---
+
+# JSON {#json-data-type}
+
+Stores JavaScript Object Notation (JSON) documents in a single column.
+
+`JSON` is an alias for `Object('json')`.
+
+:::warning
+The JSON data type is an experimental feature. To use it, set `allow_experimental_object_type = 1`.
+:::
+
+## Example {#usage-example}
+
+**Example 1**
+
+Creating a table with a `JSON` column and inserting data into it:
+
+```sql
+CREATE TABLE json
+(
+ o JSON
+)
+ENGINE = Memory
+```
+
+```sql
+INSERT INTO json VALUES ('{"a": 1, "b": { "c": 2, "d": [1, 2, 3] }}')
+```
+
+```sql
+SELECT o.a, o.b.c, o.b.d[3] FROM json
+```
+
+```text
+┌─o.a─┬─o.b.c─┬─arrayElement(o.b.d, 3)─┐
+│ 1 │ 2 │ 3 │
+└─────┴───────┴────────────────────────┘
+```
+
+**Example 2**
+
+To be able to create an ordered `MergeTree` family table the sorting key has to be extracted into its column. For example, to insert a file of compressed HTTP access logs in JSON format:
+
+```sql
+CREATE TABLE logs
+(
+ timestamp DateTime,
+ message JSON
+)
+ENGINE = MergeTree
+ORDER BY timestamp
+```
+
+```sql
+INSERT INTO logs
+SELECT parseDateTimeBestEffort(JSONExtractString(json, 'timestamp')), json
+FROM file('access.json.gz', JSONAsString)
+```
+
+## Displaying JSON columns
+
+When displaying a `JSON` column ClickHouse only shows the field values by default (because internally, it is represented as a tuple). You can display the field names as well by setting `output_format_json_named_tuples_as_objects = 1`:
+
+```sql
+SET output_format_json_named_tuples_as_objects = 1
+
+SELECT * FROM json FORMAT JSONEachRow
+```
+
+```text
+{"o":{"a":1,"b":{"c":2,"d":[1,2,3]}}}
+```
diff --git a/docs/en/sql-reference/functions/geo/h3.md b/docs/en/sql-reference/functions/geo/h3.md
index 50115dd4d75..f4d199e6729 100644
--- a/docs/en/sql-reference/functions/geo/h3.md
+++ b/docs/en/sql-reference/functions/geo/h3.md
@@ -1026,4 +1026,119 @@ Result:
│ 41162 │
└─────────────┘
```
+
+## h3Line {#h3line}
+
+Returns the line of indices between the two indices that are provided.
+
+**Syntax**
+
+``` sql
+h3Line(start,end)
+```
+
+**Parameter**
+
+- `start` — Hexagon index number that represents a starting point. Type: [UInt64](../../../sql-reference/data-types/int-uint.md).
+- `end` — Hexagon index number that represents an ending point. Type: [UInt64](../../../sql-reference/data-types/int-uint.md).
+
+**Returned value**
+
+Array of h3 indexes representing the line of indices between the two provided indices:
+
+Type: [Array](../../../sql-reference/data-types/array.md)([UInt64](../../../sql-reference/data-types/int-uint.md)).
+
+**Example**
+
+Query:
+
+``` sql
+ SELECT h3Line(590080540275638271,590103561300344831) as indexes;
+```
+
+Result:
+
+``` text
+┌─indexes────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
+│ [590080540275638271,590080471556161535,590080883873021951,590106516237844479,590104385934065663,590103630019821567,590103561300344831] │
+└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
+```
+
+## h3Distance {#h3distance}
+
+Returns the distance in grid cells between the two indices that are provided.
+
+**Syntax**
+
+``` sql
+h3Distance(start,end)
+```
+
+**Parameter**
+
+- `start` — Hexagon index number that represents a starting point. Type: [UInt64](../../../sql-reference/data-types/int-uint.md).
+- `end` — Hexagon index number that represents an ending point. Type: [UInt64](../../../sql-reference/data-types/int-uint.md).
+
+**Returned value**
+
+- Number of grid cells.
+
+Type: [Int64](../../../sql-reference/data-types/int-uint.md).
+
+Returns a negative number if finding the distance fails.
+
+**Example**
+
+Query:
+
+``` sql
+ SELECT h3Distance(590080540275638271,590103561300344831) as distance;
+```
+
+Result:
+
+``` text
+┌─distance─┐
+│ 7 │
+└──────────┘
+```
+
+## h3HexRing {#h3hexring}
+
+Returns the indexes of the hexagonal ring centered at the provided origin h3Index and length k.
+
+Returns 0 if no pentagonal distortion was encountered.
+
+**Syntax**
+
+``` sql
+h3HexRing(index, k)
+```
+
+**Parameter**
+
+- `index` — Hexagon index number that represents the origin. Type: [UInt64](../../../sql-reference/data-types/int-uint.md).
+- `k` — Distance. Type: [UInt64](../../../sql-reference/data-types/int-uint.md).
+
+**Returned values**
+
+- Array of H3 indexes.
+
+Type: [Array](../../../sql-reference/data-types/array.md)([UInt64](../../../sql-reference/data-types/int-uint.md)).
+
+**Example**
+
+Query:
+
+``` sql
+ SELECT h3HexRing(590080540275638271, toUInt16(1)) AS hexRing;
+```
+
+Result:
+
+``` text
+┌─hexRing─────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
+│ [590080815153545215,590080471556161535,590080677714591743,590077585338138623,590077447899185151,590079509483487231] │
+└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
+```
[Original article](https://clickhouse.com/docs/en/sql-reference/functions/geo/h3)
diff --git a/docs/en/sql-reference/functions/random-functions.md b/docs/en/sql-reference/functions/random-functions.md
index 5e20a93da1f..3931898f081 100644
--- a/docs/en/sql-reference/functions/random-functions.md
+++ b/docs/en/sql-reference/functions/random-functions.md
@@ -96,10 +96,14 @@ SELECT fuzzBits(materialize('abacaba'), 0.1)
FROM numbers(3)
```
-\`\`\` text
-┌─fuzzBits(materialize(‘abacaba’), 0.1)─┐
-│ abaaaja │
-│ a\*cjab+ │
-│ aeca2A │
-└───────────────────────────────────────┘
+Result:
+
+``` text
+┌─fuzzBits(materialize('abacaba'), 0.1)─┐
+│ abaaaja │
+│ a*cjab+ │
+│ aeca2A │
+└───────────────────────────────────────┘
+```
+
diff --git a/docs/en/sql-reference/statements/create/user.md b/docs/en/sql-reference/statements/create/user.md
index 0aad0961a8b..34f0a13147c 100644
--- a/docs/en/sql-reference/statements/create/user.md
+++ b/docs/en/sql-reference/statements/create/user.md
@@ -29,12 +29,14 @@ There are multiple ways of user identification:
- `IDENTIFIED WITH no_password`
- `IDENTIFIED WITH plaintext_password BY 'qwerty'`
- `IDENTIFIED WITH sha256_password BY 'qwerty'` or `IDENTIFIED BY 'password'`
-- `IDENTIFIED WITH sha256_hash BY 'hash'`
+- `IDENTIFIED WITH sha256_hash BY 'hash'` or `IDENTIFIED WITH sha256_hash BY 'hash' SALT 'salt'`
- `IDENTIFIED WITH double_sha1_password BY 'qwerty'`
- `IDENTIFIED WITH double_sha1_hash BY 'hash'`
- `IDENTIFIED WITH ldap SERVER 'server_name'`
- `IDENTIFIED WITH kerberos` or `IDENTIFIED WITH kerberos REALM 'realm'`
+For identification with sha256_hash using `SALT` - hash must be calculated from concatination of 'password' and 'salt'.
+
## User Host {#user-host}
User host is a host from which a connection to ClickHouse server could be established. The host can be specified in the `HOST` query section in the following ways:
diff --git a/docs/en/sql-reference/statements/grant.md b/docs/en/sql-reference/statements/grant.md
index 1ee330061b5..b60114e10c5 100644
--- a/docs/en/sql-reference/statements/grant.md
+++ b/docs/en/sql-reference/statements/grant.md
@@ -170,6 +170,7 @@ Hierarchy of privileges:
- `SYSTEM FLUSH`
- `SYSTEM FLUSH DISTRIBUTED`
- `SYSTEM FLUSH LOGS`
+ - `CLUSTER` (see also `access_control_improvements.on_cluster_queries_require_cluster_grant` configuration directive)
- [INTROSPECTION](#grant-introspection)
- `addressToLine`
- `addressToLineWithInlines`
diff --git a/docs/en/sql-reference/syntax.md b/docs/en/sql-reference/syntax.md
index 41c95c6159e..f73b9a17c3d 100644
--- a/docs/en/sql-reference/syntax.md
+++ b/docs/en/sql-reference/syntax.md
@@ -104,7 +104,7 @@ There are many nuances to processing `NULL`. For example, if at least one of the
In queries, you can check `NULL` using the [IS NULL](../sql-reference/operators/index.md#operator-is-null) and [IS NOT NULL](../sql-reference/operators/index.md) operators and the related functions `isNull` and `isNotNull`.
-### Heredoc {#heredeoc}
+### Heredoc {#heredoc}
A [heredoc](https://en.wikipedia.org/wiki/Here_document) is a way to define a string (often multiline), while maintaining the original formatting. A heredoc is defined as a custom string literal, placed between two `$` symbols, for example `$heredoc$`. A value between two heredocs is processed "as-is".
diff --git a/docs/ru/faq/use-cases/time-series.md b/docs/ru/faq/use-cases/time-series.md
index d2229c30359..d7525214cba 100644
--- a/docs/ru/faq/use-cases/time-series.md
+++ b/docs/ru/faq/use-cases/time-series.md
@@ -5,7 +5,7 @@ sidebar_position: 101
# Можно ли использовать ClickHouse как базу данных временных рядов? {#can-i-use-clickhouse-as-a-time-series-database}
-ClickHouse — это универсальное решение для [OLAP](../../faq/general/olap.md) операций, в то время как существует много специализированных СУБД временных рядов. Однако [высокая скорость выполнения запросов](../../faq/general/why-clickhouse-is-so-fast.md) позволяет CLickHouse во многих случаях "побеждать" специализированные аналоги. В подтверждение этому есть много примеров с конкретными показателями производительности, так что мы не будем останавливаться на этом подробно. Лучше рассмотрим те возможности ClickHouse, которые стоит использовать.
+ClickHouse — это универсальное решение для [OLAP](../../faq/general/olap.md) операций, в то время как существует много специализированных СУБД временных рядов. Однако [высокая скорость выполнения запросов](../../faq/general/why-clickhouse-is-so-fast.md) позволяет ClickHouse во многих случаях "побеждать" специализированные аналоги. В подтверждение этому есть много примеров с конкретными показателями производительности, так что мы не будем останавливаться на этом подробно. Лучше рассмотрим те возможности ClickHouse, которые стоит использовать.
Во-первых, есть **[специальные кодеки](../../sql-reference/statements/create/table.md#create-query-specialized-codecs)**, которые составляют типичные временные ряды. Это могут быть либо стандартные алгоритмы, такие как `DoubleDelta` или `Gorilla`, либо специфические для ClickHouse, например `T64`.
diff --git a/docs/ru/operations/settings/settings.md b/docs/ru/operations/settings/settings.md
index ebcb8855238..9470e3e0f9b 100644
--- a/docs/ru/operations/settings/settings.md
+++ b/docs/ru/operations/settings/settings.md
@@ -2432,7 +2432,7 @@ SELECT idx, i FROM null_in WHERE i IN (1, NULL) SETTINGS transform_null_in = 1;
Разрешает или запрещает использование типа данных `LowCardinality` с форматом данных [Native](../../interfaces/formats.md#native).
-Если использование типа `LowCardinality` ограничено, сервер CLickHouse преобразует столбцы `LowCardinality` в обычные столбцы для запросов `SELECT`, а обычные столбцы - в столбцы `LowCardinality` для запросов `INSERT`.
+Если использование типа `LowCardinality` ограничено, сервер ClickHouse преобразует столбцы `LowCardinality` в обычные столбцы для запросов `SELECT`, а обычные столбцы - в столбцы `LowCardinality` для запросов `INSERT`.
В основном настройка используется для сторонних клиентов, не поддерживающих тип данных `LowCardinality`.
diff --git a/docs/ru/operations/system-tables/tables.md b/docs/ru/operations/system-tables/tables.md
index bf47051442e..ae5ca586a88 100644
--- a/docs/ru/operations/system-tables/tables.md
+++ b/docs/ru/operations/system-tables/tables.md
@@ -12,11 +12,13 @@
- `name` ([String](../../sql-reference/data-types/string.md)) — имя таблицы.
+- `uuid` ([UUID](../../sql-reference/data-types/uuid.md)) — Uuid таблицы (Atomic database).
+
- `engine` ([String](../../sql-reference/data-types/string.md)) — движок таблицы (без параметров).
- `is_temporary` ([UInt8](../../sql-reference/data-types/int-uint.md)) — флаг, указывающий на то, временная это таблица или нет.
-- `data_path` ([String](../../sql-reference/data-types/string.md)) — путь к данным таблицы в файловой системе.
+- `data_paths` ([Array](../../sql-reference/data-types/array.md)([String](../../sql-reference/data-types/string.md))) — пути к данным таблицы в файловых системах.
- `metadata_path` ([String](../../sql-reference/data-types/string.md)) — путь к табличным метаданным в файловой системе.
@@ -60,6 +62,14 @@
- `has_own_data` ([UInt8](../../sql-reference/data-types/int-uint.md)) — флаг, показывающий хранит ли таблица сама какие-то данные на диске или только обращается к какому-то другому источнику.
+- `loading_dependencies_database` ([Array](../../sql-reference/data-types/array.md)([String](../../sql-reference/data-types/string.md))) - базы данных необходимые для загрузки объекта.
+
+- `loading_dependencies_table` ([Array](../../sql-reference/data-types/array.md)([String](../../sql-reference/data-types/string.md))) - таблицы необходимые для загрузки объекта.
+
+- `loading_dependent_database` ([Array](../../sql-reference/data-types/array.md)([String](../../sql-reference/data-types/string.md))) - базы данных, которым объект необходим для загрузки.
+
+- `loading_dependent_table` ([Array](../../sql-reference/data-types/array.md)([String](../../sql-reference/data-types/string.md))) - таблицы, которым объект необходим для загрузки.
+
Таблица `system.tables` используется при выполнении запроса `SHOW TABLES`.
**Пример**
@@ -95,6 +105,10 @@ lifetime_rows: ᴺᵁᴸᴸ
lifetime_bytes: ᴺᵁᴸᴸ
comment:
has_own_data: 0
+loading_dependencies_database: []
+loading_dependencies_table: []
+loading_dependent_database: []
+loading_dependent_table: []
Row 2:
──────
@@ -122,4 +136,8 @@ lifetime_rows: ᴺᵁᴸᴸ
lifetime_bytes: ᴺᵁᴸᴸ
comment:
has_own_data: 0
+loading_dependencies_database: []
+loading_dependencies_table: []
+loading_dependent_database: []
+loading_dependent_table: []
```
diff --git a/docs/ru/sql-reference/data-types/boolean.md b/docs/ru/sql-reference/data-types/boolean.md
index 2e18f1a35fe..621d3550eaa 100644
--- a/docs/ru/sql-reference/data-types/boolean.md
+++ b/docs/ru/sql-reference/data-types/boolean.md
@@ -3,7 +3,35 @@ sidebar_position: 43
sidebar_label: "Булевы значения"
---
-# Булевы значения {#bulevy-znacheniia}
+# Булевы значения bool (boolean) {#bulevy-znacheniia}
-Отдельного типа для булевых значений нет. Для них используется тип UInt8, в котором используются только значения 0 и 1.
+Тип `bool` хранится как UInt8. Значения `true` (1), `false` (0).
+```sql
+select true as col, toTypeName(col);
+┌─col──┬─toTypeName(true)─┐
+│ true │ Bool │
+└──────┴──────────────────┘
+
+select true == 1 as col, toTypeName(col);
+┌─col─┬─toTypeName(equals(true, 1))─┐
+│ 1 │ UInt8 │
+└─────┴─────────────────────────────┘
+```
+
+```sql
+CREATE TABLE test_bool
+(
+ `A` Int64,
+ `B` Bool
+)
+ENGINE = Memory;
+
+INSERT INTO test_bool VALUES (1, true),(2,0);
+
+SELECT * FROM test_bool;
+┌─A─┬─B─────┐
+│ 1 │ true │
+│ 2 │ false │
+└───┴───────┘
+```
diff --git a/docs/ru/sql-reference/statements/create/user.md b/docs/ru/sql-reference/statements/create/user.md
index 78c481e8eb7..d7da1748821 100644
--- a/docs/ru/sql-reference/statements/create/user.md
+++ b/docs/ru/sql-reference/statements/create/user.md
@@ -29,12 +29,14 @@ CREATE USER [IF NOT EXISTS | OR REPLACE] name1 [ON CLUSTER cluster_name1]
- `IDENTIFIED WITH no_password`
- `IDENTIFIED WITH plaintext_password BY 'qwerty'`
- `IDENTIFIED WITH sha256_password BY 'qwerty'` or `IDENTIFIED BY 'password'`
-- `IDENTIFIED WITH sha256_hash BY 'hash'`
+- `IDENTIFIED WITH sha256_hash BY 'hash'` or `IDENTIFIED WITH sha256_hash BY 'hash' SALT 'salt'`
- `IDENTIFIED WITH double_sha1_password BY 'qwerty'`
- `IDENTIFIED WITH double_sha1_hash BY 'hash'`
- `IDENTIFIED WITH ldap SERVER 'server_name'`
- `IDENTIFIED WITH kerberos` or `IDENTIFIED WITH kerberos REALM 'realm'`
+Для идентификации с sha256_hash используя `SALT` - хэш должен быть вычислен от конкатенации 'password' и 'salt'.
+
## Пользовательский хост
Пользовательский хост — это хост, с которого можно установить соединение с сервером ClickHouse. Хост задается в секции `HOST` следующими способами:
diff --git a/docs/ru/sql-reference/syntax.md b/docs/ru/sql-reference/syntax.md
index 5c187a43721..17eb0165a4e 100644
--- a/docs/ru/sql-reference/syntax.md
+++ b/docs/ru/sql-reference/syntax.md
@@ -102,7 +102,7 @@ INSERT INTO t VALUES (1, 'Hello, world'), (2, 'abc'), (3, 'def')
В запросах можно проверить `NULL` с помощью операторов [IS NULL](operators/index.md#operator-is-null) и [IS NOT NULL](operators/index.md), а также соответствующих функций `isNull` и `isNotNull`.
-### Heredoc {#heredeoc}
+### Heredoc {#heredoc}
Синтаксис [heredoc](https://ru.wikipedia.org/wiki/Heredoc-синтаксис) — это способ определения строк с сохранением исходного формата (часто с переносом строки). `Heredoc` задается как произвольный строковый литерал между двумя символами `$`, например `$heredoc$`. Значение между двумя `heredoc` обрабатывается "как есть".
diff --git a/docs/zh/sql-reference/functions/bit-functions.md b/docs/zh/sql-reference/functions/bit-functions.md
index dd6958afec1..b2e9230c799 100644
--- a/docs/zh/sql-reference/functions/bit-functions.md
+++ b/docs/zh/sql-reference/functions/bit-functions.md
@@ -4,26 +4,437 @@
结果类型是一个整数,其位数等于其参数的最大位。如果至少有一个参数为有符数字,则结果为有符数字。如果参数是浮点数,则将其强制转换为Int64。
-## bitAnd(a,b) {#bitanda-b}
+## bitAnd(a, b) {#bitanda-b}
-## bitOr(a,b) {#bitora-b}
+## bitOr(a, b) {#bitora-b}
-## bitXor(a,b) {#bitxora-b}
+## bitXor(a, b) {#bitxora-b}
## bitNot(a) {#bitnota}
-## bitShiftLeft(a,b) {#bitshiftlefta-b}
+## bitShiftLeft(a, b) {#bitshiftlefta-b}
-## bitShiftRight(a,b) {#bitshiftrighta-b}
+将值的二进制表示向左移动指定数量的位。
-## bitRotateLeft(a,b) {#bitrotatelefta-b}
+`FixedString` 或 `String` 被视为单个多字节值。
-## bitRotateRight(a,b) {#bitrotaterighta-b}
+`FixedString` 值的位在移出时会丢失。相反,`String` 值使用额外的字节进行扩展,因此不会丢失任何位。
-## bitTest(a,b) {#bittesta-b}
+**语法**
-## bitTestAll(a,b) {#bittestalla-b}
+``` sql
+bitShiftLeft(a, b)
+```
+
+**参数**
+
+- `a` — 要进行移位操作的值。类型可以为[Integer types](../../sql-reference/data-types/int-uint.md),[String](../../sql-reference/data-types/string.md)或者[FixedString](../../sql-reference/data-types/fixedstring.md)。
+- `b` — 移位的次数。类型为[Unsigned integer types](../../sql-reference/data-types/int-uint.md),允许使用64位数字及64位以下的数字类型。
+
+**返回值**
+
+- 移位后的值。
+
+返回值的类型与输入值的类型相同。
+
+**示例**
+
+在以下查询中,[bin](encoding-functions.md#bin)和[hex](encoding-functions.md#hex)函数用于显示移位值的位。
+
+``` sql
+SELECT 99 AS a, bin(a), bitShiftLeft(a, 2) AS a_shifted, bin(a_shifted);
+SELECT 'abc' AS a, hex(a), bitShiftLeft(a, 4) AS a_shifted, hex(a_shifted);
+SELECT toFixedString('abc', 3) AS a, hex(a), bitShiftLeft(a, 4) AS a_shifted, hex(a_shifted);
+```
+
+结果:
+
+``` text
+┌──a─┬─bin(99)──┬─a_shifted─┬─bin(bitShiftLeft(99, 2))─┐
+│ 99 │ 01100011 │ 140 │ 10001100 │
+└────┴──────────┴───────────┴──────────────────────────┘
+┌─a───┬─hex('abc')─┬─a_shifted─┬─hex(bitShiftLeft('abc', 4))─┐
+│ abc │ 616263 │ &0 │ 06162630 │
+└─────┴────────────┴───────────┴─────────────────────────────┘
+┌─a───┬─hex(toFixedString('abc', 3))─┬─a_shifted─┬─hex(bitShiftLeft(toFixedString('abc', 3), 4))─┐
+│ abc │ 616263 │ &0 │ 162630 │
+└─────┴──────────────────────────────┴───────────┴───────────────────────────────────────────────┘
+```
+
+## bitShiftRight(a, b) {#bitshiftrighta-b}
+
+将值的二进制表示向右移动指定数量的位。
+
+`FixedString`或`String`被视为单个多字节值。请注意,`String`值的长度会随着位的移出而减少。
+
+**语法**
+
+``` sql
+bitShiftRight(a, b)
+```
+
+**参数**
+
+- `a` — 需要进行位移的值。类型可以为[Integer types](../../sql-reference/data-types/int-uint.md),[String](../../sql-reference/data-types/string.md)或者[FixedString](../../sql-reference/data-types/fixedstring.md)。
+- `b` — 移位的次数。类型为[Unsigned integer types](../../sql-reference/data-types/int-uint.md),允许使用64位数字及64位以下的数字类型。
+
+**返回值**
+
+- 移位后的值。
+
+返回值的类型与输入值的类型相同。
+
+**示例**
+
+查询语句:
+
+``` sql
+SELECT 101 AS a, bin(a), bitShiftRight(a, 2) AS a_shifted, bin(a_shifted);
+SELECT 'abc' AS a, hex(a), bitShiftRight(a, 12) AS a_shifted, hex(a_shifted);
+SELECT toFixedString('abc', 3) AS a, hex(a), bitShiftRight(a, 12) AS a_shifted, hex(a_shifted);
+```
+
+结果:
+
+``` text
+┌───a─┬─bin(101)─┬─a_shifted─┬─bin(bitShiftRight(101, 2))─┐
+│ 101 │ 01100101 │ 25 │ 00011001 │
+└─────┴──────────┴───────────┴────────────────────────────┘
+┌─a───┬─hex('abc')─┬─a_shifted─┬─hex(bitShiftRight('abc', 12))─┐
+│ abc │ 616263 │ │ 0616 │
+└─────┴────────────┴───────────┴───────────────────────────────┘
+┌─a───┬─hex(toFixedString('abc', 3))─┬─a_shifted─┬─hex(bitShiftRight(toFixedString('abc', 3), 12))─┐
+│ abc │ 616263 │ │ 000616 │
+└─────┴──────────────────────────────┴───────────┴─────────────────────────────────────────────────┘
+```
+
+## bitRotateLeft(a, b) {#bitrotatelefta-b}
+
+## bitRotateRight(a, b) {#bitrotaterighta-b}
+
+## bitSlice(s, offset, length)
+
+返回从`offset`索引中的`length`位长的位开始的子字符串,位索引从 1 开始。
+
+**语法**
+
+``` sql
+bitSlice(s, offset[, length])
+```
+
+**参数**
+
+- `s` — 类型可以是[String](../../sql-reference/data-types/string.md)或者[FixedString](../../sql-reference/data-types/fixedstring.md)。
+- `offset` — 带位的起始索引,正值表示左侧偏移,负值表示右侧缩进,位编号从 1 开始。
+- `length` — 带位的子串长度。如果您指定一个负值,该函数将返回一个开放子字符串 \[offset, array_length - length\]。如果省略该值,该函数将返回子字符串 \[offset, the_end_string\]。如果长度超过s,将被截断。如果长度不是8的倍数,则在右边填充0。
+
+**返回值**
+
+- 子字符串,类型为[String](../../sql-reference/data-types/string.md)。
+
+**示例**
+
+查询语句:
+
+``` sql
+select bin('Hello'), bin(bitSlice('Hello', 1, 8))
+select bin('Hello'), bin(bitSlice('Hello', 1, 2))
+select bin('Hello'), bin(bitSlice('Hello', 1, 9))
+select bin('Hello'), bin(bitSlice('Hello', -4, 8))
+```
+
+结果:
+
+``` text
+┌─bin('Hello')─────────────────────────────┬─bin(bitSlice('Hello', 1, 8))─┐
+│ 0100100001100101011011000110110001101111 │ 01001000 │
+└──────────────────────────────────────────┴──────────────────────────────┘
+┌─bin('Hello')─────────────────────────────┬─bin(bitSlice('Hello', 1, 2))─┐
+│ 0100100001100101011011000110110001101111 │ 01000000 │
+└──────────────────────────────────────────┴──────────────────────────────┘
+┌─bin('Hello')─────────────────────────────┬─bin(bitSlice('Hello', 1, 9))─┐
+│ 0100100001100101011011000110110001101111 │ 0100100000000000 │
+└──────────────────────────────────────────┴──────────────────────────────┘
+┌─bin('Hello')─────────────────────────────┬─bin(bitSlice('Hello', -4, 8))─┐
+│ 0100100001100101011011000110110001101111 │ 11110000 │
+└──────────────────────────────────────────┴───────────────────────────────┘
+```
+
+## bitTest {#bittest}
+
+取任意整数并将其转换为[binary form](https://en.wikipedia.org/wiki/Binary_number),返回指定位置的位值。位值从右到左数,从0开始计数。
+
+**语法**
+
+``` sql
+SELECT bitTest(number, index)
+```
+
+**参数**
+
+- `number` – 整数。
+- `index` – 要获取位值的位置。
+
+**返回值**
+
+返回指定位置的位值
+
+类型为:`UInt8`。
+
+**示例**
+
+例如,十进制数字 43 在二进制的表示是 101011。
+
+查询语句:
+
+``` sql
+SELECT bitTest(43, 1);
+```
+
+结果:
+
+``` text
+┌─bitTest(43, 1)─┐
+│ 1 │
+└────────────────┘
+```
+
+另一个示例:
+
+查询语句:
+
+``` sql
+SELECT bitTest(43, 2);
+```
+
+结果:
+
+``` text
+┌─bitTest(43, 2)─┐
+│ 0 │
+└────────────────┘
+```
+
+## bitTestAll {#bittestall}
+
+返回给定位置所有位的 [logical conjuction](https://en.wikipedia.org/wiki/Logical_conjunction) 进行与操作的结果。位值从右到左数,从0开始计数。
+
+与运算的结果:
+
+0 AND 0 = 0
+
+0 AND 1 = 0
+
+1 AND 0 = 0
+
+1 AND 1 = 1
+
+**语法**
+
+``` sql
+SELECT bitTestAll(number, index1, index2, index3, index4, ...)
+```
+
+**参数**
+
+- `number` – 整数。
+- `index1`, `index2`, `index3`, `index4` – 位的位置。例如,对于一组位置 (`index1`, `index2`, `index3`, `index4`) 当且仅当它的所有位置都为真时才为真 (`index1` ⋀ `index2`, ⋀ `index3` ⋀ `index4` )。
+
+**返回值**
+
+返回逻辑与的结果。
+
+类型为: `UInt8`。
+
+**示例**
+
+例如,十进制数字 43 在二进制的表示是 101011。
+
+查询语句:
+
+``` sql
+SELECT bitTestAll(43, 0, 1, 3, 5);
+```
+
+结果:
+
+``` text
+┌─bitTestAll(43, 0, 1, 3, 5)─┐
+│ 1 │
+└────────────────────────────┘
+```
+
+另一个例子:
+
+查询语句:
+
+``` sql
+SELECT bitTestAll(43, 0, 1, 3, 5, 2);
+```
+
+结果:
+
+``` text
+┌─bitTestAll(43, 0, 1, 3, 5, 2)─┐
+│ 0 │
+└───────────────────────────────┘
+```
+
+## bitTestAny {#bittestany}
+
+返回给定位置所有位的 [logical disjunction](https://en.wikipedia.org/wiki/Logical_disjunction) 进行或操作的结果。位值从右到左数,从0开始计数。
+
+或运算的结果:
+
+0 OR 0 = 0
+
+0 OR 1 = 1
+
+1 OR 0 = 1
+
+1 OR 1 = 1
+
+**语法**
+
+``` sql
+SELECT bitTestAny(number, index1, index2, index3, index4, ...)
+```
+
+**参数**
+
+- `number` – 整数。
+- `index1`, `index2`, `index3`, `index4` – 位的位置。
+
+**返回值**
+
+返回逻辑或的结果。
+
+类型为: `UInt8`。
+
+**示例**
+
+例如,十进制数字 43 在二进制的表示是 101011。
+
+查询语句:
+
+``` sql
+SELECT bitTestAny(43, 0, 2);
+```
+
+结果:
+
+``` text
+┌─bitTestAny(43, 0, 2)─┐
+│ 1 │
+└──────────────────────┘
+```
+
+另一个例子:
+
+查询语句:
+
+``` sql
+SELECT bitTestAny(43, 4, 2);
+```
+
+结果:
+
+``` text
+┌─bitTestAny(43, 4, 2)─┐
+│ 0 │
+└──────────────────────┘
+```
+
+## bitCount {#bitcount}
+
+计算数字的二进制表示中值为 1 的位数。
+
+**语法**
+
+``` sql
+bitCount(x)
+```
+
+**参数**
+
+- `x` — 类型为[Integer](../../sql-reference/data-types/int-uint.md)或[floating-point](../../sql-reference/data-types/float.md)数字。该函数使用内存中的值表示。它允许支持浮点数。
+
+**返回值**
+
+- 输入数字中值为 1 的位数。
+
+该函数不会将输入值转换为更大的类型 ([sign extension](https://en.wikipedia.org/wiki/Sign_extension))。 因此,例如,`bitCount(toUInt8(-1)) = 8`。
+
+类型为: `UInt8`。
+
+**示例**
+
+以十进制数字 333 为例,它的二进制表示为: 0000000101001101。
+
+查询语句:
+
+``` sql
+SELECT bitCount(333);
+```
+
+结果:
+
+``` text
+┌─bitCount(333)─┐
+│ 5 │
+└───────────────┘
+```
+
+## bitHammingDistance {#bithammingdistance}
+
+返回两个整数值的位表示之间的 [Hamming Distance](https://en.wikipedia.org/wiki/Hamming_distance)。可与 [SimHash](../../sql-reference/functions/hash-functions.md#ngramsimhash) 函数一起使用,用于检测半重复字符串。距离越小,这些字符串就越有可能相同。
+
+**语法**
+
+``` sql
+bitHammingDistance(int1, int2)
+```
+
+**参数**
+
+- `int1` — 第一个整数值。类型为[Int64](../../sql-reference/data-types/int-uint.md)。
+- `int2` — 第二个整数值。类型为[Int64](../../sql-reference/data-types/int-uint.md)。
+
+**返回值**
+
+- 汉明距离。
+
+类型为: [UInt8](../../sql-reference/data-types/int-uint.md)。
+
+**示例**
+
+查询语句:
+
+``` sql
+SELECT bitHammingDistance(111, 121);
+```
+
+结果:
+
+``` text
+┌─bitHammingDistance(111, 121)─┐
+│ 3 │
+└──────────────────────────────┘
+```
+
+使用[SimHash](../../sql-reference/functions/hash-functions.md#ngramsimhash)函数:
+
+``` sql
+SELECT bitHammingDistance(ngramSimHash('cat ate rat'), ngramSimHash('rat ate cat'));
+```
+
+结果:
+
+``` text
+┌─bitHammingDistance(ngramSimHash('cat ate rat'), ngramSimHash('rat ate cat'))─┐
+│ 5 │
+└──────────────────────────────────────────────────────────────────────────────┘
+```
-## bitTestAny(a,b) {#bittestanya-b}
[来源文章](https://clickhouse.com/docs/en/query_language/functions/bit_functions/)
diff --git a/docs/zh/sql-reference/functions/conditional-functions.md b/docs/zh/sql-reference/functions/conditional-functions.md
index ce421138d0e..64b4c96478a 100644
--- a/docs/zh/sql-reference/functions/conditional-functions.md
+++ b/docs/zh/sql-reference/functions/conditional-functions.md
@@ -12,6 +12,8 @@ SELECT if(cond, then, else)
如果条件 `cond` 的计算结果为非零值,则返回表达式 `then` 的结果,并且跳过表达式 `else` 的结果(如果存在)。 如果 `cond` 为零或 `NULL`,则将跳过 `then` 表达式的结果,并返回 `else` 表达式的结果(如果存在)。
+您可以使用[short_circuit_function_evaluation](../../operations/settings/settings.md#short-circuit-function-evaluation) 设置,来根据短路方案计算 `if` 函数。如果启用此设置,则仅在`cond`为真的时,加载`then`表达式,此时不加载`else`表达式。仅在`cond`为假时,加载`else`表达式,此时不加载`then`表达式。例如,执行查询`SELECT if(number = 0, 0, intDiv(42, number)) FROM numbers(10)`时不会抛出除以零的异常,因为`intDiv(42, number)`会仅对不满足条件`number = 0`的数字进行处理。
+
**参数**
- `cond` – 条件结果可以为零或不为零。 类型是 UInt8,Nullable(UInt8) 或 NULL。
@@ -102,11 +104,21 @@ WHERE isNotNull(left) AND isNotNull(right)
- `then`和`else`可以是`NULL`
+**参考**
+
+- [ifNotFinite](../../sql-reference/functions/other-functions.md#ifnotfinite)。
+
## multiIf {#multiif}
允许您在查询中更紧凑地编写[CASE](../operators/index.md#operator_case)运算符。
- multiIf(cond_1, then_1, cond_2, then_2...else)
+**语法**
+
+``` sql
+multiIf(cond_1, then_1, cond_2, then_2, ..., else)
+```
+
+您可以使用[short_circuit_function_evaluation](../../operations/settings/settings.md#short-circuit-function-evaluation) 设置,根据短路方案计算 `multiIf` 函数。如果启用此设置,则 `then_i` 表达式仅在 `((NOT cond_1) AND (NOT cond_2) AND ... AND (NOT cond_{i-1}) AND cond_i)` 为真,`cond_i ` 将仅对 `((NOT cond_1) AND (NOT cond_2) AND ... AND (NOT cond_{i-1}))` 为真的行进行执行。例如,执行查询“SELECT multiIf(number = 2, intDiv(1, number), number = 5) FROM numbers(10)”时不会抛出除以零的异常。
**参数:**
diff --git a/docs/zh/sql-reference/functions/date-time-functions.md b/docs/zh/sql-reference/functions/date-time-functions.md
index 96477fadb3b..f268e9584ce 100644
--- a/docs/zh/sql-reference/functions/date-time-functions.md
+++ b/docs/zh/sql-reference/functions/date-time-functions.md
@@ -12,16 +12,61 @@ SELECT
toString(time, 'US/Samoa') AS time_samoa
```
- ┌────────────────time─┬─date_local─┬─date_yekat─┬─time_samoa──────────┐
- │ 2016-06-15 23:00:00 │ 2016-06-15 │ 2016-06-16 │ 2016-06-15 09:00:00 │
- └─────────────────────┴────────────┴────────────┴─────────────────────┘
+``` text
+┌────────────────time─┬─date_local─┬─date_yekat─┬─time_samoa──────────┐
+│ 2016-06-15 23:00:00 │ 2016-06-15 │ 2016-06-16 │ 2016-06-15 09:00:00 │
+└─────────────────────┴────────────┴────────────┴─────────────────────┘
+```
仅支持与UTC相差一整小时的时区。
+## timeZone {#timezone}
+
+返回服务器的时区。
+如果它在分布式表的上下文中执行,那么它会生成一个普通列,其中包含与每个分片相关的值。否则它会产生一个常数值。
+
+**语法**
+
+``` sql
+timeZone()
+```
+
+别名:`timezone`。
+
+**返回值**
+
+- 时区。
+
+类型为: [String](../../sql-reference/data-types/string.md)。
+
+
## toTimeZone {#totimezone}
将Date或DateTime转换为指定的时区。 时区是Date/DateTime类型的属性。 表字段或结果集的列的内部值(秒数)不会更改,列的类型会更改,并且其字符串表示形式也会相应更改。
+**语法**
+
+``` sql
+toTimezone(value, timezone)
+```
+
+别名:`toTimezone`。
+
+**参数**
+
+- `value` — 时间或日期和时间。类型为[DateTime64](../../sql-reference/data-types/datetime64.md)。
+- `timezone` — 返回值的时区。类型为 [String](../../sql-reference/data-types/string.md)。 这个参数是一个常量,因为 `toTimezone` 改变了列的时区(时区是 `DateTime` 类型的属性)。
+
+**返回值**
+
+- 日期和时间。
+
+类型为: [DateTime](../../sql-reference/data-types/datetime.md)。
+
+**示例**
+
+查询语句:
+
```sql
SELECT
toDateTime('2019-01-01 00:00:00', 'UTC') AS time_utc,
@@ -52,44 +97,138 @@ int32samoa: 1546300800
`toTimeZone(time_utc, 'Asia/Yekaterinburg')` 把 `DateTime('UTC')` 类型转换为 `DateTime('Asia/Yekaterinburg')`. 内部值 (Unixtimestamp) 1546300800 保持不变, 但是字符串表示(toString() 函数的结果值) 由 `time_utc: 2019-01-01 00:00:00` 转换为o `time_yekat: 2019-01-01 05:00:00`.
+## timeZoneOf {#timezoneof}
+
+返回[DateTime](../../sql-reference/data-types/datetime.md)或者[DateTime64](../../sql-reference/data-types/datetime64.md)数据类型的时区名称。
+
+**语法**
+
+``` sql
+timeZoneOf(value)
+```
+
+别名: `timezoneOf`。
+
+**参数**
+
+- `value` — 日期和时间。类型为[DateTime](../../sql-reference/data-types/datetime.md)或者[DateTime64](../../sql-reference/data-types/datetime64.md)。
+
+**返回值**
+
+- 时区名称。
+
+类型为:[String](../../sql-reference/data-types/string.md)。
+
+**示例**
+
+查询语句:
+``` sql
+SELECT timezoneOf(now());
+```
+
+结果:
+``` text
+┌─timezoneOf(now())─┐
+│ Etc/UTC │
+└───────────────────┘
+```
+
+## timeZoneOffset {#timezoneoffset}
+
+返回从[UTC](https://en.wikipedia.org/wiki/Coordinated_Universal_Time)开始到现在以秒为单位的时区偏移量。该函数考虑到[夏时令](https://en.wikipedia.org/wiki/Daylight_saving_time)并在指定日期和时间更改历史时区。
+[IANA timezone database](https://www.iana.org/time-zones)用于计算偏移量。
+
+**语法**
+
+``` sql
+timeZoneOffset(value)
+```
+
+别名: `timezoneOffset`。
+
+**参数**
+
+- `value` — 日期和时间。类型为[DateTime](../../sql-reference/data-types/datetime.md)或者[DateTime64](../../sql-reference/data-types/datetime64.md)。
+
+**返回值**
+
+- 以秒为单位的UTC偏移量。
+
+类型为: [Int32](../../sql-reference/data-types/int-uint.md)。
+
+**示例**
+
+查询语句:
+
+``` sql
+SELECT toDateTime('2021-04-21 10:20:30', 'America/New_York') AS Time, toTypeName(Time) AS Type,
+ timeZoneOffset(Time) AS Offset_in_seconds, (Offset_in_seconds / 3600) AS Offset_in_hours;
+```
+
+结果:
+
+``` text
+┌────────────────Time─┬─Type─────────────────────────┬─Offset_in_seconds─┬─Offset_in_hours─┐
+│ 2021-04-21 10:20:30 │ DateTime('America/New_York') │ -14400 │ -4 │
+└─────────────────────┴──────────────────────────────┴───────────────────┴─────────────────┘
+```
+
## toYear {#toyear}
将Date或DateTime转换为包含年份编号(AD)的UInt16类型的数字。
+别名为:`YEAR`。
+
## toQuarter {#toquarter}
将Date或DateTime转换为包含季度编号的UInt8类型的数字。
+别名为:`QUARTER`。
+
## toMonth {#tomonth}
将Date或DateTime转换为包含月份编号(1-12)的UInt8类型的数字。
+别名为:`MONTH`。
+
## toDayOfYear {#todayofyear}
将Date或DateTime转换为包含一年中的某一天的编号的UInt16(1-366)类型的数字。
+别名为: `DAYOFYEAR`。
+
## toDayOfMonth {#todayofmonth}
将Date或DateTime转换为包含一月中的某一天的编号的UInt8(1-31)类型的数字。
+别名为:`DAYOFMONTH`,`DAY`。
+
## toDayOfWeek {#todayofweek}
将Date或DateTime转换为包含一周中的某一天的编号的UInt8(周一是1, 周日是7)类型的数字。
+别名为:`DAYOFWEEK`。
+
## toHour {#tohour}
将DateTime转换为包含24小时制(0-23)小时数的UInt8数字。
这个函数假设如果时钟向前移动,它是一个小时,发生在凌晨2点,如果时钟被移回,它是一个小时,发生在凌晨3点(这并非总是如此 - 即使在莫斯科时钟在不同的时间两次改变)。
+别名为: `HOUR`。
+
## toMinute {#tominute}
将DateTime转换为包含一小时中分钟数(0-59)的UInt8数字。
+别名为: `MINUTE`。
+
## toSecond {#tosecond}
将DateTime转换为包含一分钟中秒数(0-59)的UInt8数字。
闰秒不计算在内。
+别名为: `SECOND`。
+
## toUnixTimestamp {#to-unix-timestamp}
对于DateTime参数:将值转换为UInt32类型的数字-Unix时间戳(https://en.wikipedia.org/wiki/Unix_time)。
@@ -124,6 +263,10 @@ SELECT toUnixTimestamp('2017-11-05 08:07:47', 'Asia/Tokyo') AS unix_timestamp
└────────────────┘
```
+:::注意
+下面描述的返回类型 `toStartOf` 函数是 `Date` 或 `DateTime`。尽管这些函数可以将 `DateTime64` 作为参数,但将超出正常范围(1925年-2283年)的 `DateTime64` 传递给它们会给出不正确的结果。
+:::
+
## toStartOfYear {#tostartofyear}
将Date或DateTime向前取整到本年的第一天。
@@ -429,6 +572,263 @@ SELECT now(), date_trunc('hour', now(), 'Asia/Istanbul');
- [toStartOfInterval](#tostartofintervaltime-or-data-interval-x-unit-time-zone)
+## date_add {#date_add}
+
+将时间间隔或日期间隔添加到提供的日期或带时间的日期。
+
+**语法**
+
+``` sql
+date_add(unit, value, date)
+```
+
+别名为:`dateAdd`, `DATE_ADD`。
+
+**参数**
+
+- `unit` — `value`对应的时间单位。类型为[String](../../sql-reference/data-types/string.md)。
+ 可能的值:
+
+ - `second`
+ - `minute`
+ - `hour`
+ - `day`
+ - `week`
+ - `month`
+ - `quarter`
+ - `year`
+
+- `value` — 要添加的间隔值。类型为[Int](../../sql-reference/data-types/int-uint.md)。
+- `date` — 添加`value`的日期或日期。类型为[Date](../../sql-reference/data-types/date.md)或者[DateTime](../../sql-reference/data-types/datetime.md)。
+
+**返回值**
+
+通过将 `value` 以`unit` 表示,添加到`date` 获得的日期或带时间的日期。
+
+类型为: [Date](../../sql-reference/data-types/date.md)或[DateTime](../../sql-reference/data-types/datetime.md)。
+
+**示例**
+
+查询语句:
+
+```sql
+SELECT date_add(YEAR, 3, toDate('2018-01-01'));
+```
+
+结果:
+
+```text
+┌─plus(toDate('2018-01-01'), toIntervalYear(3))─┐
+│ 2021-01-01 │
+└───────────────────────────────────────────────┘
+```
+
+## date_diff {#date_diff}
+
+返回两个日期或具有时间值的日期之间的差值。
+
+**语法**
+
+``` sql
+date_diff('unit', startdate, enddate, [timezone])
+```
+
+别名为: `dateDiff`, `DATE_DIFF`。
+
+**参数**
+
+- `unit` — `value`对应的时间单位。类型为[String](../../sql-reference/data-types/string.md)。
+ 可能的值:
+
+ - `second`
+ - `minute`
+ - `hour`
+ - `day`
+ - `week`
+ - `month`
+ - `quarter`
+ - `year`
+
+- `startdate` — 要减去的第一个时间值(减数)。类型为[Date](../../sql-reference/data-types/date.md)或者[DateTime](../../sql-reference/data-types/datetime.md)。
+
+- `enddate` — 要减去的第二个时间值(被减数)。类型为[Date](../../sql-reference/data-types/date.md)或者[DateTime](../../sql-reference/data-types/datetime.md)。
+
+- `timezone` — [Timezone name](../../operations/server-configuration-parameters/settings.md#server_configuration_parameters-timezone) (可选项)。如果指定,它适用于 `startdate` 和 `enddate`。如果未指定,则使用 `startdate` 和 `enddate` 的时区。如果它们不相同,则结果未指定。类型为[String](../../sql-reference/data-types/string.md)。
+
+**返回值**
+
+以 `unit` 表示的 `enddate` 和 `startdate` 之间的区别。
+
+类型为: [Int](../../sql-reference/data-types/int-uint.md)。
+
+**示例**
+
+查询语句:
+
+``` sql
+SELECT dateDiff('hour', toDateTime('2018-01-01 22:00:00'), toDateTime('2018-01-02 23:00:00'));
+```
+
+结果:
+
+``` text
+┌─dateDiff('hour', toDateTime('2018-01-01 22:00:00'), toDateTime('2018-01-02 23:00:00'))─┐
+│ 25 │
+└────────────────────────────────────────────────────────────────────────────────────────┘
+```
+
+## date_sub {#date_sub}
+
+从提供的日期或带时间的日期中减去时间间隔或日期间隔。
+
+**语法**
+
+``` sql
+date_sub(unit, value, date)
+```
+
+别名为: `dateSub`, `DATE_SUB`.
+
+**参数**
+
+- `unit` — `value`对应的时间单位。类型为[String](../../sql-reference/data-types/string.md)。
+ 可能的值:
+
+ - `second`
+ - `minute`
+ - `hour`
+ - `day`
+ - `week`
+ - `month`
+ - `quarter`
+ - `year`
+
+- `value` — 要减去的时间。类型为[Int](../../sql-reference/data-types/int-uint.md)。
+- `date` — 被减去`value`的日期或日期。类型为[Date](../../sql-reference/data-types/date.md)或者[DateTime](../../sql-reference/data-types/datetime.md)。
+
+**返回值**
+
+从 `date` 中减去以`unit` 表示的`value` 得到的日期或带时间的日期。
+
+类型为:[Date](../../sql-reference/data-types/date.md) or [DateTime](../../sql-reference/data-types/datetime.md)。
+
+**示例**
+
+查询语句:
+
+``` sql
+SELECT date_sub(YEAR, 3, toDate('2018-01-01'));
+```
+
+结果:
+
+``` text
+┌─minus(toDate('2018-01-01'), toIntervalYear(3))─┐
+│ 2015-01-01 │
+└────────────────────────────────────────────────┘
+```
+
+## timestamp_add {#timestamp_add}
+
+将指定的时间值与提供的日期或日期时间值相加。
+
+**语法**
+
+``` sql
+timestamp_add(date, INTERVAL value unit)
+```
+
+别名为: `timeStampAdd`, `TIMESTAMP_ADD`.
+
+**参数**
+
+- `date` — 日期或日期与时间。类型为[Date](../../sql-reference/data-types/date.md)或者[DateTime](../../sql-reference/data-types/datetime.md)。
+- `value` — 要添加的间隔值。类型为[Int](../../sql-reference/data-types/int-uint.md)。
+- `unit` — `value`对应的时间单位。类型为[String](../../sql-reference/data-types/string.md)。
+ 可能的值:
+
+ - `second`
+ - `minute`
+ - `hour`
+ - `day`
+ - `week`
+ - `month`
+ - `quarter`
+ - `year`
+
+**返回值**
+
+以`unit`表示的指定`value`的日期或带时间的日期添加到`date`。
+
+类型为:[Date](../../sql-reference/data-types/date.md)或者[DateTime](../../sql-reference/data-types/datetime.md)。
+
+**示例**
+
+查询语句:
+
+```sql
+select timestamp_add(toDate('2018-01-01'), INTERVAL 3 MONTH);
+```
+
+结果:
+
+```text
+┌─plus(toDate('2018-01-01'), toIntervalMonth(3))─┐
+│ 2018-04-01 │
+└────────────────────────────────────────────────┘
+```
+
+## timestamp_sub {#timestamp_sub}
+
+从提供的日期或带时间的日期中减去时间间隔。
+
+**语法**
+
+``` sql
+timestamp_sub(unit, value, date)
+```
+
+别名为: `timeStampSub`, `TIMESTAMP_SUB`。
+
+**参数**
+
+- `unit` — `value`对应的时间单位。类型为[String](../../sql-reference/data-types/string.md)。
+ 可能的值:
+
+ - `second`
+ - `minute`
+ - `hour`
+ - `day`
+ - `week`
+ - `month`
+ - `quarter`
+ - `year`
+
+- `value` — 要减去的间隔值。类型为[Int](../../sql-reference/data-types/int-uint.md)。
+- `date` — 日期或日期与时间。类型为[Date](../../sql-reference/data-types/date.md)或者[DateTime](../../sql-reference/data-types/datetime.md)。
+
+**返回值**
+
+从 `date` 中减去以`unit` 表示的`value` 得到的日期或带时间的日期。
+
+类型为: [Date](../../sql-reference/data-types/date.md)或者[DateTime](../../sql-reference/data-types/datetime.md)。
+
+**示例**
+
+查询语句:
+
+```sql
+select timestamp_sub(MONTH, 5, toDateTime('2018-12-18 01:02:03'));
+```
+
+结果:
+
+```text
+┌─minus(toDateTime('2018-12-18 01:02:03'), toIntervalMonth(5))─┐
+│ 2018-07-18 01:02:03 │
+└──────────────────────────────────────────────────────────────┘
+```
+
# now {#now}
返回当前日期和时间。
@@ -540,50 +940,6 @@ SELECT
│ 2018-01-01 │ 2018-01-01 00:00:00 │
└──────────────────────────┴───────────────────────────────┘
-## dateDiff {#datediff}
-
-返回两个Date或DateTime类型之间的时差。
-
-**语法**
-
-``` sql
-dateDiff('unit', startdate, enddate, [timezone])
-```
-
-**参数**
-
-- `unit` — 返回结果的时间单位。 [String](../../sql-reference/syntax.md#syntax-string-literal).
-
- 支持的时间单位: second, minute, hour, day, week, month, quarter, year.
-
-- `startdate` — 第一个待比较值。 [Date](../../sql-reference/data-types/date.md) 或 [DateTime](../../sql-reference/data-types/datetime.md).
-
-- `enddate` — 第二个待比较值。 [Date](../../sql-reference/data-types/date.md) 或 [DateTime](../../sql-reference/data-types/datetime.md).
-
-- `timezone` — 可选参数。 如果指定了,则同时适用于`startdate`和`enddate`。如果不指定,则使用`startdate`和`enddate`的时区。如果两个时区不一致,则结果不可预料。
-
-**返回值**
-
-以`unit`为单位的`startdate`和`enddate`之间的时差。
-
-类型: `int`.
-
-**示例**
-
-查询:
-
-``` sql
-SELECT dateDiff('hour', toDateTime('2018-01-01 22:00:00'), toDateTime('2018-01-02 23:00:00'));
-```
-
-结果:
-
-``` text
-┌─dateDiff('hour', toDateTime('2018-01-01 22:00:00'), toDateTime('2018-01-02 23:00:00'))─┐
-│ 25 │
-└────────────────────────────────────────────────────────────────────────────────────────┘
-```
-
## timeSlots(StartTime, Duration,\[, Size\]) {#timeslotsstarttime-duration-size}
它返回一个时间数组,其中包括从从«StartTime»开始到«StartTime + Duration 秒»内的所有符合«size»(以秒为单位)步长的时间点。其中«size»是一个可选参数,默认为1800。
@@ -652,7 +1008,44 @@ SELECT formatDateTime(toDate('2010-01-04'), '%g')
└────────────────────────────────────────────┘
```
-[Original article](https://clickhouse.com/docs/en/query_language/functions/date_time_functions/)
+## dateName {#dataname}
+
+返回日期的指定部分。
+
+**语法**
+
+``` sql
+dateName(date_part, date)
+```
+
+**参数**
+
+- `date_part` — 日期部分。可能的值为:'year', 'quarter', 'month', 'week', 'dayofyear', 'day', 'weekday', 'hour', 'minute', 'second'。类型为[String](../../sql-reference/data-types/string.md)。
+- `date` — 日期。类型为[Date](../../sql-reference/data-types/date.md), [DateTime](../../sql-reference/data-types/datetime.md)或者[DateTime64](../../sql-reference/data-types/datetime64.md)。
+- `timezone` — 时区(可选项)。类型为[String](../../sql-reference/data-types/string.md)。
+
+**返回值**
+
+- 日期的指定部分。
+
+类型为: [String](../../sql-reference/data-types/string.md#string)。
+
+**示例**
+
+查询语句:
+
+```sql
+WITH toDateTime('2021-04-14 11:22:33') AS date_value
+SELECT dateName('year', date_value), dateName('month', date_value), dateName('day', date_value);
+```
+
+结果:
+
+```text
+┌─dateName('year', date_value)─┬─dateName('month', date_value)─┬─dateName('day', date_value)─┐
+│ 2021 │ April │ 14 │
+└──────────────────────────────┴───────────────────────────────┴─────────────────────────────
+```
## FROM_UNIXTIME
@@ -683,3 +1076,149 @@ SELECT FROM_UNIXTIME(1234334543, '%Y-%m-%d %R:%S') AS DateTime
│ 2009-02-11 14:42:23 │
└─────────────────────┘
```
+
+## toModifiedJulianDay {#tomodifiedjulianday}
+
+将文本形式 `YYYY-MM-DD` 的 [Proleptic Gregorian calendar](https://en.wikipedia.org/wiki/Proleptic_Gregorian_calendar) 日期转换为 Int32 中的 [Modified Julian Day](https://en.wikipedia.org/wiki/Julian_day#Variants) 数字。此功能支持从`0000-01-01`到`9999-12-31`的日期。如果无法将参数解析为日期或日期无效,则会引发异常。
+
+**语法**
+
+``` sql
+toModifiedJulianDay(date)
+```
+
+**参数**
+
+- `date` — 文本形式的日期。类型为[String](../../sql-reference/data-types/string.md)或者[FixedString](../../sql-reference/data-types/fixedstring.md)。
+
+**返回值**
+
+- 转换的儒略日数。
+
+类型为: [Int32](../../sql-reference/data-types/int-uint.md)。
+
+**示例**
+
+查询语句:
+
+``` sql
+SELECT toModifiedJulianDay('2020-01-01');
+```
+
+结果:
+
+``` text
+┌─toModifiedJulianDay('2020-01-01')─┐
+│ 58849 │
+└───────────────────────────────────┘
+```
+
+## toModifiedJulianDayOrNull {#tomodifiedjuliandayornull}
+
+类似于[toModifiedJulianDay()](#tomodifiedjulianday),但它不会引发异常,而是返回 `NULL`。
+
+**语法**
+
+``` sql
+toModifiedJulianDayOrNull(date)
+```
+
+**参数**
+
+- `date` — 文本形式的日期。类型为[String](../../sql-reference/data-types/string.md)或者[FixedString](../../sql-reference/data-types/fixedstring.md)。
+
+**返回值**
+
+- 转换的儒略日数。
+
+类型为: [Nullable(Int32)](../../sql-reference/data-types/int-uint.md)。
+
+**示例**
+
+查询语句:
+
+``` sql
+SELECT toModifiedJulianDayOrNull('2020-01-01');
+```
+
+结果:
+
+``` text
+┌─toModifiedJulianDayOrNull('2020-01-01')─┐
+│ 58849 │
+└─────────────────────────────────────────┘
+```
+
+## fromModifiedJulianDay {#frommodifiedjulianday}
+
+将 [Modified Julian Day](https://en.wikipedia.org/wiki/Julian_day#Variants) 数字转换为 `YYYY-MM-DD` 文本格式的 [Proleptic Gregorian calendar](https://en.wikipedia.org/wiki/Proleptic_Gregorian_calendar) 日期。该函数支持从 `-678941` 到 `2973119` 的天数(分别代表 0000-01-01 和 9999-12-31)。如果天数超出支持范围,则会引发异常。
+
+**语法**
+
+``` sql
+fromModifiedJulianDay(day)
+```
+
+**参数**
+
+- `day` — 需要转换的儒略日数。类型为[Any integral types](../../sql-reference/data-types/int-uint.md)。
+
+**返回值**
+
+- 文本形式的日期。
+
+类型为: [String](../../sql-reference/data-types/string.md)。
+
+**示例**
+
+查询语句:
+
+``` sql
+SELECT fromModifiedJulianDay(58849);
+```
+
+结果:
+
+``` text
+┌─fromModifiedJulianDay(58849)─┐
+│ 2020-01-01 │
+└──────────────────────────────┘
+```
+
+## fromModifiedJulianDayOrNull {#frommodifiedjuliandayornull}
+
+类似于[fromModifiedJulianDayOrNull()](#frommodifiedjuliandayornull),但它不会引发异常,而是返回 `NULL`。
+
+**语法**
+
+``` sql
+fromModifiedJulianDayOrNull(day)
+```
+
+**参数**
+
+- `day` — 需要转换的儒略日数。类型为[Any integral types](../../sql-reference/data-types/int-uint.md)。
+
+**返回值**
+
+- 文本形式的日期。
+
+类型为: [Nullable(String)](../../sql-reference/data-types/string.md)。
+
+**示例**
+
+查询语句:
+
+``` sql
+SELECT fromModifiedJulianDayOrNull(58849);
+```
+
+结果:
+
+``` text
+┌─fromModifiedJulianDayOrNull(58849)─┐
+│ 2020-01-01 │
+└────────────────────────────────────┘
+```
+
+[Original article](https://clickhouse.com/docs/en/query_language/functions/date_time_functions/)
\ No newline at end of file
diff --git a/docs/zh/sql-reference/functions/encoding-functions.md b/docs/zh/sql-reference/functions/encoding-functions.md
index f1152965d2d..b9a3cbf0550 100644
--- a/docs/zh/sql-reference/functions/encoding-functions.md
+++ b/docs/zh/sql-reference/functions/encoding-functions.md
@@ -68,12 +68,306 @@ SELECT char(0xE4, 0xBD, 0xA0, 0xE5, 0xA5, 0xBD) AS hello;
## hex {#hex}
-接受`String`,`unsigned integer`,`Date`或`DateTime`类型的参数。返回包含参数的十六进制表示的字符串。使用大写字母`A-F`。不使用`0x`前缀或`h`后缀。对于字符串,所有字节都简单地编码为两个十六进制数字。数字转换为大端(«易阅读»)格式。对于数字,去除其中较旧的零,但仅限整个字节。例如,`hex(1)='01'`。 `Date`被编码为自Unix时间开始以来的天数。 `DateTime`编码为自Unix时间开始以来的秒数。
+返回包含参数的十六进制表示的字符串。
-## unhex(str) {#unhexstr}
+别名为: `HEX`。
-接受包含任意数量的十六进制数字的字符串,并返回包含相应字节的字符串。支持大写和小写字母A-F。十六进制数字的数量不必是偶数。如果是奇数,则最后一位数被解释为00-0F字节的低位。如果参数字符串包含除十六进制数字以外的任何内容,则返回一些实现定义的结果(不抛出异常)。
-如果要将结果转换为数字,可以使用«reverse»和«reinterpretAsType»函数。
+**语法**
+
+``` sql
+hex(arg)
+```
+
+该函数使用大写字母`A-F`,不使用任何前缀(如`0x`)或后缀(如`h`)
+
+对于整数参数,它从高到低(大端或“人类可读”顺序)打印十六进制数字(“半字节”)。它从左侧第一个非零字节开始(省略前导零字节),但即使前导数字为零,也始终打印每个字节的两个数字。
+
+类型为[Date](../../sql-reference/data-types/date.md)和[DateTime](../../sql-reference/data-types/datetime.md)的值将被格式化为相应的整数(日期为 Epoch 以来的天数,DateTime 为 Unix Timestamp 的值)。
+
+对于[String](../../sql-reference/data-types/string.md)和[FixedString](../../sql-reference/data-types/fixedstring.md),所有字节都被简单地编码为两个十六进制数字。零字节不会被省略。
+
+类型为[Float](../../sql-reference/data-types/float.md)和[Decimal](../../sql-reference/data-types/decimal.md)的值被编码为它们在内存中的表示。由于我们支持小端架构,它们以小端编码。零前导尾随字节不会被省略。
+
+类型为[UUID](../data-types/uuid.md)的值被编码为大端顺序字符串。
+
+**参数**
+
+- `arg` — 要转换为十六进制的值。类型为[String](../../sql-reference/data-types/string.md),[UInt](../../sql-reference/data-types/int-uint.md),[Float](../../sql-reference/data-types/float.md),[Decimal](../../sql-reference/data-types/decimal.md),[Date](../../sql-reference/data-types/date.md)或者[DateTime](../../sql-reference/data-types/datetime.md)。
+
+**返回值**
+
+- 具有参数的十六进制表示的字符串。
+
+类型为:[String](../../sql-reference/data-types/string.md)。
+
+**示例**
+
+查询语句:
+
+``` sql
+SELECT hex(1);
+```
+
+结果:
+
+``` text
+01
+```
+
+查询语句:
+
+``` sql
+SELECT hex(toFloat32(number)) AS hex_presentation FROM numbers(15, 2);
+```
+
+结果:
+
+``` text
+┌─hex_presentation─┐
+│ 00007041 │
+│ 00008041 │
+└──────────────────┘
+```
+
+查询语句:
+
+``` sql
+SELECT hex(toFloat64(number)) AS hex_presentation FROM numbers(15, 2);
+```
+
+结果:
+
+``` text
+┌─hex_presentation─┐
+│ 0000000000002E40 │
+│ 0000000000003040 │
+└──────────────────┘
+```
+
+查询语句:
+
+``` sql
+SELECT lower(hex(toUUID('61f0c404-5cb3-11e7-907b-a6006ad3dba0'))) as uuid_hex
+```
+
+结果:
+
+``` text
+┌─uuid_hex─────────────────────────┐
+│ 61f0c4045cb311e7907ba6006ad3dba0 │
+└──────────────────────────────────┘
+```
+
+## unhex {#unhexstr}
+
+执行[hex](#hex)函数的相反操作。它将每对十六进制数字(在参数中)解释为一个数字,并将其转换为该数字表示的字节。返回值是一个二进制字符串 (BLOB)。
+
+如果要将结果转换为数字,可以使用 [reverse](../../sql-reference/functions/string-functions.md#reverse) 和 [reinterpretAs<Type>](../../sql-reference/functions/type-conversion-functions.md#type-conversion-functions) 函数。
+
+:::注意
+如果从 `clickhouse-client` 中调用 `unhex`,二进制字符串将使用 UTF-8 显示。
+:::
+
+别名为:`UNHEX`。
+
+**语法**
+
+``` sql
+unhex(arg)
+```
+
+**参数**
+
+- `arg` — 包含任意数量的十六进制数字的字符串。类型为:[String](../../sql-reference/data-types/string.md)。
+
+支持大写和小写字母A-F。十六进制数字的数量不必是偶数。如果是奇数,则最后一位数被解释为00-0F字节的低位。如果参数字符串包含除十六进制数字以外的任何内容,则返回一些实现定义的结果(不抛出异常)。对于数字参数, unhex()不执行 hex(N) 的倒数。
+
+**返回值**
+
+- 二进制字符串 (BLOB)。
+
+类型为: [String](../../sql-reference/data-types/string.md)。
+
+**示例**
+
+查询语句:
+``` sql
+SELECT unhex('303132'), UNHEX('4D7953514C');
+```
+
+结果:
+``` text
+┌─unhex('303132')─┬─unhex('4D7953514C')─┐
+│ 012 │ MySQL │
+└─────────────────┴─────────────────────┘
+```
+
+查询语句:
+
+``` sql
+SELECT reinterpretAsUInt64(reverse(unhex('FFF'))) AS num;
+```
+
+结果:
+
+``` text
+┌──num─┐
+│ 4095 │
+└──────┘
+```
+
+## bin {#bin}
+
+返回一个包含参数二进制表示的字符串。
+
+**语法**
+
+``` sql
+bin(arg)
+```
+
+别名为: `BIN`。
+
+对于整数参数,它从最高有效到最低有效(大端或“人类可读”顺序)打印 bin 数字。它从最重要的非零字节开始(省略前导零字节),但如果前导数字为零,则始终打印每个字节的八位数字。
+
+类型为[Date](../../sql-reference/data-types/date.md)和[DateTime](../../sql-reference/data-types/datetime.md)的值被格式化为相应的整数(`Date` 为 Epoch 以来的天数,`DateTime` 为 Unix Timestamp 的值)。
+
+对于[String](../../sql-reference/data-types/string.md)和[FixedString](../../sql-reference/data-types/fixedstring.md),所有字节都被简单地编码为八个二进制数。零字节不会被省略。
+
+类型为[Float](../../sql-reference/data-types/float.md)和[Decimal](../../sql-reference/data-types/decimal.md)的值被编码为它们在内存中的表示。由于我们支持小端架构,它们以小端编码。零前导尾随字节不会被省略。
+
+类型为[UUID](../data-types/uuid.md)的值被编码为大端顺序字符串。
+
+**参数**
+
+- `arg` — 要转换为二进制的值。类型为[String](../../sql-reference/data-types/string.md),[FixedString](../../sql-reference/data-types/fixedstring.md),[UInt](../../sql-reference/data-types/int-uint.md),[Float](../../sql-reference/data-types/float.md),[Decimal](../../sql-reference/data-types/decimal.md),[Date](../../sql-reference/data-types/date.md)或者[DateTime](../../sql-reference/data-types/datetime.md)。
+
+**返回值**
+
+- 具有参数的二进制表示的字符串。
+
+类型为: [String](../../sql-reference/data-types/string.md)。
+
+**示例**
+
+查询语句:
+
+``` sql
+SELECT bin(14);
+```
+
+结果:
+
+``` text
+┌─bin(14)──┐
+│ 00001110 │
+└──────────┘
+```
+
+查询语句:
+
+``` sql
+SELECT bin(toFloat32(number)) AS bin_presentation FROM numbers(15, 2);
+```
+
+结果:
+
+``` text
+┌─bin_presentation─────────────────┐
+│ 00000000000000000111000001000001 │
+│ 00000000000000001000000001000001 │
+└──────────────────────────────────┘
+```
+
+查询语句:
+
+``` sql
+SELECT bin(toFloat64(number)) AS bin_presentation FROM numbers(15, 2);
+```
+
+结果:
+
+``` text
+┌─bin_presentation─────────────────────────────────────────────────┐
+│ 0000000000000000000000000000000000000000000000000010111001000000 │
+│ 0000000000000000000000000000000000000000000000000011000001000000 │
+└──────────────────────────────────────────────────────────────────┘
+```
+
+查询语句:
+
+``` sql
+SELECT bin(toUUID('61f0c404-5cb3-11e7-907b-a6006ad3dba0')) as bin_uuid
+```
+
+结果:
+
+``` text
+┌─bin_uuid─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
+│ 01100001111100001100010000000100010111001011001100010001111001111001000001111011101001100000000001101010110100111101101110100000 │
+└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
+```
+
+
+## unbin {#unbinstr}
+
+将每对二进制数字(在参数中)解释为一个数字,并将其转换为该数字表示的字节。这些函数执行与 [bin](#bin) 相反的操作。
+
+**语法**
+
+``` sql
+unbin(arg)
+```
+
+别名为: `UNBIN`。
+
+对于数字参数,`unbin()` 不会返回 `bin()` 的倒数。如果要将结果转换为数字,可以使用[reverse](../../sql-reference/functions/string-functions.md#reverse) 和 [reinterpretAs<Type>](../../sql-reference/functions/type-conversion-functions.md#reinterpretasuint8163264) 函数。
+
+:::note
+如果从 `clickhouse-client` 中调用 `unbin`,则使用 UTF-8 显示二进制字符串。
+:::
+
+支持二进制数字`0`和`1`。二进制位数不必是八的倍数。如果参数字符串包含二进制数字以外的任何内容,则返回一些实现定义的结果(不抛出异常)。
+
+**参数**
+
+- `arg` — 包含任意数量的二进制数字的字符串。类型为[String](../../sql-reference/data-types/string.md)。
+
+**返回值**
+
+- 二进制字符串 (BLOB)。
+
+类型为:[String](../../sql-reference/data-types/string.md)。
+
+**示例**
+
+查询语句:
+
+``` sql
+SELECT UNBIN('001100000011000100110010'), UNBIN('0100110101111001010100110101000101001100');
+```
+
+结果:
+
+``` text
+┌─unbin('001100000011000100110010')─┬─unbin('0100110101111001010100110101000101001100')─┐
+│ 012 │ MySQL │
+└───────────────────────────────────┴───────────────────────────────────────────────────┘
+```
+
+查询语句:
+
+``` sql
+SELECT reinterpretAsUInt64(reverse(unbin('1110'))) AS num;
+```
+
+结果:
+
+``` text
+┌─num─┐
+│ 14 │
+└─────┘
+```
## UUIDStringToNum(str) {#uuidstringtonumstr}
@@ -91,4 +385,55 @@ SELECT char(0xE4, 0xBD, 0xA0, 0xE5, 0xA5, 0xBD) AS hello;
接受一个整数。返回一个UInt64类型数组,其中包含一组2的幂列表,其列表中的所有值相加等于这个整数。数组中的数字按升序排列。
+## bitPositionsToArray(num) {#bitpositionstoarraynum}
+
+接受整数并将其转换为无符号整数。返回一个 `UInt64` 数字数组,其中包含 `arg` 中等于 `1` 的位的位置列表,按升序排列。
+
+**语法**
+
+```sql
+bitPositionsToArray(arg)
+```
+
+**参数**
+
+- `arg` — 整数值。类型为[Int/UInt](../../sql-reference/data-types/int-uint.md)。
+
+**返回值**
+
+- 包含等于 `1` 的位位置列表的数组,按升序排列。
+
+类型为: [Array](../../sql-reference/data-types/array.md)([UInt64](../../sql-reference/data-types/int-uint.md))。
+
+**示例**
+
+查询语句:
+
+``` sql
+SELECT bitPositionsToArray(toInt8(1)) AS bit_positions;
+```
+
+结果:
+
+``` text
+┌─bit_positions─┐
+│ [0] │
+└───────────────┘
+```
+
+查询语句:
+
+``` sql
+SELECT bitPositionsToArray(toInt8(-1)) AS bit_positions;
+```
+
+结果:
+
+``` text
+┌─bit_positions─────┐
+│ [0,1,2,3,4,5,6,7] │
+└───────────────────┘
+```
+
+
[来源文章](https://clickhouse.com/docs/en/query_language/functions/encoding_functions/)
diff --git a/programs/bash-completion/completions/clickhouse-bootstrap b/programs/bash-completion/completions/clickhouse-bootstrap
index 98fcd68db16..8684f122503 100644
--- a/programs/bash-completion/completions/clickhouse-bootstrap
+++ b/programs/bash-completion/completions/clickhouse-bootstrap
@@ -34,6 +34,12 @@ CLICKHOUSE_QueryProcessingStage=(
with_mergeable_state_after_aggregation_and_limit
)
+CLICKHOUSE_QueryKind=(
+ initial_query
+ secondary_query
+ no_query
+)
+
CLICKHOUSE_Format=(
CapnProto
PostgreSQLWire
@@ -124,6 +130,10 @@ function _complete_for_clickhouse_generic_bin_impl()
COMPREPLY=( $(compgen -W "${CLICKHOUSE_QueryProcessingStage[*]}" -- "$cur") )
return 1
;;
+ --query_kind)
+ COMPREPLY=( $(compgen -W "${CLICKHOUSE_QueryKind[*]}" -- "$cur") )
+ return 1
+ ;;
--send_logs_level)
COMPREPLY=( $(compgen -W "${CLICKHOUSE_logs_level[*]}" -- "$cur") )
return 1
diff --git a/programs/benchmark/Benchmark.cpp b/programs/benchmark/Benchmark.cpp
index a4c0d92898d..5b77883c7b0 100644
--- a/programs/benchmark/Benchmark.cpp
+++ b/programs/benchmark/Benchmark.cpp
@@ -1,8 +1,8 @@
#include
-#include
+#include
#include
-#include
-#include
+#include
+#include
#include
#include
#include
diff --git a/programs/client/Client.cpp b/programs/client/Client.cpp
index 3a6dfb161a2..cbbf195a68c 100644
--- a/programs/client/Client.cpp
+++ b/programs/client/Client.cpp
@@ -1,4 +1,4 @@
-#include
+#include
#include
#include