From 80d8f4bd6043457e5d35fd83319713fad2688934 Mon Sep 17 00:00:00 2001 From: sundyli <543950155@qq.com> Date: Wed, 17 Oct 2018 06:43:36 -0500 Subject: [PATCH] add datatypes translate (#3403) * add datatypes translate * fixed some left English --- docs/zh/data_types/array.md | 9 +- docs/zh/data_types/boolean.md | 6 +- docs/zh/data_types/date.md | 9 +- docs/zh/data_types/datetime.md | 17 ++- docs/zh/data_types/decimal.md | 101 +++++++++++++++++- docs/zh/data_types/enum.md | 35 +++++- docs/zh/data_types/fixedstring.md | 10 +- docs/zh/data_types/float.md | 73 ++++++++++++- docs/zh/data_types/index.md | 10 +- docs/zh/data_types/int_uint.md | 23 +++- .../aggregatefunction.md | 6 +- .../nested_data_structures/index.md | 5 +- .../nested_data_structures/nested.md | 100 ++++++++++++++++- docs/zh/data_types/nullable.md | 60 ++++++++++- .../special_data_types/expression.md | 6 +- .../zh/data_types/special_data_types/index.md | 6 +- .../data_types/special_data_types/nothing.md | 25 ++++- docs/zh/data_types/special_data_types/set.md | 6 +- docs/zh/data_types/string.md | 14 ++- docs/zh/data_types/tuple.md | 54 +++++++++- docs/zh/interfaces/formats.md | 4 +- 21 files changed, 557 insertions(+), 22 deletions(-) mode change 120000 => 100644 docs/zh/data_types/array.md mode change 120000 => 100644 docs/zh/data_types/boolean.md mode change 120000 => 100644 docs/zh/data_types/date.md mode change 120000 => 100644 docs/zh/data_types/datetime.md mode change 120000 => 100644 docs/zh/data_types/decimal.md mode change 120000 => 100644 docs/zh/data_types/enum.md mode change 120000 => 100644 docs/zh/data_types/fixedstring.md mode change 120000 => 100644 docs/zh/data_types/float.md mode change 120000 => 100644 docs/zh/data_types/index.md mode change 120000 => 100644 docs/zh/data_types/int_uint.md mode change 120000 => 100644 docs/zh/data_types/nested_data_structures/aggregatefunction.md mode change 120000 => 100644 docs/zh/data_types/nested_data_structures/index.md mode change 120000 => 100644 docs/zh/data_types/nested_data_structures/nested.md mode change 120000 => 100644 docs/zh/data_types/nullable.md mode change 120000 => 100644 docs/zh/data_types/special_data_types/expression.md mode change 120000 => 100644 docs/zh/data_types/special_data_types/index.md mode change 120000 => 100644 docs/zh/data_types/special_data_types/nothing.md mode change 120000 => 100644 docs/zh/data_types/special_data_types/set.md mode change 120000 => 100644 docs/zh/data_types/string.md mode change 120000 => 100644 docs/zh/data_types/tuple.md diff --git a/docs/zh/data_types/array.md b/docs/zh/data_types/array.md deleted file mode 120000 index 808c98bf91a..00000000000 --- a/docs/zh/data_types/array.md +++ /dev/null @@ -1 +0,0 @@ -../../en/data_types/array.md \ No newline at end of file diff --git a/docs/zh/data_types/array.md b/docs/zh/data_types/array.md new file mode 100644 index 00000000000..155d32500da --- /dev/null +++ b/docs/zh/data_types/array.md @@ -0,0 +1,8 @@ + + +# Array(T) + +一个包含类型 T 的 数组(Array)。T 类型可以是任意类型,包括数组类型。 +我们不推荐使用多维数组,因为多维数组并没有得到很好支持(比如,不能在 MergeTree 引擎的表中存储多维数组)。 + +[来源文章](https://clickhouse.yandex/docs/en/data_types/array/) \ No newline at end of file diff --git a/docs/zh/data_types/boolean.md b/docs/zh/data_types/boolean.md deleted file mode 120000 index 42e84f1e52a..00000000000 --- a/docs/zh/data_types/boolean.md +++ /dev/null @@ -1 +0,0 @@ -../../en/data_types/boolean.md \ No newline at end of file diff --git a/docs/zh/data_types/boolean.md b/docs/zh/data_types/boolean.md new file mode 100644 index 00000000000..26485028358 --- /dev/null +++ b/docs/zh/data_types/boolean.md @@ -0,0 +1,5 @@ +# Boolean values + +没有单独的类型来存储 boolean 值。可以使用 UInt8 类型,取值限制为 0 或 1。 + +[来源文章](https://clickhouse.yandex/docs/en/data_types/boolean/) diff --git a/docs/zh/data_types/date.md b/docs/zh/data_types/date.md deleted file mode 120000 index d1ebc137e8f..00000000000 --- a/docs/zh/data_types/date.md +++ /dev/null @@ -1 +0,0 @@ -../../en/data_types/date.md \ No newline at end of file diff --git a/docs/zh/data_types/date.md b/docs/zh/data_types/date.md new file mode 100644 index 00000000000..39475a6558a --- /dev/null +++ b/docs/zh/data_types/date.md @@ -0,0 +1,8 @@ +# Date + +Date 用两个字节来存储从 1970-01-01 到现在的日期值(无符号的值)。Date 允许存储的值 UNIX 纪元开始后的时间值,这个值上限会在编译阶段作为一个常量存储(当前只能到 2038 年,但可以拓展到 2106 年)。 +Date 最小的值为 0000-00-00 00:00:00。 + +Date 中没有存储时区信息。 + +[来源文章](https://clickhouse.yandex/docs/en/data_types/date/) diff --git a/docs/zh/data_types/datetime.md b/docs/zh/data_types/datetime.md deleted file mode 120000 index 2eb9f44e6eb..00000000000 --- a/docs/zh/data_types/datetime.md +++ /dev/null @@ -1 +0,0 @@ -../../en/data_types/datetime.md \ No newline at end of file diff --git a/docs/zh/data_types/datetime.md b/docs/zh/data_types/datetime.md new file mode 100644 index 00000000000..4cf8661e218 --- /dev/null +++ b/docs/zh/data_types/datetime.md @@ -0,0 +1,16 @@ +# DateTime + +包含时间和日期。用4个字节来存储 Unix 时间戳(无符号的值)。允许存储的时间范围同 Date 类型。最小的值为 0000-00-00 00:00:00。 +DateTime 类型值精确到秒(不考虑闰秒) + +## Time zones + +在客户端或服务器启动时,会使用系统的时区来将时间日期从文本(划分成多个部分)到二进制之间相互转化。在文本格式中,有关夏令时信息不作存储。 + +默认情况下,客户端连接到服务的时候会使用服务端时区。可以通过客户端命令行参数 `--use_client_time_zone` 来设置使用客户端时区。 + +在所有的时区内,只支持部分与UTC相差整数小时(不考虑闰秒)的时区。 + +因此,在处理文本日期时(例如,在保存文本转储时),请记住在夏时制期间可能会出现歧义,如果时区发生变化,可能会出现与数据匹配的问题。 + +[来源文章](https://clickhouse.yandex/docs/en/data_types/datetime/) diff --git a/docs/zh/data_types/decimal.md b/docs/zh/data_types/decimal.md deleted file mode 120000 index ccea440adfa..00000000000 --- a/docs/zh/data_types/decimal.md +++ /dev/null @@ -1 +0,0 @@ -../../en/data_types/decimal.md \ No newline at end of file diff --git a/docs/zh/data_types/decimal.md b/docs/zh/data_types/decimal.md new file mode 100644 index 00000000000..a18394409fd --- /dev/null +++ b/docs/zh/data_types/decimal.md @@ -0,0 +1,100 @@ + + +# Decimal(P, S), Decimal32(S), Decimal64(S), Decimal128(S) + +有符号的定点数,在进行加减乘操作的过程中都会保留精度。对于除法,最低有效数字被丢弃(不舍入)。 + +## 参数 + +- P - 精度。范围值: [ 1 : 38 ],决定可以有多少个十进制数字(包括分数)。 +- S - 范围。范围值: [ 0 : P ],决定小数的位数。 + +对于不同的 P 参数值 Decimal 表示,以下例子都是同义的: +- [ 1 : 9 ] 的 P - for Decimal32(S) +- [ 10 : 18 ] 的 P - for Decimal64(S) +- [ 19 : 38 ] 的 P - for Decimal128(S) + +## 十进制值范围 + +- Decimal32(S) - ( -1 * 10^(9 - S), 1 * 10^(9 - S) ) +- Decimal64(S) - ( -1 * 10^(18 - S), 1 * 10^(18 - S) ) +- Decimal128(S) - ( -1 * 10^(38 - S), 1 * 10^(38 - S) ) + +例如, Decimal32(4) 可以表示 -99999.9999 到 99999.9999 范围内步数为 0.0001 的值。 + +## 内部表示方式 + +数据采用与自身位宽相同的有符号整数存储。这个数在内存中实际范围会高于上述范围,从 String 转换到十进制数的时候会做对应的检查。 + +Decimal32/Decimal64 通常处理速度要高于Decimal128,这是因为当前通用CPU不支持128位的操作导致的。 + +## 运算以及结果的类型 + +对Decimal的二进制运算导致更宽的结果类型(具有任何参数顺序)。 + +- Decimal64(S1) Decimal32(S2) -> Decimal64(S) +- Decimal128(S1) Decimal32(S2) -> Decimal128(S) +- Decimal128(S1) Decimal64(S2) -> Decimal128(S) + +精度变化的规则: + +- 加,减: S = max(S1, S2). +- 相乘: S = S1 + S2. +- 相除:S = S1. + +对于 Decimal 和整数之间的类似操作,结果为一样参数值的 Decimal。 + +没有定义 Decimal 和 Float32/Float64 的操作。如果你真的需要他们,你可以某一个参数明确地转换为 toDecimal32,toDecimal64, toDecimal128 或 toFloat32, toFloat64。注意这个操作会丢失精度,并且类型转换是一个代价昂贵的操作。 + +有一些函数对 Decimal 进行操作后是返回 Float64 的(例如,var 或 stddev)。计算的结果可能仍在 Decimal 中执行,这可能导致 Float64 和具有相同值的 Decimal 输入计算后的结果不同。 + + +## 溢出检查 + +在对 Decimal 计算的过程中,数值会有可能溢出。分数中的过多数字被丢弃(不是舍入的)。 整数中的过多数字将导致异常。 + +``` +SELECT toDecimal32(2, 4) AS x, x / 3 +``` +``` +┌──────x─┬─divide(toDecimal32(2, 4), 3)─┐ +│ 2.0000 │ 0.6666 │ +└────────┴──────────────────────────────┘ +``` + +``` +SELECT toDecimal32(4.2, 8) AS x, x * x +``` +``` +DB::Exception: Scale is out of bounds. +``` + +``` +SELECT toDecimal32(4.2, 8) AS x, 6 * x +``` +``` +DB::Exception: Decimal math overflow. +``` + +溢出检查会导致操作减慢。 如果已知溢出不可能,则使用`decimal_check_overflow`设置禁用检查是有意义的。 禁用检查并发生溢出时,结果将不正确: + +``` +SET decimal_check_overflow = 0; +SELECT toDecimal32(4.2, 8) AS x, 6 * x +``` +``` +┌──────────x─┬─multiply(6, toDecimal32(4.2, 8))─┐ +│ 4.20000000 │ -17.74967296 │ +└────────────┴──────────────────────────────────┘ +``` + +溢出检查不仅会在数学运算中进行,还会在值比较中进行: + +``` +SELECT toDecimal32(1, 8) < 100 +``` +``` +DB::Exception: Can't compare. +``` + +[来源文章](https://clickhouse.yandex/docs/en/data_types/decimal/) diff --git a/docs/zh/data_types/enum.md b/docs/zh/data_types/enum.md deleted file mode 120000 index 23ebe64773e..00000000000 --- a/docs/zh/data_types/enum.md +++ /dev/null @@ -1 +0,0 @@ -../../en/data_types/enum.md \ No newline at end of file diff --git a/docs/zh/data_types/enum.md b/docs/zh/data_types/enum.md new file mode 100644 index 00000000000..48ab4e0d130 --- /dev/null +++ b/docs/zh/data_types/enum.md @@ -0,0 +1,34 @@ +# Enum + +`Enum8` 或者 `Enum16`。 一组有限的字符串值,比 `String` 类型的存储更加有效。 + +示例: + +```text +Enum8('hello' = 1, 'world' = 2) +``` + +- 一个类型可以表示两个值: 'hello' and 'world'。 + +`Enum8` 类型的每个值范围是 `-128 ... 127`,`Enum16` 类型的每个值范围是 `-32768 ... 32767`。所有的字符串或者数字都必须是不一样的。允许存在空字符串。如果某个 Enum 类型被指定了(在表定义的时候),数字可以是任意顺序。然而,顺序并不重要。 +(译者注:如 `Enum8('he o' = 3, 'wld' = 1)` 也是合法的) + +在内存中,Enum 类型当做 `Int8` or `Int16` 对应的数值来存储。 +当以文本方式读取的时候,ClickHouse 将值解析成字符串然后去 Enum 值的集合中搜索对应字符串。如果没有找到,会抛出异常。当读取文本格式的时候,会根据读取到的字符串去找对应的数值。如果没有找到,会抛出异常。 + +当以文本方式写入的时候,ClickHouse 将值解析成字符串写入。如果 column 数据包含垃圾(不是从有用集合含有的数值),会抛弃异常。Enum 类型以二进制读取和写入的方式与 Int8 和 Int16 类型一样的。 +隐式默认值是对应类型的最小值。 + +在 `ORDER BY`, `GROUP BY`, `IN`, `DISTINCT` 中,Enums 和对应数值是一样的工作方式。比如, ORDER BY 会将它们按数值排序。对 Enums 类型使用相同和比较操作符都与操作它们隐含的数值是一样的。 + +Enum 值不能和数值比较大小。Enums 可以和一个常量字符串比较大小。如果字符串不是一个可用的 Enum 值,会抛出异常。可以使用 IN 运算符来判断一个 Enum 是否存在于某个 Enum 集合中,其中集合中的 Enum 需要用字符串表示。 + +大部分数字运算和字符串运算都没有给 Enum 类型定义,比如,Enum 类型不能和一个数相加,或进行字符串连接的操作,但是可以通过 toString 方法返回它对应的字符串。 + +Enum 值使用 `toT` 函数可以转换成数值类型,其中 T 是一个数值类型。若 `T` 恰好对应 Enum 的底层数值类型,这个转换是零消耗的。 + +Enum 类型可以被 `ALTER` 无成本地修改对应集合的值。可以通过 `ALTER` 操作来增加或删除 Enum 的成员(只要表没有用到该值,删除都是安全的)。作为安全保障,改变之前使用过的 Enum 成员将抛出异常。 + +通过 `ALTER` 操作,可以将 `Enum8` 转成 `Enum16`,反之亦然,就像 `Int8` 转 `Int16`一样。 + +[来源文章](https://clickhouse.yandex/docs/en/data_types/enum/) diff --git a/docs/zh/data_types/fixedstring.md b/docs/zh/data_types/fixedstring.md deleted file mode 120000 index 53092fcb884..00000000000 --- a/docs/zh/data_types/fixedstring.md +++ /dev/null @@ -1 +0,0 @@ -../../en/data_types/fixedstring.md \ No newline at end of file diff --git a/docs/zh/data_types/fixedstring.md b/docs/zh/data_types/fixedstring.md new file mode 100644 index 00000000000..1d8a4982e48 --- /dev/null +++ b/docs/zh/data_types/fixedstring.md @@ -0,0 +1,9 @@ +# FixedString(N) + +固定长度 N 的字符串。N 必须是严格的正自然数。 +当服务端读取长度小于 N 的字符串时候(譬如解析插入的数据),字符串通过在末尾添加空字节来达到 N 字节长度。 +当服务端读取长度大于 N 的字符串时候,会返回一个错误。 +当服务端写入一个字符串的时候(譬如写入数据到 SELECT 查询结果中),末尾的空字节会被修剪掉。 +注意这种方式与 MYSQL 的 CHAR 类型是不一样的(MYSQL 的字符串会以空格填充,然后输出的时候空格会被修剪)。 + +很少函数会使用 `FixedString(N)` 来代替 `String`,因此它并不是很方便。 diff --git a/docs/zh/data_types/float.md b/docs/zh/data_types/float.md deleted file mode 120000 index d2ae6bd11de..00000000000 --- a/docs/zh/data_types/float.md +++ /dev/null @@ -1 +0,0 @@ -../../en/data_types/float.md \ No newline at end of file diff --git a/docs/zh/data_types/float.md b/docs/zh/data_types/float.md new file mode 100644 index 00000000000..67a237ba5a5 --- /dev/null +++ b/docs/zh/data_types/float.md @@ -0,0 +1,72 @@ +# Float32, Float64 + +[浮点数](https://en.wikipedia.org/wiki/IEEE_754)。 + +类型与以下 C 类型是相同的: + +- `Float32` - `float` +- `Float64` - ` double` + +我们建议,如果可能的话尽量用整形来存储数据。比如,将一定精度的浮点数转换成整形,譬如货币金额或者毫秒单位的加载时间。 + +## 使用浮点数 + +- 对浮点数进行计算可能引起四舍五入的误差。 + + ```sql + SELECT 1 - 0.9 + ``` + + ``` + ┌───────minus(1, 0.9)─┐ + │ 0.09999999999999998 │ + └─────────────────────┘ + ``` + +- 计算的结果取决于计算方式(处理器类型和计算机系统架构) + +- 浮点数计算可能出现这样的结果,比如 "infinity" (`Inf`) 和 "not-a-number" (`NaN`)。对浮点数计算的时候应该考虑到这点。 + +- 当一行行阅读浮点数的时候,浮点数的结果可能不是机器最近显示的数值。 + +## NaN 和 Inf + +相比于 SQL,ClickHouse 支持以下几种浮点数分类: + +- `Inf` – 正无穷。 + + ```sql + SELECT 0.5 / 0 + ``` + + ``` + ┌─divide(0.5, 0)─┐ + │ inf │ + └────────────────┘ + ``` +- `-Inf` – 负无穷。 + + ```sql + SELECT -0.5 / 0 + ``` + + ``` + ┌─divide(-0.5, 0)─┐ + │ -inf │ + └─────────────────┘ + ``` +- `NaN` – 非数字。 + + ``` + SELECT 0 / 0 + ``` + + ``` + ┌─divide(0, 0)─┐ + │ nan │ + └──────────────┘ + ``` + +可以在[ORDER BY 子句](../query_language/queries.md#query_language-queries-order_by) 查看更多关于 ` NaN` 排序的规则。 + +[来源文章](https://clickhouse.yandex/docs/en/data_types/float/) diff --git a/docs/zh/data_types/index.md b/docs/zh/data_types/index.md deleted file mode 120000 index c9f29d637f3..00000000000 --- a/docs/zh/data_types/index.md +++ /dev/null @@ -1 +0,0 @@ -../../en/data_types/index.md \ No newline at end of file diff --git a/docs/zh/data_types/index.md b/docs/zh/data_types/index.md new file mode 100644 index 00000000000..785216a22a9 --- /dev/null +++ b/docs/zh/data_types/index.md @@ -0,0 +1,9 @@ + + +# 数据类型 + +ClickHouse 可以在数据表中存储多种数据类型。 + +本节将描述 ClickHouse 支持的数据类型以及在使用 与/或 运算实现他们时候的特殊考虑(如果有)。 + +[来源文章](https://clickhouse.yandex/docs/en/data_types/) diff --git a/docs/zh/data_types/int_uint.md b/docs/zh/data_types/int_uint.md deleted file mode 120000 index 3a913c9328e..00000000000 --- a/docs/zh/data_types/int_uint.md +++ /dev/null @@ -1 +0,0 @@ -../../en/data_types/int_uint.md \ No newline at end of file diff --git a/docs/zh/data_types/int_uint.md b/docs/zh/data_types/int_uint.md new file mode 100644 index 00000000000..c142cf50106 --- /dev/null +++ b/docs/zh/data_types/int_uint.md @@ -0,0 +1,22 @@ + + +# UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64 + +固定长度的整型,包括有符号整型或无符号整型。 + +## 整型范围 + +- Int8 - [-128 : 127] +- Int16 - [-32768 : 32767] +- Int32 - [-2147483648 : 2147483647] +- Int64 - [-9223372036854775808 : 9223372036854775807] + +## 无符号整型范围 + +- UInt8 - [0 : 255] +- UInt16 - [0 : 65535] +- UInt32 - [0 : 4294967295] +- UInt64 - [0 : 18446744073709551615] + + +[来源文章](https://clickhouse.yandex/docs/en/data_types/int_uint/) diff --git a/docs/zh/data_types/nested_data_structures/aggregatefunction.md b/docs/zh/data_types/nested_data_structures/aggregatefunction.md deleted file mode 120000 index 36544324d2b..00000000000 --- a/docs/zh/data_types/nested_data_structures/aggregatefunction.md +++ /dev/null @@ -1 +0,0 @@ -../../../en/data_types/nested_data_structures/aggregatefunction.md \ No newline at end of file diff --git a/docs/zh/data_types/nested_data_structures/aggregatefunction.md b/docs/zh/data_types/nested_data_structures/aggregatefunction.md new file mode 100644 index 00000000000..bb9d57274ec --- /dev/null +++ b/docs/zh/data_types/nested_data_structures/aggregatefunction.md @@ -0,0 +1,5 @@ +# AggregateFunction(name, types_of_arguments...) + +表示聚合函数中的中间状态。可以在聚合函数中通过 '-State' 后缀来访问它。更多信息,参考 "AggregatingMergeTree"。 + +[来源文章](https://clickhouse.yandex/docs/en/data_types/nested_data_structures/aggregatefunction/) \ No newline at end of file diff --git a/docs/zh/data_types/nested_data_structures/index.md b/docs/zh/data_types/nested_data_structures/index.md deleted file mode 120000 index a5659a9c5cd..00000000000 --- a/docs/zh/data_types/nested_data_structures/index.md +++ /dev/null @@ -1 +0,0 @@ -../../../en/data_types/nested_data_structures/index.md \ No newline at end of file diff --git a/docs/zh/data_types/nested_data_structures/index.md b/docs/zh/data_types/nested_data_structures/index.md new file mode 100644 index 00000000000..fcb01993389 --- /dev/null +++ b/docs/zh/data_types/nested_data_structures/index.md @@ -0,0 +1,4 @@ +# 嵌套数据类型 + + +[来源文章](https://clickhouse.yandex/docs/en/data_types/nested_data_structures/) diff --git a/docs/zh/data_types/nested_data_structures/nested.md b/docs/zh/data_types/nested_data_structures/nested.md deleted file mode 120000 index 653a1ce31c3..00000000000 --- a/docs/zh/data_types/nested_data_structures/nested.md +++ /dev/null @@ -1 +0,0 @@ -../../../en/data_types/nested_data_structures/nested.md \ No newline at end of file diff --git a/docs/zh/data_types/nested_data_structures/nested.md b/docs/zh/data_types/nested_data_structures/nested.md new file mode 100644 index 00000000000..2ab6d06cbdc --- /dev/null +++ b/docs/zh/data_types/nested_data_structures/nested.md @@ -0,0 +1,99 @@ +# Nested(Name1 Type1, Name2 Type2, ...) + +类似嵌套表的嵌套数据结构。嵌套数据结构的参数(列名和列类型)与 CREATE 查询类似。每个表可以对应任意多行嵌套数据结构。 + +示例: + +```sql +CREATE TABLE test.visits +( + CounterID UInt32, + StartDate Date, + Sign Int8, + IsNew UInt8, + VisitID UInt64, + UserID UInt64, + ... + Goals Nested + ( + ID UInt32, + Serial UInt32, + EventTime DateTime, + Price Int64, + OrderID String, + CurrencyID UInt32 + ), + ... +) ENGINE = CollapsingMergeTree(StartDate, intHash32(UserID), (CounterID, StartDate, intHash32(UserID), VisitID), 8192, Sign) +``` + +上述示例声明了 `Goals` 这种嵌套数据结构,它包含访客转化相关的数据(访客达到的目标)。在 'visits' 表中每一行都可以对应零个或者任意个转化数据。 + +只支持一级嵌套。嵌套结构的列中,若列的类型是数组类型,那么该列其实和多维数组是相同的,所以目前嵌套层级的支持很局限(MergeTree 引擎中不支持存储这样的列) + +大多数情况下,处理嵌套数据结构时,会指定一个单独的列。为了这样实现,列的名称会与点号连接起来。这些列构成了一组匹配类型。在同一条嵌套数据中,所有的列都具有相同的长度。 + +示例: + +```sql +SELECT + Goals.ID, + Goals.EventTime +FROM test.visits +WHERE CounterID = 101500 AND length(Goals.ID) < 5 +LIMIT 10 +``` + +```text +┌─Goals.ID───────────────────────┬─Goals.EventTime───────────────────────────────────────────────────────────────────────────┐ +│ [1073752,591325,591325] │ ['2014-03-17 16:38:10','2014-03-17 16:38:48','2014-03-17 16:42:27'] │ +│ [1073752] │ ['2014-03-17 00:28:25'] │ +│ [1073752] │ ['2014-03-17 10:46:20'] │ +│ [1073752,591325,591325,591325] │ ['2014-03-17 13:59:20','2014-03-17 22:17:55','2014-03-17 22:18:07','2014-03-17 22:18:51'] │ +│ [] │ [] │ +│ [1073752,591325,591325] │ ['2014-03-17 11:37:06','2014-03-17 14:07:47','2014-03-17 14:36:21'] │ +│ [] │ [] │ +│ [] │ [] │ +│ [591325,1073752] │ ['2014-03-17 00:46:05','2014-03-17 00:46:05'] │ +│ [1073752,591325,591325,591325] │ ['2014-03-17 13:28:33','2014-03-17 13:30:26','2014-03-17 18:51:21','2014-03-17 18:51:45'] │ +└────────────────────────────────┴───────────────────────────────────────────────────────────────────────────────────────────┘ +``` + +所以可以简单地把嵌套数据结构当做是所有列都是相同长度的多列数组。 + +SELECT 查询只有在使用 ARRAY JOIN 的时候才可以指定整个嵌套数据结构的名称。更多信息,参考 "ARRAY JOIN 子句"。示例: + +```sql +SELECT + Goal.ID, + Goal.EventTime +FROM test.visits +ARRAY JOIN Goals AS Goal +WHERE CounterID = 101500 AND length(Goals.ID) < 5 +LIMIT 10 +``` + +```text +┌─Goal.ID─┬──────Goal.EventTime─┐ +│ 1073752 │ 2014-03-17 16:38:10 │ +│ 591325 │ 2014-03-17 16:38:48 │ +│ 591325 │ 2014-03-17 16:42:27 │ +│ 1073752 │ 2014-03-17 00:28:25 │ +│ 1073752 │ 2014-03-17 10:46:20 │ +│ 1073752 │ 2014-03-17 13:59:20 │ +│ 591325 │ 2014-03-17 22:17:55 │ +│ 591325 │ 2014-03-17 22:18:07 │ +│ 591325 │ 2014-03-17 22:18:51 │ +│ 1073752 │ 2014-03-17 11:37:06 │ +└─────────┴─────────────────────┘ +``` + +不能对整个嵌套数据结构进行 SELECT 。只能显式地列出它的一部分列。 + +对于 INSERT 查询,可以单独地传入所有嵌套数据结构中的列数组(假如它们是单独的列数组)。在插入过程中,系统会检查它们是否有相同的长度。 + +对于 DESCRIBE 查询,嵌套数据结构中的列会以相同的方式分别列出来。 + +ALTER 查询对嵌套数据结构的操作非常局限。 + +[来源文章](https://clickhouse.yandex/docs/en/data_types/nested_data_structures/nested/) diff --git a/docs/zh/data_types/nullable.md b/docs/zh/data_types/nullable.md deleted file mode 120000 index 0233f91d954..00000000000 --- a/docs/zh/data_types/nullable.md +++ /dev/null @@ -1 +0,0 @@ -../../en/data_types/nullable.md \ No newline at end of file diff --git a/docs/zh/data_types/nullable.md b/docs/zh/data_types/nullable.md new file mode 100644 index 00000000000..00c24c26c3a --- /dev/null +++ b/docs/zh/data_types/nullable.md @@ -0,0 +1,59 @@ + + +# Nullable(TypeName) + +允许加上一个符号 ([NULL](../query_language/syntax.md#null-literal)) 表示“缺失值”和 `TypeName` 允许的正常值。 例如,`Nullable(Int8)` 类型列可以存储 `Int8` 类型值,而没有值的行将存储 `NULL` 。 + +对于`TypeName`,您不能使用复合数据类型 [Array](array.md#data_type is array) 和 [Tuple](tuple.md#data_type-tuple)。 复合数据类型可以包含 `Nullable` 类型值,例如 `Array (Nullable(Int8))`。 + + +`Nullable` 类型字段不能包含在表索引中。 + +除非在 ClickHouse 服务器配置中另有说明,否则 `NULL` 是任何 `Nullable` 类型的默认值。 + +## 存储特性 + +要在表的列中存储 `Nullable` 类型值,ClickHouse 除了使用带有值的普通文件外,还使用带有 `NULL` 掩码的单独文件。 掩码文件中的条目允许 ClickHouse 区分每个表行的 `NULL` 和相应数据类型的默认值。 由于附加了新文件,`Nullable` 列与类似的普通文件相比消耗额外的存储空间。 + +!!! info "Note" + 使用 `Nullable` 几乎总是会对性能产生负面影响,在设计数据库时请记住这一点。 + + +## 使用案例 + +``` +:) CREATE TABLE t_null(x Int8, y Nullable(Int8)) ENGINE TinyLog + +CREATE TABLE t_null +( + x Int8, + y Nullable(Int8) +) +ENGINE = TinyLog + +Ok. + +0 rows in set. Elapsed: 0.012 sec. + +:) INSERT INTO t_null VALUES (1, NULL) + +INSERT INTO t_null VALUES + +Ok. + +1 rows in set. Elapsed: 0.007 sec. + +:) SELECT x + y FROM t_null + +SELECT x + y +FROM t_null + +┌─plus(x, y)─┐ +│ ᴺᵁᴸᴸ │ +│ 5 │ +└────────────┘ + +2 rows in set. Elapsed: 0.144 sec. +``` + +[来源文章](https://clickhouse.yandex/docs/en/data_types/nullable/) diff --git a/docs/zh/data_types/special_data_types/expression.md b/docs/zh/data_types/special_data_types/expression.md deleted file mode 120000 index 4cec632b416..00000000000 --- a/docs/zh/data_types/special_data_types/expression.md +++ /dev/null @@ -1 +0,0 @@ -../../../en/data_types/special_data_types/expression.md \ No newline at end of file diff --git a/docs/zh/data_types/special_data_types/expression.md b/docs/zh/data_types/special_data_types/expression.md new file mode 100644 index 00000000000..14e8aaf5362 --- /dev/null +++ b/docs/zh/data_types/special_data_types/expression.md @@ -0,0 +1,5 @@ +# Expression + +用在高阶函数中的 lambda 表达式中。 + +[来源文章](https://clickhouse.yandex/docs/en/data_types/special_data_types/expression/) diff --git a/docs/zh/data_types/special_data_types/index.md b/docs/zh/data_types/special_data_types/index.md deleted file mode 120000 index f3ca4a47f98..00000000000 --- a/docs/zh/data_types/special_data_types/index.md +++ /dev/null @@ -1 +0,0 @@ -../../../en/data_types/special_data_types/index.md \ No newline at end of file diff --git a/docs/zh/data_types/special_data_types/index.md b/docs/zh/data_types/special_data_types/index.md new file mode 100644 index 00000000000..03f66e36189 --- /dev/null +++ b/docs/zh/data_types/special_data_types/index.md @@ -0,0 +1,5 @@ +# Special Data Types + +特殊数据类型的值既不能存在表中也不能在结果中输出,但是可以被用于表示查询过程中的中间结果。 + +[来源文章](https://clickhouse.yandex/docs/en/data_types/special_data_types/) diff --git a/docs/zh/data_types/special_data_types/nothing.md b/docs/zh/data_types/special_data_types/nothing.md deleted file mode 120000 index 197a752ce9c..00000000000 --- a/docs/zh/data_types/special_data_types/nothing.md +++ /dev/null @@ -1 +0,0 @@ -../../../en/data_types/special_data_types/nothing.md \ No newline at end of file diff --git a/docs/zh/data_types/special_data_types/nothing.md b/docs/zh/data_types/special_data_types/nothing.md new file mode 100644 index 00000000000..dd7f51cca0f --- /dev/null +++ b/docs/zh/data_types/special_data_types/nothing.md @@ -0,0 +1,24 @@ + + +# Nothing + +此数据类型的唯一目的是表示不是期望值的情况。 所以你不能创建一个` Nothing` 类型的值。 + +例如, [NULL](../../query_language/syntax.md#null-literal) 有 `Nullable(Nothing)`。更多参见[Nullable](../../data_types/nullable.md#data_type-nullable). + +`Nothing` 类型也可用于表示空数组: + +```bash +:) SELECT toTypeName(array()) + +SELECT toTypeName([]) + +┌─toTypeName(array())─┐ +│ Array(Nothing) │ +└─────────────────────┘ + +1 rows in set. Elapsed: 0.062 sec. +``` + + +[来源文章](https://clickhouse.yandex/docs/en/data_types/special_data_types/nothing/) diff --git a/docs/zh/data_types/special_data_types/set.md b/docs/zh/data_types/special_data_types/set.md deleted file mode 120000 index 5beb14114d3..00000000000 --- a/docs/zh/data_types/special_data_types/set.md +++ /dev/null @@ -1 +0,0 @@ -../../../en/data_types/special_data_types/set.md \ No newline at end of file diff --git a/docs/zh/data_types/special_data_types/set.md b/docs/zh/data_types/special_data_types/set.md new file mode 100644 index 00000000000..0e62f64f540 --- /dev/null +++ b/docs/zh/data_types/special_data_types/set.md @@ -0,0 +1,5 @@ +# Set + +可以用在 IN 表达式的右半边。 + +[来源文章](https://clickhouse.yandex/docs/en/data_types/special_data_types/set/) diff --git a/docs/zh/data_types/string.md b/docs/zh/data_types/string.md deleted file mode 120000 index 7bdd739398f..00000000000 --- a/docs/zh/data_types/string.md +++ /dev/null @@ -1 +0,0 @@ -../../en/data_types/string.md \ No newline at end of file diff --git a/docs/zh/data_types/string.md b/docs/zh/data_types/string.md new file mode 100644 index 00000000000..6d45b8f4741 --- /dev/null +++ b/docs/zh/data_types/string.md @@ -0,0 +1,13 @@ +# String + +字符串可以任意长度的。它可以包含任意的字节组合,包括空字符。 +String 类型替代了其他 DBMSs 中的 VARCHAR, BLOB, CLOB 等类型。 + +## 编码 + +ClickHouse 没有编码的概念。字符串可以是任意的字节组合,按它们原本的方式进行存储和输出。 +若需存储文本,我们建议使用 UTF-8 编码。至少,如果你的终端使用UTF-8(推荐),这样读写就不需要进行任何的转换了。 +同样,对不同的编码文本 ClickHouse 会有不同处理字符串的函数。 +比如,`length` 函数可以计算字符串包含的字节数组的长度,然而 `lengthUTF8` 函数是假设字符串以 UTF-8 编码,计算的是字符串包含的 Unicode 字符的长度。 + +[来源文章](https://clickhouse.yandex/docs/en/data_types/string/) diff --git a/docs/zh/data_types/tuple.md b/docs/zh/data_types/tuple.md deleted file mode 120000 index d30a8463aeb..00000000000 --- a/docs/zh/data_types/tuple.md +++ /dev/null @@ -1 +0,0 @@ -../../en/data_types/tuple.md \ No newline at end of file diff --git a/docs/zh/data_types/tuple.md b/docs/zh/data_types/tuple.md new file mode 100644 index 00000000000..02320a4be73 --- /dev/null +++ b/docs/zh/data_types/tuple.md @@ -0,0 +1,53 @@ +# Tuple(T1, T2, ...) + +元组,元组中的每个元素都有独立的[类型](index.md#data_types)。 + +元组不能写入表中(除 Memory 表外)。它们会用于临时列分组。在某个查询中,IN 表达式和带特定参数的 lambda 函数可以来对临时列进行分组。更多信息,参见 [IN 操作符] (../query_language/select.md#in_operators) 和 [高阶函数](../query_language/functions/higher_order_functions.md#higher_order_functions)。 + +## 创建元组 + +可以用下面函数来创建元组: + +``` +tuple(T1, T2, ...) +``` + +创建元组的示例: + +``` +:) SELECT tuple(1,'a') AS x, toTypeName(x) + +SELECT + (1, 'a') AS x, + toTypeName(x) + +┌─x───────┬─toTypeName(tuple(1, 'a'))─┐ +│ (1,'a') │ Tuple(UInt8, String) │ +└─────────┴───────────────────────────┘ + +1 rows in set. Elapsed: 0.021 sec. +``` + +## 元组中的数据类型 + +当动态创建元组时,ClickHouse 会自动为元组的每一个参数赋予最小可表达的类型。如果该参数是 [NULL](../query_language/syntax.md#null-literal),那么这个元组对应元素就是 [Nullable](nullable.md#data_type-nullable)。 + +自动识别数据类型的示例: + +``` +SELECT tuple(1, NULL) AS x, toTypeName(x) + +SELECT + (1, NULL) AS x, + toTypeName(x) + +┌─x────────┬─toTypeName(tuple(1, NULL))──────┐ +│ (1,NULL) │ Tuple(UInt8, Nullable(Nothing)) │ +└──────────┴─────────────────────────────────┘ + +1 rows in set. Elapsed: 0.002 sec. +``` + + +[来源文章](https://clickhouse.yandex/docs/en/data_types/tuple/) + diff --git a/docs/zh/interfaces/formats.md b/docs/zh/interfaces/formats.md index ec905713b1c..fdfb2ccb0e7 100644 --- a/docs/zh/interfaces/formats.md +++ b/docs/zh/interfaces/formats.md @@ -173,7 +173,7 @@ clickhouse-client --format_csv_delimiter="|" --query="INSERT INTO test.csv FORMA 解析的时候,可以使用或不使用引号来解析所有值。支持双引号和单引号。行也可以不用引号排列。 在这种情况下,它们被解析为逗号或换行符(CR 或 LF)。在解析不带引号的行时,若违反 RFC 规则,会忽略前导和尾随的空格和制表符。 对于换行,全部支持 Unix(LF),Windows(CR LF)和 Mac OS Classic(CR LF)。 -`NULL` is formatted as `\N`. +`NULL` 将输出为 `\N`。 CSV 格式是和 TabSeparated 一样的方式输出总数和极值。 @@ -511,7 +511,7 @@ test: string with 'quotes' and with some special characters ``` -Compare with the Vertical format: +和 Vertical 格式相比: ``` :) SELECT 'string with \'quotes\' and \t with some special \n characters' AS test FORMAT Vertical;