update zh-docs-aggregate-functions (#11623)

This commit is contained in:
zzsmdfj 2020-06-12 19:03:01 +08:00 committed by GitHub
parent 37d7e9a60a
commit a2ed8d70a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 228 additions and 236 deletions

View File

@ -316,7 +316,7 @@ Result:
The function takes as arguments a set of conditions from 1 to 32 arguments of type `UInt8` that indicate whether a certain condition was met for the event.
Any condition can be specified as an argument (as in [WHERE](../../sql-reference/statements/select/where.md#select-where)).
The conditions, except the first, apply in pairs: the result of the second will be true if the first and second are true, of the third if the first and fird are true, etc.
The conditions, except the first, apply in pairs: the result of the second will be true if the first and second are true, of the third if the first and third are true, etc.
**Syntax**

View File

@ -1805,7 +1805,7 @@ For more information see [parameters](#agg_functions-stochasticlinearregression-
stochasticLogisticRegression(1.0, 1.0, 10, 'SGD')
```
1. Fitting
**1.** Fitting
<!-- -->
@ -1813,7 +1813,7 @@ stochasticLogisticRegression(1.0, 1.0, 10, 'SGD')
Predicted labels have to be in \[-1, 1\].
1. Predicting
**2.** Predicting
<!-- -->

View File

@ -28,7 +28,7 @@ CREATE TABLE t
) ENGINE = ...
```
[uniq](../../sql-reference/aggregate-functions/reference.md#agg_function-uniq), anyIf ([any](../../sql-reference/aggregate-functions/reference.md#agg_function-any)+[If](../../sql-reference/aggregate-functions/combinators.md#agg-functions-combinator-if)) and [quantiles](../../sql-reference/aggregate-functions/reference.md) are the aggregate functions supported in ClickHouse.
[uniq](../../sql-reference/aggregate-functions/reference.md#agg_function-uniq), anyIf ([any](../../sql-reference/aggregate-functions/reference.md#agg_function-any)+[If](../../sql-reference/aggregate-functions/combinators.md#agg-functions-combinator-if)) and [quantiles](../../sql-reference/aggregate-functions/reference.md#quantiles) are the aggregate functions supported in ClickHouse.
## Usage {#usage}

View File

@ -1,51 +1,49 @@
---
machine_translated: true
machine_translated_rev: 72537a2d527c63c07aa5d2361a8829f3895cf2bd
toc_priority: 37
toc_title: "\u7EC4\u5408\u5668"
toc_title: 聚合函数组合器
---
# 聚合函数组合器 {#aggregate_functions_combinators}
聚合函数的名称可以附加一个后缀。 这改变了聚合函数的工作方式。
## -如果 {#agg-functions-combinator-if}
## -If {#agg-functions-combinator-if}
The suffix -If can be appended to the name of any aggregate function. In this case, the aggregate function accepts an extra argument a condition (Uint8 type). The aggregate function processes only the rows that trigger the condition. If the condition was not triggered even once, it returns a default value (usually zeros or empty strings).
-If可以加到任何聚合函数之后。加了-If之后聚合函数需要接受一个额外的参数一个条件Uint8类型如果条件满足那聚合函数处理当前的行数据如果不满足那返回默认值通常是0或者空字符串
: `sumIf(column, cond)`, `countIf(cond)`, `avgIf(x, cond)`, `quantilesTimingIf(level1, level2)(x, cond)`, `argMinIf(arg, val, cond)` 等等。
`sumIf(column, cond)`, `countIf(cond)`, `avgIf(x, cond)`, `quantilesTimingIf(level1, level2)(x, cond)`, `argMinIf(arg, val, cond)` 等等。
使用条件聚合函数,您可以一次计算多个条件的聚合,而无需使用子查询和 `JOIN`例如在Yandex的。Metrica条件聚合函数用于实现段比较功能。
使用条件聚合函数,您可以一次计算多个条件的聚合,而无需使用子查询和 `JOIN`例如在Yandex.Metrica条件聚合函数用于实现段比较功能。
## -阵列 {#agg-functions-combinator-array}
## -Array {#agg-functions-combinator-array}
-Array后缀可以附加到任何聚合函数。 在这种情况下,聚合函数采用的参数 Array(T) 类型(数组)而不是 T 类型参数。 如果聚合函数接受多个参数,则它必须是长度相等的数组。 在处理数组时,聚合函数的工作方式与所有数组元素的原始聚合函数类似。
示例1: `sumArray(arr)` -总计所有的所有元素 arr 阵列。 在这个例子中,它可以更简单地编写: `sum(arraySum(arr))`.
示例1 `sumArray(arr)` -总计所有的所有元素 arr 阵列。在这个例子中,它可以更简单地编写: `sum(arraySum(arr))`.
示例2: `uniqArray(arr)` Counts the number of unique elements in all arr 阵列。 这可以做一个更简单的方法: `uniq(arrayJoin(arr))`,但它并不总是可以添加 arrayJoin 到查询。
示例2 `uniqArray(arr)` 计算arr中唯一元素的个数。这可以是一个更简单的方法 `uniq(arrayJoin(arr))`,但它并不总是可以添加 arrayJoin 到查询。
-如果和-阵列可以组合。 然而, Array 必须先来,然后 If. 例: `uniqArrayIf(arr, cond)`, `quantilesTimingArrayIf(level1, level2)(arr, cond)`. 由于这个顺序,该 cond 参数不会是数组。
如果和-If组合Array 必须先来,然后 If. 例: `uniqArrayIf(arr, cond)` `quantilesTimingArrayIf(level1, level2)(arr, cond)`由于这个顺序,该 cond 参数不会是数组。
## - {#agg-functions-combinator-state}
## -State {#agg-functions-combinator-state}
如果应用此combinator则聚合函数不会返回结果值例如唯一值的数量 [uniq](reference.md#agg_function-uniq) 函数),但聚合的中间状态(用于 `uniq`,这是用于计算唯一值的数量的散列表)。 这是一个 `AggregateFunction(...)` 可用于进一步处理或存储在表中以完成聚合。
如果应用此combinator则聚合函数不会返回结果值例如唯一值的数量 [uniq](reference.md#agg_function-uniq) 函数),但是返回聚合的中间状态(对于 `uniq`,返回的是计算唯一值的数量的哈希表)。 这是一个 `AggregateFunction(...)` 可用于进一步处理或存储在表中以完成稍后的聚合。
要使用这些状态,请使用:
- [AggregatingMergeTree](../../engines/table-engines/mergetree-family/aggregatingmergetree.md) 表引擎。
- [最后聚会](../../sql-reference/functions/other-functions.md#function-finalizeaggregation) 功能。
- [跑累积](../../sql-reference/functions/other-functions.md#function-runningaccumulate) 功能。
- [-合并](#aggregate_functions_combinators-merge) combinator
- [finalizeAggregation](../../sql-reference/functions/other-functions.md#function-finalizeaggregation) 功能。
- [runningAccumulate](../../sql-reference/functions/other-functions.md#function-runningaccumulate) 功能。
- [-Merge](#aggregate_functions_combinators-merge) combinator
- [-MergeState](#aggregate_functions_combinators-mergestate) combinator
## -合并 {#aggregate_functions_combinators-merge}
## -Merge {#aggregate_functions_combinators-merge}
如果应用此组合器,则聚合函数将中间聚合状态作为参数,组合状态以完成聚合,并返回结果值。
## -MergeState {#aggregate_functions_combinators-mergestate}
以与-Merge combinator相同的方式合并中间聚合状态。 但是,它不会返回结果值,而是返回中间聚合状态,类似于-State combinator
以与-Merge 相同的方式合并中间聚合状态。 但是,它不会返回结果值,而是返回中间聚合状态,类似于-State。
## -ForEach {#agg-functions-combinator-foreach}
@ -55,7 +53,7 @@ The suffix -If can be appended to the name of any aggregate function. In this ca
更改聚合函数的行为。
如果聚合函数没有输入值,则使用此combinator它返回其返回数据类型的默认值。 适用于可以采用空输入数据的聚合函数。
如果聚合函数没有输入值,则使用此组合器它返回其返回数据类型的默认值。 适用于可以采用空输入数据的聚合函数。
`-OrDefault` 可与其他组合器一起使用。
@ -67,7 +65,7 @@ The suffix -If can be appended to the name of any aggregate function. In this ca
**参数**
- `x`Aggregate function parameters.
- `x`聚合函数参数。
**返回值**
@ -174,7 +172,7 @@ FROM
└────────────────────────────────┘
```
## -重新采样 {#agg-functions-combinator-resample}
## -Resample {#agg-functions-combinator-resample}
允许您将数据划分为组,然后单独聚合这些组中的数据。 通过将一列中的值拆分为间隔来创建组。
@ -184,19 +182,19 @@ FROM
**参数**
- `start`Starting value of the whole required interval for `resampling_key` 值。
- `stop`Ending value of the whole required interval for `resampling_key` 值。 整个时间间隔不包括 `stop` 价值 `[start, stop)`.
- `step`Step for separating the whole interval into subintervals. The `aggFunction` 在每个子区间上独立执行。
- `resampling_key`Column whose values are used for separating data into intervals.
- `start``resampling_key` 开始值。
- `stop``resampling_key` 结束边界。 区间内部不包含 `stop` 值,即 `[start, stop)`.
- `step`分组的步长。 The `aggFunction` 在每个子区间上独立执行。
- `resampling_key`取样列,被用来分组.
- `aggFunction_params``aggFunction` 参数。
**返回值**
- 阵列 `aggFunction` 每个子区间的结果。
- `aggFunction` 每个子区间的结果,结果为数组
**示例**
考虑一下 `people` 具有以下数据的表:
考虑一下 `people` 表具有以下数据的表结构:
``` text
┌─name───┬─age─┬─wage─┐
@ -209,9 +207,9 @@ FROM
└────────┴─────┴──────┘
```
让我们得到的人的名字,他们的年龄在于的时间间隔 `[30,60)``[60,75)`. 由于我们使用整数表示的年龄,我们得到的年龄 `[30, 59]``[60,74]` 间隔。
让我们得到的人的名字,他们的年龄在于的时间间隔 `[30,60)``[60,75)` 由于我们使用整数表示的年龄,我们得到的年龄 `[30, 59]``[60,74]` 间隔。
要在数组中聚合名称,我们使用 [groupArray](reference.md#agg_function-grouparray) 聚合函数。 这需要一个参数。 在我们的例子中,它是 `name` 列。 `groupArrayResample` 函数应该使用 `age` 按年龄聚合名称的列。 要定义所需的时间间隔,我们通过 `30, 75, 30` 参数到 `groupArrayResample` 功能
要在数组中聚合名称,我们使用 [groupArray](reference.md#agg_function-grouparray) 聚合函数。 这需要一个参数。 在我们的例子中,它是 `name` 列。 `groupArrayResample` 函数应该使用 `age` 按年龄聚合名称 要定义所需的时间间隔,我们传入 `30, 75, 30` 参数给 `groupArrayResample` 函数
``` sql
SELECT groupArrayResample(30, 75, 30)(name, age) FROM people
@ -225,7 +223,7 @@ SELECT groupArrayResample(30, 75, 30)(name, age) FROM people
考虑结果。
`Jonh` 是因为他太年轻了 其他人按照指定的年龄间隔进行分配。
`Jonh` 没有被选中,因为他太年轻了。 其他人按照指定的年龄间隔进行分配。
现在让我们计算指定年龄间隔内的总人数和平均工资。

View File

@ -1,9 +1,6 @@
---
machine_translated: true
machine_translated_rev: 72537a2d527c63c07aa5d2361a8829f3895cf2bd
toc_folder_title: "\u805A\u5408\u51FD\u6570"
toc_priority: 33
toc_title: "\u5BFC\u8A00"
toc_title: 简介
---
# 聚合函数 {#aggregate-functions}

View File

@ -1,15 +1,13 @@
---
machine_translated: true
machine_translated_rev: 72537a2d527c63c07aa5d2361a8829f3895cf2bd
toc_priority: 38
toc_title: "\u53C2\u6570"
toc_title: 参数聚合函数
---
# 参数聚合函数 {#aggregate_functions_parametric}
Some aggregate functions can accept not only argument columns (used for compression), but a set of parameters constants for initialization. The syntax is two pairs of brackets instead of one. The first is for parameters, and the second is for arguments.
一些聚合函数不仅可以接受参数列(用于压缩),也可以接收常量的初始化参数。这种语法是接受两个括号的参数,第一个数初始化参数,第二个是入参。
## 直方图 {#histogram}
## histogram {#histogram}
计算自适应直方图。 它不能保证精确的结果。
@ -21,20 +19,21 @@ histogram(number_of_bins)(values)
**参数**
`number_of_bins` — Upper limit for the number of bins in the histogram. The function automatically calculates the number of bins. It tries to reach the specified number of bins, but if it fails, it uses fewer bins.
`values` — [表达式](../syntax.md#syntax-expressions) 导致输入值。
`number_of_bins` — 直方图bin个数这个函数会自动计算bin的数量而且会尽量使用指定值如果无法做到那就使用更小的bin个数。
`values` — [表达式](../syntax.md#syntax-expressions) 输入值。
**返回值**
- [阵列](../../sql-reference/data-types/array.md) 的 [元组](../../sql-reference/data-types/tuple.md) 下面的格式:
- [Array](../../sql-reference/data-types/array.md) 的 [Tuples](../../sql-reference/data-types/tuple.md) 如下:
```
[(lower_1, upper_1, height_1), ... (lower_N, upper_N, height_N)]
```
- `lower`Lower bound of the bin.
- `upper`Upper bound of the bin.
- `height`Calculated height of the bin.
- `lower`bin的下边界。
- `upper`bin的上边界。
- `height`bin的计算权重。
**示例**
@ -53,7 +52,7 @@ FROM (
└─────────────────────────────────────────────────────────────────────────┘
```
您可以使用 [酒吧](../../sql-reference/functions/other-functions.md#function-bar) 功能,例如:
您可以使用 [bar](../../sql-reference/functions/other-functions.md#function-bar) 功能,例如:
``` sql
WITH histogram(5)(rand() % 100) AS hist
@ -93,11 +92,11 @@ sequenceMatch(pattern)(timestamp, cond1, cond2, ...)
**参数**
- `pattern`Pattern string. See [模式语法](#sequence-function-pattern-syntax).
- `pattern`模式字符串。 参考 [模式语法](#sequence-function-pattern-syntax).
- `timestamp`Column considered to contain time data. Typical data types are `Date``DateTime`. 您还可以使用任何支持的 [UInt](../../sql-reference/data-types/int-uint.md) 数据类型。
- `timestamp`包含时间的列。典型的时间类型是: `Date``DateTime`您还可以使用任何支持的 [UInt](../../sql-reference/data-types/int-uint.md) 数据类型。
- `cond1`, `cond2`Conditions that describe the chain of events. Data type: `UInt8`. 最多可以传递32个条件参数。 该函数只考虑这些条件中描述的事件。 如果序列包含未在条件中描述的数据,则函数将跳过这些数据。
- `cond1`, `cond2`事件链的约束条件。 数据类型是: `UInt8` 最多可以传递32个条件参数。 该函数只考虑这些条件中描述的事件。 如果序列包含未在条件中描述的数据,则函数将跳过这些数据。
**返回值**
@ -109,11 +108,11 @@ sequenceMatch(pattern)(timestamp, cond1, cond2, ...)
<a name="sequence-function-pattern-syntax"></a>
**模式语法**
- `(?N)`Matches the condition argument at position `N`. 条件在编号 `[1, 32]` 范围。 例如, `(?1)` 匹配传递给 `cond1` 参数。
- `(?N)`在位置`N`匹配条件参数。 条件在编号 `[1, 32]` 范围。 例如, `(?1)` 匹配传递给 `cond1` 参数。
- `.*`Matches any number of events. You don't need conditional arguments to match this element of the pattern.
- `.*`匹配任何事件的数字。 不需要条件参数来匹配这个模式。
- `(?t operator value)`Sets the time in seconds that should separate two events. For example, pattern `(?1)(?t>1800)(?2)` 匹配彼此发生超过1800秒的事件。 这些事件之间可以存在任意数量的任何事件。 您可以使用 `>=`, `>`, `<`, `<=`营商
- `(?t operator value)`分开两个事件的时间。 例如: `(?1)(?t>1800)(?2)` 匹配彼此发生超过1800秒的事件。 这些事件之间可以存在任意数量的任何事件。 您可以使用 `>=`, `>`, `<`, `<=`算符
**例**
@ -169,7 +168,7 @@ SELECT sequenceMatch('(?1)(?2)')(time, number = 1, number = 2, number = 4) FROM
## sequenceCount(pattern)(time, cond1, cond2, …) {#function-sequencecount}
数与模式匹配的事件链的数量。 该函数搜索不重叠的事件链。 当前链匹配后,它开始搜索下一个链。
算与模式匹配的事件链的数量。该函数搜索不重叠的事件链。当前链匹配后,它开始搜索下一个链。
!!! warning "警告"
在同一秒钟发生的事件可能以未定义的顺序排列在序列中,影响结果。
@ -180,11 +179,11 @@ sequenceCount(pattern)(timestamp, cond1, cond2, ...)
**参数**
- `pattern`Pattern string. See [模式语法](#sequence-function-pattern-syntax).
- `pattern`模式字符串。 参考:[模式语法](#sequence-function-pattern-syntax).
- `timestamp`Column considered to contain time data. Typical data types are `Date``DateTime`. 您还可以使用任何支持的 [UInt](../../sql-reference/data-types/int-uint.md) 数据类型。
- `timestamp`包含时间的列。典型的时间类型是: `Date``DateTime`您还可以使用任何支持的 [UInt](../../sql-reference/data-types/int-uint.md) 数据类型。
- `cond1`, `cond2`Conditions that describe the chain of events. Data type: `UInt8`. 最多可以传递32个条件参数。 该函数只考虑这些条件中描述的事件。 如果序列包含未在条件中描述的数据,则函数将跳过这些数据。
- `cond1`, `cond2`事件链的约束条件。 数据类型是: `UInt8`。 最多可以传递32个条件参数。该函数只考虑这些条件中描述的事件。 如果序列包含未在条件中描述的数据,则函数将跳过这些数据。
**返回值**
@ -227,9 +226,9 @@ SELECT sequenceCount('(?1).*(?2)')(time, number = 1, number = 2) FROM t
搜索滑动时间窗中的事件链,并计算从链中发生的最大事件数。
该函数根据算法工作:
该函数采用如下算法:
- 该函数搜索触发链中的第一个条件并将事件计数器设置为1的数据。 这是滑动窗口启动的时刻。
- 该函数搜索触发链中的第一个条件并将事件计数器设置为1。 这是滑动窗口启动的时刻。
- 如果来自链的事件在窗口内顺序发生,则计数器将递增。 如果事件序列中断,则计数器不会增加。
@ -243,11 +242,11 @@ windowFunnel(window, [mode])(timestamp, cond1, cond2, ..., condN)
**参数**
- `window`Length of the sliding window in seconds.
- `mode` -这是一个可选的参数。
- `'strict'` -当 `'strict'` 设置时windowFunnel()仅对唯一值应用条件。
- `timestamp`Name of the column containing the timestamp. Data types supported: [日期](../../sql-reference/data-types/date.md), [日期时间](../../sql-reference/data-types/datetime.md#data_type-datetime) 和其他无符号整数类型(请注意,即使时间戳支持 `UInt64` 类型它的值不能超过Int64最大值即2^63-1
- `cond`Conditions or data describing the chain of events. [UInt8](../../sql-reference/data-types/int-uint.md).
- `window`滑动窗户的大小,单位是秒。
- `mode` - 这是一个可选的参数。
- `'strict'` - `'strict'` 设置时windowFunnel()仅对唯一值应用匹配条件。
- `timestamp`包含时间的列。 数据类型支持: [日期](../../sql-reference/data-types/date.md), [日期时间](../../sql-reference/data-types/datetime.md#data_type-datetime) 和其他无符号整数类型(请注意,即使时间戳支持 `UInt64` 类型它的值不能超过Int64最大值即2^63-1
- `cond`事件链的约束条件。 [UInt8](../../sql-reference/data-types/int-uint.md) 类型。
**返回值**
@ -284,7 +283,7 @@ windowFunnel(window, [mode])(timestamp, cond1, cond2, ..., condN)
└────────────┴─────────┴─────────────────────┴─────────┴─────────┘
```
了解用户有多远 `user_id` 可以在2019的1-2月期间通过链条。
了解用户`user_id` 可以在2019的1-2月期间通过链条多远
查询:
@ -315,10 +314,10 @@ ORDER BY level ASC
## Retention {#retention}
该函数将一组条件作为参数类型为1到32个参数 `UInt8` 表示事件是否满足特定条件。
该函数将一组条件作为参数类型为1到32个 `UInt8` 类型的参数,用来表示事件是否满足特定条件。
任何条件都可以指定为参数(如 [WHERE](../../sql-reference/statements/select/where.md#select-where)).
除了第一个以外,条件成对适用:如果第一个和第二个是真的,第二个结果将是真的,如果第一个和fird是真的,第三个结果将是真的,等等。
除了第一个以外,条件成对适用:如果第一个和第二个是真的,第二个结果将是真的,如果第一个和第三个是真的,第三个结果将是真的,等等。
**语法**
@ -328,22 +327,22 @@ retention(cond1, cond2, ..., cond32);
**参数**
- `cond`an expression that returns a `UInt8` 结果1或0
- `cond`返回 `UInt8` 结果1或0的表达式
**返回值**
数组为1或0。
- 1 — condition was met for the event.
- 0 — condition wasn't met for the event.
- 1 — 条件满足。
- 0 — 条件不满足。
类型: `UInt8`.
**示例**
让我们考虑计算的一个例子 `retention` 功能,以确定网站流量。
让我们考虑使用 `retention` 功能的一个例子 ,以确定网站流量。
**1.** Сreate a table to illustrate an example.
**1.** 举例说明,先创建一张表。
``` sql
CREATE TABLE retention_test(date Date, uid Int32) ENGINE = Memory;
@ -402,7 +401,7 @@ SELECT * FROM retention_test
└────────────┴─────┘
```
**2.** 按唯一ID对用户进行分组 `uid` 使用 `retention` 功能。
**2.** 按唯一ID `uid` 对用户进行分组,使用 `retention` 功能。
查询:
@ -466,7 +465,7 @@ FROM
└────┴────┴────┘
```
哪里:
条件:
- `r1`-2020-01-01期间访问该网站的独立访问者数量 `cond1` 条件)。
- `r2`-在2020-01-01和2020-01-02之间的特定时间段内访问该网站的唯一访问者的数量 (`cond1` 和 `cond2` 条件)。
@ -474,9 +473,9 @@ FROM
## uniqUpTo(N)(x) {#uniquptonx}
Calculates the number of different argument values if it is less than or equal to N. If the number of different argument values is greater than N, it returns N + 1.
计算小于或者等于N的不同参数的个数。如果结果大于N那返回N+1。
建议使用小Ns高达10。 N的最大值为100。
建议使用较小的Ns比如10。N的最大值为100。
对于聚合函数的状态它使用的内存量等于1+N\*一个字节值的大小。
对于字符串它存储8个字节的非加密哈希。 也就是说,计算是近似的字符串。
@ -488,12 +487,12 @@ Calculates the number of different argument values if it is less than or e
用法示例:
``` text
Problem: Generate a report that shows only keywords that produced at least 5 unique users.
Solution: Write in the GROUP BY query SearchPhrase HAVING uniqUpTo(4)(UserID) >= 5
问题:产出一个不少于五个唯一用户的关键字报告
解决方案: 写group by查询语句 HAVING uniqUpTo(4)(UserID) >= 5
```
## sumMapFiltered(keys\_to\_keep)(keys, values) {#summapfilteredkeys-to-keepkeys-values}
和 [sumMap](reference.md#agg_functions-summap) 基本一致, 除了一个键数组作为参数传递。这在使用高基数key时尤其有用。
[原始文章](https://clickhouse.tech/docs/en/query_language/agg_functions/parametric_functions/) <!--hide-->
## sumMapFiltered(keys\_to\_keep)(键值) {#summapfilteredkeys-to-keepkeys-values}
同样的行为 [sumMap](reference.md#agg_functions-summap) 除了一个键数组作为参数传递。 这在使用高基数密钥时尤其有用。

View File

@ -1,13 +1,11 @@
---
machine_translated: true
machine_translated_rev: 72537a2d527c63c07aa5d2361a8829f3895cf2bd
toc_priority: 36
toc_title: "\u53C2\u8003\u8D44\u6599"
toc_title: 聚合函数
---
# 聚合函数引用 {#aggregate-functions-reference}
## 计数 {#agg_function-count}
## count {#agg_function-count}
计数行数或非空值。
@ -73,7 +71,7 @@ SELECT count(DISTINCT num) FROM t
这个例子表明 `count(DISTINCT num)` 由执行 `uniqExact` 根据功能 `count_distinct_implementation` 设定值。
## 任何(x) {#agg_function-any}
## any(x) {#agg_function-any}
选择第一个遇到的值。
查询可以以任何顺序执行,甚至每次都以不同的顺序执行,因此此函数的结果是不确定的。
@ -115,7 +113,7 @@ FROM ontime
选择遇到的最后一个值。
其结果是一样不确定的 `any` 功能。
## 集团比特 {#groupbitand}
## groupBitAnd {#groupbitand}
按位应用 `AND` 对于一系列的数字。
@ -337,7 +335,7 @@ SELECT argMin(user, salary) FROM salary
总计 value 数组根据在指定的键 key 阵列。
传递键和值数组的元组与传递两个键和值数组是同义的。
元素的数量 keyvalue 总计的每一行必须相同。
Returns a tuple of two arrays: keys in sorted order, and values summed for the corresponding keys.
返回两个数组的一个二元组: key是排好序的value是对应key的求和。
示例:
@ -374,7 +372,7 @@ GROUP BY timeslot
## skewPop {#skewpop}
计算 [歪斜](https://en.wikipedia.org/wiki/Skewness) 的序列
计算的序列[偏度](https://en.wikipedia.org/wiki/Skewness)
``` sql
skewPop(expr)
@ -386,7 +384,7 @@ skewPop(expr)
**返回值**
The skewness of the given distribution. Type — [Float64](../../sql-reference/data-types/float.md)
给定序列的偏度。类型 — [Float64](../../sql-reference/data-types/float.md)
**示例**
@ -410,7 +408,7 @@ skewSamp(expr)
**返回值**
The skewness of the given distribution. Type — [Float64](../../sql-reference/data-types/float.md). 如果 `n <= 1` (`n` 是样本的大小),则该函数返回 `nan`.
给定序列的偏度。 类型 — [Float64](../../sql-reference/data-types/float.md). 如果 `n <= 1` (`n` 是样本的大小),则该函数返回 `nan`.
**示例**
@ -432,7 +430,7 @@ kurtPop(expr)
**返回值**
The kurtosis of the given distribution. Type — [Float64](../../sql-reference/data-types/float.md)
给定序列的峰度。 类型 — [Float64](../../sql-reference/data-types/float.md)
**示例**
@ -456,7 +454,7 @@ kurtSamp(expr)
**返回值**
The kurtosis of the given distribution. Type — [Float64](../../sql-reference/data-types/float.md). 如果 `n <= 1` (`n` 是样本的大小),则该函数返回 `nan`.
给定序列的峰度。类型 — [Float64](../../sql-reference/data-types/float.md). 如果 `n <= 1` (`n` 是样本的大小),则该函数返回 `nan`.
**示例**
@ -533,7 +531,7 @@ FROM (
只适用于数字。
结果总是Float64。
## 平均加权 {#avgweighted}
## avgWeighted {#avgweighted}
计算 [加权算术平均值](https://en.wikipedia.org/wiki/Weighted_arithmetic_mean).
@ -545,10 +543,10 @@ avgWeighted(x, weight)
**参数**
- `x`Values. [整数](../data-types/int-uint.md) 或 [浮点](../data-types/float.md).
- `weight`Weights of the values. [整数](../data-types/int-uint.md) 或 [浮点](../data-types/float.md).
- `x`值。 [整数](../data-types/int-uint.md) 或 [浮点](../data-types/float.md).
- `weight`值的加权。 [整数](../data-types/int-uint.md) 或 [浮点](../data-types/float.md).
类型 `x``weight` 一定是一样的
`x``weight` 的类型一定是一样的
**返回值**
@ -590,7 +588,7 @@ uniq(x[, ...])
- A [UInt64](../../sql-reference/data-types/int-uint.md)-键入号码。
**实细节**
**实细节**
功能:
@ -598,7 +596,7 @@ uniq(x[, ...])
- 使用自适应采样算法。 对于计算状态该函数使用最多65536个元素哈希值的样本。
This algorithm is very accurate and very efficient on the CPU. When the query contains several of these functions, using `uniq` is almost as fast as using other aggregate functions.
这个算法是非常精确的并且对于CPU来说非常高效。如果查询包含一些这样的函数那和其他聚合函数相比 `uniq` 将是几乎一样快。
- 确定性地提供结果(它不依赖于查询处理顺序)。
@ -629,17 +627,17 @@ uniqCombined(HLL_precision)(x[, ...])
**返回值**
- 一个数字 [UInt64](../../sql-reference/data-types/int-uint.md)-键入号码
- 一个[UInt64](../../sql-reference/data-types/int-uint.md)类型的数字
**实细节**
**实细节**
功能:
- 计算散列64位散列 `String` 否则32位对于聚合中的所有参数然后在计算中使用它。
- 使用三种算法的组合数组、哈希表和HyperLogLog与error错表
- 使用三种算法的组合:数组、哈希表和包含错误修正表的HyperLogLog。
For a small number of distinct elements, an array is used. When the set size is larger, a hash table is used. For a larger number of elements, HyperLogLog is used, which will occupy a fixed amount of memory.
少量的不同的值,使用数组。 值再多一些使用哈希表。对于大量的数据来说使用HyperLogLogHyperLogLog占用一个固定的内存空间。
- 确定性地提供结果(它不依赖于查询处理顺序)。
@ -650,7 +648,7 @@ uniqCombined(HLL_precision)(x[, ...])
- 消耗少几倍的内存。
- 计算精度高出几倍。
- 通常具有略低的性能。 在某些情况下, `uniqCombined` 可以表现得比 `uniq`,例如,使用通过网络传输大量聚合状态的分布式查询。
- 通常具有略低的性能。 在某些情况下, `uniqCombined` 可以表现得比 `uniq`,例如,使用通过网络传输大量聚合状态的分布式查询。
**另请参阅**
@ -679,7 +677,7 @@ uniqHLL12(x[, ...])
- A [UInt64](../../sql-reference/data-types/int-uint.md)-键入号码。
**实细节**
**实细节**
功能:
@ -707,9 +705,9 @@ uniqHLL12(x[, ...])
uniqExact(x[, ...])
```
使用 `uniqExact` 功能,如果你绝对需要一个确切的结果。 否则使用 [uniq](#agg_function-uniq) 功能。
如果你绝对需要一个确切的结果,使用 `uniqExact` 功能。 否则使用 [uniq](#agg_function-uniq) 功能。
`uniqExact` 功能使用更多的内存`uniq`,因为状态的大小随着不同值的数量的增加而无界增长。
`uniqExact``uniq` 使用更多的内存,因为状态的大小随着不同值的数量的增加而无界增长。
**参数**
@ -721,7 +719,7 @@ uniqExact(x[, ...])
- [uniqCombined](#agg_function-uniqcombined)
- [uniqHLL12](#agg_function-uniqhll12)
## 群交(x),群交(max\_size)(x) {#agg_function-grouparray}
## groupArray(x), groupArray(max\_size)(x) {#agg_function-grouparray}
创建参数值的数组。
值可以按任何(不确定)顺序添加到数组中。
@ -748,10 +746,10 @@ groupArrayInsertAt(default_x, size)(x, pos);
**参数**
- `x`Value to be inserted. [表达式](../syntax.md#syntax-expressions) 导致的一个 [支持的数据类型](../../sql-reference/data-types/index.md).
- `pos`Position at which the specified element `x` 将被插入。 数组中的索引编号从零开始。 [UInt32](../../sql-reference/data-types/int-uint.md#uint-ranges).
- `default_x`Default value for substituting in empty positions. Optional parameter. [表达式](../syntax.md#syntax-expressions) 导致为配置的数据类型 `x` 参数。 如果 `default_x` 未定义,则 [默认值](../../sql-reference/statements/create.md#create-default-values) 被使用。
- `size`Length of the resulting array. Optional parameter. When using this parameter, the default value `default_x` 必须指定。 [UInt32](../../sql-reference/data-types/int-uint.md#uint-ranges).
- `x`被插入的值。[表达式](../syntax.md#syntax-expressions) 导致的一个 [支持的数据类型](../../sql-reference/data-types/index.md).
- `pos``x` 将被插入的位置。 数组中的索引编号从零开始。 [UInt32](../../sql-reference/data-types/int-uint.md#uint-ranges).
- `default_x`如果代入值为空,则使用默认值。可选参数。[表达式](../syntax.md#syntax-expressions) 为 `x` 数据类型的数据。 如果 `default_x` 未定义,则 [默认值](../../sql-reference/statements/create.md#create-default-values) 被使用。
- `size`结果数组的长度。可选参数。如果使用该参数,`default_x` 必须指定。 [UInt32](../../sql-reference/data-types/int-uint.md#uint-ranges).
**返回值**
@ -803,7 +801,7 @@ SELECT groupArrayInsertAt('-', 5)(toString(number), number * 2) FROM numbers(5);
└───────────────────────────────────────────────────────────────────┘
```
元件的多线程插入到一个位置
在一个位置多线程插入数据
查询:
@ -832,8 +830,8 @@ groupArrayMovingSum(window_size)(numbers_for_summing)
**参数**
- `numbers_for_summing` — [表达式](../syntax.md#syntax-expressions) 生成数值数据类型值。
- `window_size`Size of the calculation window.
- `numbers_for_summing` — [表达式](../syntax.md#syntax-expressions) 数值数据类型值。
- `window_size`窗口大小。
**返回值**
@ -906,13 +904,13 @@ groupArrayMovingAvg(window_size)(numbers_for_summing)
**参数**
- `numbers_for_summing` — [表达式](../syntax.md#syntax-expressions) 生成数值数据类型值。
- `window_size`Size of the calculation window.
- `window_size`窗口大小。
**返回值**
- 与输入数据大小和类型相同的数组。
该函数使用 [四舍五入到零](https://en.wikipedia.org/wiki/Rounding#Rounding_towards_zero). 它截断结果数据类型的小数位数
该函数使用 [四舍五入到零](https://en.wikipedia.org/wiki/Rounding#Rounding_towards_zero). 它截断无意义的小数位来保证结果数据类型。
**示例**
@ -967,20 +965,20 @@ FROM t
└───────────┴──────────────────────────────────┴───────────────────────┘
```
## 禄,赂麓ta脌麓,):脡,,拢脢,group媒group)galaxy s8碌胫脢)禄煤)酶脱脩) {#groupuniqarrayx-groupuniqarraymax-sizex}
## groupUniqArray(x), groupUniqArray(max\_size)(x) {#groupuniqarrayx-groupuniqarraymax-sizex}
从不同的参数值创建一个数组。 内存消耗是一样的 `uniqExact` 功能。
第二个版本(`max_size` 参数)将结果数组的大小限制为 `max_size` 元素。
第二个版本(`max_size` 参数)将结果数组的大小限制为 `max_size` 元素。
例如, `groupUniqArray(1)(x)` 相当于 `[any(x)]`.
## 分位数 {#quantile}
## quantile {#quantile}
计算近似[分位数](https://en.wikipedia.org/wiki/Quantile) 的数字数据序列
计算数字序列的近似[分位数](https://en.wikipedia.org/wiki/Quantile)。
此功能适用 [油藏采样](https://en.wikipedia.org/wiki/Reservoir_sampling) 随着储存器大小高达8192和随机数发生器进行采样。 结果是非确定性的。 要获得精确的分位数,请使用 [quantileExact](#quantileexact) 功能。
此功能适用 [水塘抽样(](https://en.wikipedia.org/wiki/Reservoir_sampling),使用储存器最大到8192和随机数发生器进行采样。 结果是非确定性的。 要获得精确的分位数,请使用 [quantileExact](#quantileexact) 功能。
使用多个 `quantile*` 在查询中具有不同级别的函数,内部状态不会被组合(即查询的工作效率低于它可以)。 在这种情况下,使用 [分位数](#quantiles) 功能。
在一个查询中使用多个不同层次的 `quantile*` 时,内部状态不会被组合(即查询的工作效率低于组合情况)。在这种情况下,使用[分位数](#quantiles)功能。
**语法**
@ -992,12 +990,12 @@ quantile(level)(expr)
**参数**
- `level`Level of quantile. Optional parameter. Constant floating-point number from 0 to 1. We recommend using a `level` 值的范围 `[0.01, 0.99]`. 默认值0.5。 在 `level=0.5` 该函数计算 [中位数](https://en.wikipedia.org/wiki/Median).
- `expr`Expression over the column values resulting in numeric [数据类型](../../sql-reference/data-types/index.md#data_types), [日期](../../sql-reference/data-types/date.md) 或 [日期时间](../../sql-reference/data-types/datetime.md).
- `level`分位数层次。可选参数。 从0到1的一个float类型的常量。 我们推荐 `level` 值的范围为 `[0.01, 0.99]`. 默认值0.5。 在 `level=0.5` 该函数计算 [中位数](https://en.wikipedia.org/wiki/Median).
- `expr`求职表达式,类型为:数值[数据类型](../../sql-reference/data-types/index.md#data_types),[日期](../../sql-reference/data-types/date.md)数据类型或[时间](../../sql-reference/data-types/datetime.md)数据类型。
**返回值**
- 指定电平的近似分位数。
- 指定层次的近似分位数。
类型:
@ -1037,13 +1035,13 @@ SELECT quantile(val) FROM t
- [中位数](#median)
- [分位数](#quantiles)
## 量化确定 {#quantiledeterministic}
## quantileDeterministic {#quantiledeterministic}
计算近似[分位数](https://en.wikipedia.org/wiki/Quantile) 的数字数据序列
计算数字序列的近似[分位数](https://en.wikipedia.org/wiki/Quantile)。
此功能适用 [油藏采样](https://en.wikipedia.org/wiki/Reservoir_sampling) 与储层大小高达8192和采样的确定性算法。 结果是确定性的。 要获得精确的分位数,请使用 [quantileExact](#quantileexact) 功能。
此功能适用 [水塘抽样(](https://en.wikipedia.org/wiki/Reservoir_sampling)使用储存器最大到8192和随机数发生器进行采样。 结果是非确定性的。 要获得精确的分位数,请使用 [quantileExact](#quantileexact) 功能。
使用多个 `quantile*` 在查询中具有不同级别的函数,内部状态不会被组合(即查询的工作效率低于它可以)。 在这种情况下,使用 [分位数](#quantiles) 功能。
在一个查询中使用多个不同层次的 `quantile*` 时,内部状态不会被组合(即查询的工作效率低于组合情况)。在这种情况下,使用[分位数](#quantiles)功能。
**语法**
@ -1055,13 +1053,13 @@ quantileDeterministic(level)(expr, determinator)
**参数**
- `level`Level of quantile. Optional parameter. Constant floating-point number from 0 to 1. We recommend using a `level` 值的范围 `[0.01, 0.99]`. 默认值0.5。 在 `level=0.5` 该函数计算 [中位数](https://en.wikipedia.org/wiki/Median).
- `expr`Expression over the column values resulting in numeric [数据类型](../../sql-reference/data-types/index.md#data_types), [日期](../../sql-reference/data-types/date.md) 或 [日期时间](../../sql-reference/data-types/datetime.md).
- `determinator`Number whose hash is used instead of a random number generator in the reservoir sampling algorithm to make the result of sampling deterministic. As a determinator you can use any deterministic positive number, for example, a user id or an event id. If the same determinator value occures too often, the function works incorrectly.
- `level`分位数层次。可选参数。 从0到1的一个float类型的常量。 我们推荐 `level` 值的范围为 `[0.01, 0.99]`. 默认值0.5。 在 `level=0.5` 该函数计算 [中位数](https://en.wikipedia.org/wiki/Median).
- `expr`求职表达式,类型为:数值[数据类型](../../sql-reference/data-types/index.md#data_types),[日期](../../sql-reference/data-types/date.md)数据类型或[时间](../../sql-reference/data-types/datetime.md)数据类型。
- `determinator`一个数字其hash被用来代替在水塘抽样中随机生成的数字这样可以保证取样的确定性。你可以使用用户ID或者事件ID等任何正数但是如果相同的 `determinator` 出现多次,那结果很可能不正确。
**返回值**
- 指定电平的近似分位数。
- 指定层次的近似分位数。
类型:
@ -1103,11 +1101,11 @@ SELECT quantileDeterministic(val, 1) FROM t
## quantileExact {#quantileexact}
正是计算 [分位数](https://en.wikipedia.org/wiki/Quantile) 的数字数据序列
准确计算数字序列的[分位数](https://en.wikipedia.org/wiki/Quantile)
To get exact value, all the passed values are combined into an array, which is then partially sorted. Therefore, the function consumes `O(n)` 内存,其中 `n` 是传递的多个值。 然而,对于少量的值,该函数是非常有效的。
为了准确计算,所有输入的数据被合并为一个数组,并且部分的排序。因此该函数需要 `O(n)` 的内存n为输入数据的个数。但是对于少量数据来说该函数还是非常有效的。
使用多个 `quantile*` 在查询中具有不同级别的函数,内部状态不会被组合(即查询的工作效率低于它可以)。 在这种情况下,使用 [分位数](#quantiles) 功能。
在一个查询中使用多个不同层次的 `quantile*` 时,内部状态不会被组合(即查询的工作效率低于组合情况)。在这种情况下,使用[分位数](#quantiles)功能。
**语法**
@ -1119,12 +1117,12 @@ quantileExact(level)(expr)
**参数**
- `level`Level of quantile. Optional parameter. Constant floating-point number from 0 to 1. We recommend using a `level` 值的范围 `[0.01, 0.99]`. 默认值0.5。 在 `level=0.5` 该函数计算 [中位数](https://en.wikipedia.org/wiki/Median).
- `expr`Expression over the column values resulting in numeric [数据类型](../../sql-reference/data-types/index.md#data_types), [日期](../../sql-reference/data-types/date.md) 或 [日期时间](../../sql-reference/data-types/datetime.md).
- `level`分位数层次。可选参数。 从0到1的一个float类型的常量。 我们推荐 `level` 值的范围为 `[0.01, 0.99]`. 默认值0.5。 在 `level=0.5` 该函数计算 [中位数](https://en.wikipedia.org/wiki/Median).
- `expr`求职表达式,类型为:数值[数据类型](../../sql-reference/data-types/index.md#data_types),[日期](../../sql-reference/data-types/date.md)数据类型或[时间](../../sql-reference/data-types/datetime.md)数据类型。
**返回值**
- 指定电平的分位数。
- 指定层次的分位数。
类型:
@ -1153,13 +1151,13 @@ SELECT quantileExact(number) FROM numbers(10)
- [中位数](#median)
- [分位数](#quantiles)
## 分位数加权 {#quantileexactweighted}
## quantileExactWeighted {#quantileexactweighted}
正是计算 [分位数](https://en.wikipedia.org/wiki/Quantile) 数值数据序列,考虑到每个元素的权重
考虑到每个元素的权重,然后准确计算数值序列的[分位数](https://en.wikipedia.org/wiki/Quantile)
To get exact value, all the passed values are combined into an array, which is then partially sorted. Each value is counted with its weight, as if it is present `weight` times. A hash table is used in the algorithm. Because of this, if the passed values are frequently repeated, the function consumes less RAM than [quantileExact](#quantileexact). 您可以使用此功能,而不是 `quantileExact` 并指定重量1。
为了准确计算,所有输入的数据被合并为一个数组,并且部分的排序。每个输入值需要根据 `weight` 计算求和。该算法使用哈希表。正因为如此,在数据重复较多的时候使用的内存是少于[quantileExact](#quantileexact)的。 您可以使用此函数代替 `quantileExact` 并指定重量1。
使用多个 `quantile*` 在查询中具有不同级别的函数,内部状态不会被组合(即查询的工作效率低于它可以)。 在这种情况下,使用 [分位数](#quantiles) 功能。
在一个查询中使用多个不同层次的 `quantile*` 时,内部状态不会被组合(即查询的工作效率低于组合情况)。在这种情况下,使用[分位数](#quantiles)功能。
**语法**
@ -1171,13 +1169,13 @@ quantileExactWeighted(level)(expr, weight)
**参数**
- `level`Level of quantile. Optional parameter. Constant floating-point number from 0 to 1. We recommend using a `level` 值的范围 `[0.01, 0.99]`. 默认值0.5。 在 `level=0.5` 该函数计算 [中位数](https://en.wikipedia.org/wiki/Median).
- `expr`Expression over the column values resulting in numeric [数据类型](../../sql-reference/data-types/index.md#data_types), [日期](../../sql-reference/data-types/date.md) 或 [日期时间](../../sql-reference/data-types/datetime.md).
- `weight`Column with weights of sequence members. Weight is a number of value occurrences.
- `level`分位数层次。可选参数。 从0到1的一个float类型的常量。 我们推荐 `level` 值的范围为 `[0.01, 0.99]`. 默认值0.5。 在 `level=0.5` 该函数计算 [中位数](https://en.wikipedia.org/wiki/Median).
- `expr`求职表达式,类型为:数值[数据类型](../../sql-reference/data-types/index.md#data_types),[日期](../../sql-reference/data-types/date.md)数据类型或[时间](../../sql-reference/data-types/datetime.md)数据类型。
- `weight`权重序列。 权重是一个数据出现的数值。
**返回值**
- 指定电平的分位数。
- 指定层次的分位数。
类型:
@ -1217,13 +1215,13 @@ SELECT quantileExactWeighted(n, val) FROM t
- [中位数](#median)
- [分位数](#quantiles)
## 分位定时 {#quantiletiming}
## quantileTiming {#quantiletiming}
随着确定的精度计算 [分位数](https://en.wikipedia.org/wiki/Quantile) 的数字数据序列
使用确定的精度计算数字数据序列的[分位数](https://en.wikipedia.org/wiki/Quantile)
结果是确定性的(它不依赖于查询处理顺序)。 该函数针对描述加载网页时间或后端响应时间等分布的序列进行了优化。
使用多个 `quantile*` 在查询中具有不同级别的函数,内部状态不会被组合(即查询的工作效率低于它可以)。 在这种情况下,使用 [分位数](#quantiles) 功能。
在一个查询中使用多个不同层次的 `quantile*` 时,内部状态不会被组合(即查询的工作效率低于组合情况)。在这种情况下,使用[分位数](#quantiles)功能。
**语法**
@ -1235,12 +1233,12 @@ quantileTiming(level)(expr)
**参数**
- `level`Level of quantile. Optional parameter. Constant floating-point number from 0 to 1. We recommend using a `level` 值的范围 `[0.01, 0.99]`. 默认值0.5。 在 `level=0.5` 该函数计算 [中位数](https://en.wikipedia.org/wiki/Median).
- `level`分位数层次。可选参数。 从0到1的一个float类型的常量。 我们推荐 `level` 值的范围为 `[0.01, 0.99]`. 默认值0.5。 在 `level=0.5` 该函数计算 [中位数](https://en.wikipedia.org/wiki/Median).
- `expr` — [表达式](../syntax.md#syntax-expressions) 在一个列值返回 [浮动\*](../../sql-reference/data-types/float.md)-键入号码
- `expr` — [表达式](../syntax.md#syntax-expressions),返回 [浮动\*](../../sql-reference/data-types/float.md)类型数据
- If negative values are passed to the function, the behavior is undefined.
- If the value is greater than 30,000 (a page loading time of more than 30 seconds), it is assumed to be 30,000.
- 如果输入负值,那结果是不可预期的。
- 如果输入值大于30000页面加载时间大于30s那我们假设为30000。
**精度**
@ -1252,16 +1250,16 @@ quantileTiming(level)(expr)
否则计算结果将四舍五入到16毫秒的最接近倍数。
!!! note "注"
对于计算页面加载时间分位数,此函数比 [分位数](#quantile).
对于计算页面加载时间分位数,此函数比 [分位数](#quantile)更有效和准确。
**返回值**
- 指定电平的分位数。
- 指定层次的分位数。
类型: `Float32`.
!!! note "注"
如果没有值传递给函数(当使用 `quantileTimingIf`), [阿南](../../sql-reference/data-types/float.md#data_type-float-nan-inf) 被返回。 这样做的目的是将这些案例与导致零的案例区分开来。 看 [按条款订购](../statements/select/order-by.md#select-order-by) 对于排序注意事项 `NaN` 值。
如果没有值传递给函数(当使用 `quantileTimingIf`), [NaN](../../sql-reference/data-types/float.md#data_type-float-nan-inf) 被返回。 这样做的目的是将这些案例与导致零的案例区分开来。 看 [ORDER BY clause](../statements/select/order-by.md#select-order-by) 对于 `NaN`排序注意事项
**示例**
@ -1300,13 +1298,13 @@ SELECT quantileTiming(response_time) FROM t
- [中位数](#median)
- [分位数](#quantiles)
## 分位时间加权 {#quantiletimingweighted}
## quantileTimingWeighted {#quantiletimingweighted}
随着确定的精度计算 [分位数](https://en.wikipedia.org/wiki/Quantile) 根据每个序列成员的权重对数字数据序列进行处理
根据每个序列成员的权重,使用确定的精度计算数字序列的[分位数](https://en.wikipedia.org/wiki/Quantile)
结果是确定性的(它不依赖于查询处理顺序)。 该函数针对描述加载网页时间或后端响应时间等分布的序列进行了优化。
使用多个 `quantile*` 在查询中具有不同级别的函数,内部状态不会被组合(即查询的工作效率低于它可以)。 在这种情况下,使用 [分位数](#quantiles) 功能。
在一个查询中使用多个不同层次的 `quantile*` 时,内部状态不会被组合(即查询的工作效率低于组合情况)。在这种情况下,使用[分位数](#quantiles)功能。
**语法**
@ -1318,14 +1316,14 @@ quantileTimingWeighted(level)(expr, weight)
**参数**
- `level`Level of quantile. Optional parameter. Constant floating-point number from 0 to 1. We recommend using a `level` 值的范围 `[0.01, 0.99]`. 默认值0.5。 在 `level=0.5` 该函数计算 [中位数](https://en.wikipedia.org/wiki/Median).
- `level`分位数层次。可选参数。 从0到1的一个float类型的常量。 我们推荐 `level` 值的范围为 `[0.01, 0.99]`. 默认值0.5。 在 `level=0.5` 该函数计算 [中位数](https://en.wikipedia.org/wiki/Median).
- `expr` — [表达式](../syntax.md#syntax-expressions) 在一个列值返回 [浮动\*](../../sql-reference/data-types/float.md)-键入号码
- `expr` — [表达式](../syntax.md#syntax-expressions),返回 [浮动\*](../../sql-reference/data-types/float.md)类型数据
- If negative values are passed to the function, the behavior is undefined.
- If the value is greater than 30,000 (a page loading time of more than 30 seconds), it is assumed to be 30,000.
- 如果输入负值,那结果是不可预期的。
- 如果输入值大于30000页面加载时间大于30s那我们假设为30000。
- `weight`Column with weights of sequence elements. Weight is a number of value occurrences.
- `weight`权重序列。 权重是一个数据出现的数值。
**精度**
@ -1337,16 +1335,16 @@ quantileTimingWeighted(level)(expr, weight)
否则计算结果将四舍五入到16毫秒的最接近倍数。
!!! note "注"
对于计算页面加载时间分位数,此函数比 [分位数](#quantile).
对于计算页面加载时间分位数,此函数比 [分位数](#quantile)更高效和准确。
**返回值**
- 指定电平的分位数。
- 指定层次的分位数。
类型: `Float32`.
!!! note "注"
如果没有值传递给函数(当使用 `quantileTimingIf`), [阿南](../../sql-reference/data-types/float.md#data_type-float-nan-inf) 被返回。 这样做的目的是将这些案例与导致零的案例区分开来。 看 [按条款订购](../statements/select/order-by.md#select-order-by) 对于排序注意事项 `NaN` 值。
如果没有值传递给函数(当使用 `quantileTimingIf`), [NaN](../../sql-reference/data-types/float.md#data_type-float-nan-inf) 被返回。 这样做的目的是将这些案例与导致零的案例区分开来。看 [ORDER BY clause](../statements/select/order-by.md#select-order-by) 对于 `NaN`排序注意事项
**示例**
@ -1384,13 +1382,13 @@ SELECT quantileTimingWeighted(response_time, weight) FROM t
## quantileTDigest {#quantiletdigest}
计算近似值 [分位数](https://en.wikipedia.org/wiki/Quantile) 使用的数字数据序列 [t-digest](https://github.com/tdunning/t-digest/blob/master/docs/t-digest-paper/histo.pdf) 算法。
使用[t-digest](https://github.com/tdunning/t-digest/blob/master/docs/t-digest-paper/histo.pdf) 算法计算近似[分位数](https://en.wikipedia.org/wiki/Quantile)
最大误差为1%。 内存消耗 `log(n)`哪里 `n` 是多个值。 结果取决于运行查询的顺序,并且是不确定的。
最大误差为1%。 内存消耗 `log(n)`这里 `n` 是值的个数。 结果取决于运行查询的顺序,并且是不确定的。
该功能的性能低于性能 [分位数](#quantile) 或 [分位定时](#quantiletiming). 在状态大小与精度的比率方面,这个函数比 `quantile`.
该功能的性能低于性能 [分位数](#quantile) 或 [时间分位](#quantiletiming). 在状态大小与精度的比率方面,这个函数比 `quantile`更优秀。
使用多个 `quantile*` 在查询中具有不同级别的函数,内部状态不会被组合(即查询的工作效率低于它可以)。 在这种情况下,使用 [分位数](#quantiles) 功能。
在一个查询中使用多个不同层次的 `quantile*` 时,内部状态不会被组合(即查询的工作效率低于组合情况)。在这种情况下,使用[分位数](#quantiles)功能。
**语法**
@ -1402,12 +1400,12 @@ quantileTDigest(level)(expr)
**参数**
- `level`Level of quantile. Optional parameter. Constant floating-point number from 0 to 1. We recommend using a `level` 值的范围 `[0.01, 0.99]`. 默认值0.5。 在 `level=0.5` 该函数计算 [中位数](https://en.wikipedia.org/wiki/Median).
- `expr`Expression over the column values resulting in numeric [数据类型](../../sql-reference/data-types/index.md#data_types), [日期](../../sql-reference/data-types/date.md) 或 [日期时间](../../sql-reference/data-types/datetime.md).
- `level`分位数层次。可选参数。 从0到1的一个float类型的常量。 我们推荐 `level` 值的范围为 `[0.01, 0.99]`. 默认值0.5。 在 `level=0.5` 该函数计算 [中位数](https://en.wikipedia.org/wiki/Median).
- `expr`求职表达式,类型为:数值[数据类型](../../sql-reference/data-types/index.md#data_types),[日期](../../sql-reference/data-types/date.md)数据类型或[时间](../../sql-reference/data-types/datetime.md)数据类型。
**回值**
- 指定电平的近似分位数。
- 指定层次的分位数。
类型:
@ -1438,13 +1436,13 @@ SELECT quantileTDigest(number) FROM numbers(10)
## quantileTDigestWeighted {#quantiletdigestweighted}
计算近似值 [分位数](https://en.wikipedia.org/wiki/Quantile) 使用的数字数据序列 [t-digest](https://github.com/tdunning/t-digest/blob/master/docs/t-digest-paper/histo.pdf) 算法。 该函数考虑了每个序列成员的权重。 最大误差为1%。 内存消耗 `log(n)`哪里 `n` 是多个值
使用[t-digest](https://github.com/tdunning/t-digest/blob/master/docs/t-digest-paper/histo.pdf) 算法计算近似[分位数](https://en.wikipedia.org/wiki/Quantile)。 该函数考虑了每个序列成员的权重。最大误差为1%。 内存消耗 `log(n)`这里 `n` 是值的个数
该功能的性能低于性能 [分位数](#quantile) 或 [分位定时](#quantiletiming). 在状态大小与精度的比率方面,这个函数比 `quantile`.
该功能的性能低于性能 [分位数](#quantile) 或 [时间分位](#quantiletiming). 在状态大小与精度的比率方面,这个函数比 `quantile`更优秀。
结果取决于运行查询的顺序,并且是不确定的。
使用多个 `quantile*` 在查询中具有不同级别的函数,内部状态不会被组合(即查询的工作效率低于它可以)。 在这种情况下,使用 [分位数](#quantiles) 功能。
在一个查询中使用多个不同层次的 `quantile*` 时,内部状态不会被组合(即查询的工作效率低于组合情况)。在这种情况下,使用[分位数](#quantiles)功能
**语法**
@ -1456,13 +1454,13 @@ quantileTDigest(level)(expr)
**参数**
- `level`Level of quantile. Optional parameter. Constant floating-point number from 0 to 1. We recommend using a `level` 值的范围 `[0.01, 0.99]`. 默认值0.5。 在 `level=0.5` 该函数计算 [中位数](https://en.wikipedia.org/wiki/Median).
- `expr`Expression over the column values resulting in numeric [数据类型](../../sql-reference/data-types/index.md#data_types), [日期](../../sql-reference/data-types/date.md) 或 [日期时间](../../sql-reference/data-types/datetime.md).
- `weight`Column with weights of sequence elements. Weight is a number of value occurrences.
- `level`分位数层次。可选参数。 从0到1的一个float类型的常量。 我们推荐 `level` 值的范围为 `[0.01, 0.99]`. 默认值0.5。 在 `level=0.5` 该函数计算 [中位数](https://en.wikipedia.org/wiki/Median).
- `expr`求职表达式,类型为:数值[数据类型](../../sql-reference/data-types/index.md#data_types),[日期](../../sql-reference/data-types/date.md)数据类型或[时间](../../sql-reference/data-types/datetime.md)数据类型。
- `weight`权重序列。 权重是一个数据出现的数值。
**返回值**
- 指定电平的近似分位数。
- 指定层次的分位数。
类型:
@ -1491,20 +1489,20 @@ SELECT quantileTDigestWeighted(number, 1) FROM numbers(10)
- [中位数](#median)
- [分位数](#quantiles)
## 中位数 {#median}
## median {#median}
`median*` 函数是相应的别名 `quantile*` 功能。 它们计算数字数据样本的中位数。
`median*` 函数是 `quantile*` 函数的别名。 它们计算数字数据样本的中位数。
功能:
函数:
- `median`Alias for [分位数](#quantile).
- `medianDeterministic`Alias for [量化确定](#quantiledeterministic).
- `medianExact`Alias for [quantileExact](#quantileexact).
- `medianExactWeighted`Alias for [分位数加权](#quantileexactweighted).
- `medianTiming`Alias for [分位定时](#quantiletiming).
- `medianTimingWeighted`Alias for [分位时间加权](#quantiletimingweighted).
- `medianTDigest`Alias for [quantileTDigest](#quantiletdigest).
- `medianTDigestWeighted`Alias for [quantileTDigestWeighted](#quantiletdigestweighted).
- `median`[quantile](#quantile)别名。
- `medianDeterministic`[quantileDeterministic](#quantiledeterministic)别名。
- `medianExact`[quantileExact](#quantileexact)别名。
- `medianExactWeighted`[quantileExactWeighted](#quantileexactweighted)别名。
- `medianTiming`[quantileTiming](#quantiletiming)别名。
- `medianTimingWeighted`[quantileTimingWeighted](#quantiletimingweighted)别名。
- `medianTDigest` — [quantileTDigest](#quantiletdigest)别名。
- `medianTDigestWeighted` — [quantileTDigestWeighted](#quantiletdigestweighted)别名。
**示例**
@ -1535,11 +1533,11 @@ SELECT medianDeterministic(val, 1) FROM t
## quantiles(level1, level2, …)(x) {#quantiles}
所有分位数函数也有相应的分位数函数: `quantiles`, `quantilesDeterministic`, `quantilesTiming`, `quantilesTimingWeighted`, `quantilesExact`, `quantilesExactWeighted`, `quantilesTDigest`. 这些函数在一遍中计算所列电平的所有分位数,并返回结果值的数组。
所有分位数函数也有相应的函数: `quantiles`, `quantilesDeterministic`, `quantilesTiming`, `quantilesTimingWeighted`, `quantilesExact`, `quantilesExactWeighted`, `quantilesTDigest`。这些函数一次计算所列层次的所有分位数,并返回结果值的数组。
## varSamp(x) {#varsampx}
计算金额 `Σ((x - x̅)^2) / (n - 1)`,哪里 `n` 是样本大小和 `x̅`是平均值 `x`.
计算 `Σ((x - x̅)^2) / (n - 1)`,这里 `n` 是样本大小, `x̅`是`x`的平均值。
它表示随机变量的方差的无偏估计,如果传递的值形成其样本。
@ -1550,23 +1548,23 @@ SELECT medianDeterministic(val, 1) FROM t
## varPop(x) {#varpopx}
计算金额 `Σ((x - x̅)^2) / n`,哪里 `n` 是样本大小和 `x̅`是平均值 `x`.
计算 `Σ((x - x̅)^2) / n`,这里 `n` 是样本大小, `x̅`是`x`的平均值。
换句话说,分散为一组值。 返回 `Float64`.
换句话说,计算一组数据的离差。 返回 `Float64`
!!! note "注"
该函数使用数值不稳定的算法。 如果你需要 [数值稳定性](https://en.wikipedia.org/wiki/Numerical_stability) 在计算中,使用 `varPopStable` 功能。 它的工作速度较慢,但提供较低的计算错误。
## stddevSamp(x) {#stddevsampx}
结果等于平方根 `varSamp(x)`.
结果等于平方根 `varSamp(x)`
!!! note "注"
该函数使用数值不稳定的算法。 如果你需要 [数值稳定性](https://en.wikipedia.org/wiki/Numerical_stability) 在计算中,使用 `stddevSampStable` 功能。 它的工作速度较慢,但提供较低的计算错误。
## stddevPop(x) {#stddevpopx}
结果等于平方根 `varPop(x)`.
结果等于平方根 `varPop(x)`
!!! note "注"
该函数使用数值不稳定的算法。 如果你需要 [数值稳定性](https://en.wikipedia.org/wiki/Numerical_stability) 在计算中,使用 `stddevPopStable` 功能。 它的工作速度较慢,但提供较低的计算错误。
@ -1575,15 +1573,15 @@ SELECT medianDeterministic(val, 1) FROM t
返回指定列中近似最常见值的数组。 生成的数组按值的近似频率降序排序(而不是值本身)。
实现了 [过滤节省空间](http://www.l2f.inesc-id.pt/~fmmb/wiki/uploads/Work/misnis.ref0a.pdf) 基于reduce-and-combine算法的TopK分析算法 [并行节省空间](https://arxiv.org/pdf/1401.0702.pdf).
实现了[过滤节省空间](http://www.l2f.inesc-id.pt/~fmmb/wiki/uploads/Work/misnis.ref0a.pdf)算法, 使用基于reduce-and-combine的算法借鉴[并行节省空间](https://arxiv.org/pdf/1401.0702.pdf).
``` sql
topK(N)(column)
```
此函数不提供保证的结果。 在某些情况下,可能会发生错误,并且可能会返回不是最常见值的常见值。
此函数不提供保证的结果。 在某些情况下,可能会发生错误,并且可能会返回不是最高频的值。
我们建议使用 `N < 10`;性能降低了大 `N` 值。 的最大值 `N = 65536`.
我们建议使用 `N < 10``N` 值越大,性能越低。最大值 `N = 65536`
**参数**
@ -1593,11 +1591,11 @@ topK(N)(column)
**参数**
- ' x ' The value to calculate frequency.
- ' x ' 计算的频率值。
**示例**
就拿 [时间](../../getting-started/example-datasets/ontime.md) 数据集,选择在三个最频繁出现的值 `AirlineID` 列。
就拿 [OnTime](../../getting-started/example-datasets/ontime.md) 数据集来说,选择`AirlineID` 列中出现最频繁的三个
``` sql
SELECT topK(3)(AirlineID) AS res
@ -1612,7 +1610,7 @@ FROM ontime
## topKWeighted {#topkweighted}
类似于 `topK` 但需要一个整数类型的附加参数 - `weight`. 每个价值都被记入 `weight` 次频率计算。
类似于 `topK` 但需要一个整数类型的附加参数 - `weight`. 每个输入都被记入 `weight` 次频率计算。
**语法**
@ -1622,12 +1620,12 @@ topKWeighted(N)(x, weight)
**参数**
- `N`The number of elements to return.
- `N`返回值个数。
**参数**
- `x` The value.
- `weight`The weight. [UInt8](../../sql-reference/data-types/int-uint.md).
- `x` 输入值。
- `weight`权重。 [UInt8](../../sql-reference/data-types/int-uint.md)类型。
**返回值**
@ -1651,36 +1649,36 @@ SELECT topKWeighted(10)(number, number) FROM numbers(1000)
## covarSamp(x,y) {#covarsampx-y}
计算的值 `Σ((x - x̅)(y - y̅)) / (n - 1)`.
计算 `Σ((x - x̅)(y - y̅)) / (n - 1)`
返回Float64。 当 `n <= 1`, returns +∞.
返回Float64。 当 `n <= 1`, returns +∞
!!! note "注"
该函数使用数值不稳定的算法。 如果你需要 [数值稳定性](https://en.wikipedia.org/wiki/Numerical_stability) 在计算中,使用 `covarSampStable` 功能。 它的工作速度较慢,但提供较低的计算错误。
## covarPop(x,y) {#covarpopx-y}
计算的值 `Σ((x - x̅)(y - y̅)) / n`.
计算 `Σ((x - x̅)(y - y̅)) / n`
!!! note "注"
该函数使用数值不稳定的算法。 如果你需要 [数值稳定性](https://en.wikipedia.org/wiki/Numerical_stability) 在计算中,使用 `covarPopStable` 功能。 它的工作速度较慢,但提供了较低的计算错误。
## corr(x,y) {#corrx-y}
计算Pearson相关系数: `Σ((x - x̅)(y - y̅)) / sqrt(Σ((x - x̅)^2) * Σ((y - y̅)^2))`.
计算Pearson相关系数: `Σ((x - x̅)(y - y̅)) / sqrt(Σ((x - x̅)^2) * Σ((y - y̅)^2))`
!!! note "注"
该函数使用数值不稳定的算法。 如果你需要 [数值稳定性](https://en.wikipedia.org/wiki/Numerical_stability) 在计算中,使用 `corrStable` 功能。 它的工作速度较慢,但提供较低的计算错误。
## categoricalInformationValue {#categoricalinformationvalue}
计算的值 `(P(tag = 1) - P(tag = 0))(log(P(tag = 1)) - log(P(tag = 0)))` 对于每个类别
对于每个类别计算 `(P(tag = 1) - P(tag = 0))(log(P(tag = 1)) - log(P(tag = 0)))`
``` sql
categoricalInformationValue(category1, category2, ..., tag)
```
结果指示离散(分类)要素如何使用 `[category1, category2, ...]` 有助于预测的价值的学习模型 `tag`.
结果指示离散(分类)要素如何使用 `[category1, category2, ...]` 有助于使用学习模型预测`tag`的值。
## simpleLinearRegression {#simplelinearregression}
@ -1692,12 +1690,12 @@ simpleLinearRegression(x, y)
参数:
- `x`Column with dependent variable values.
- `y`Column with explanatory variable values.
- `x`x轴。
- `y`y轴。
返回值:
常量 `(a, b)` 结果行的 `y = a*x + b`.
符合`y = a*x + b`的常量 `(a, b)`
**例**
@ -1721,9 +1719,9 @@ SELECT arrayReduce('simpleLinearRegression', [0, 1, 2, 3], [3, 4, 5, 6])
└───────────────────────────────────────────────────────────────────┘
```
## 随机指标线上回归 {#agg_functions-stochasticlinearregression}
## stochasticLinearRegression {#agg_functions-stochasticlinearregression}
该函数实现随机线性回归。 它支持自定义参数的学习率L2正则化系数迷你批量大小并具有更新权重的方法很少 ([亚当](https://en.wikipedia.org/wiki/Stochastic_gradient_descent#Adam) (默认使用), [简单SGD](https://en.wikipedia.org/wiki/Stochastic_gradient_descent), [动量](https://en.wikipedia.org/wiki/Stochastic_gradient_descent#Momentum), [Nesterov](https://mipt.ru/upload/medialibrary/d7e/41-91.pdf)).
该函数实现随机线性回归。 它支持自定义参数的学习率、L2正则化系数、微批并且具有少量更新权重的方法[Adam](https://en.wikipedia.org/wiki/Stochastic_gradient_descent#Adam) (默认), [simple SGD](https://en.wikipedia.org/wiki/Stochastic_gradient_descent) [Momentum](https://en.wikipedia.org/wiki/Stochastic_gradient_descent#Momentum) [Nesterov](https://mipt.ru/upload/medialibrary/d7e/41-91.pdf))。
### 参数 {#agg_functions-stochasticlinearregression-parameters}
@ -1738,14 +1736,14 @@ stochasticLinearRegression(1.0, 1.0, 10, 'SGD')
3. `mini-batch size` 设置元素的数量,这些元素将被计算和求和以执行梯度下降的一个步骤。 纯随机下降使用一个元素但是具有小批量约10个元素使梯度步骤更稳定。 默认值为 `15`.
4. `method for updating weights` 他们是: `Adam` (默认情况下), `SGD`, `Momentum`, `Nesterov`. `Momentum``Nesterov` 需要更多的计算和内存,但是它们恰好在收敛速度和随机梯度方法的稳定性方面是有用的。
### 用 {#agg_functions-stochasticlinearregression-usage}
### 用 {#agg_functions-stochasticlinearregression-usage}
`stochasticLinearRegression` 用于两个步骤:拟合模型和预测新数据。 为了拟合模型并保存其状态以供以后使用,我们使用 `-State` combinator它基本上保存了状态模型权重等
为了预测我们使用函数 [evalMLMethod](../functions/machine-learning-functions.md#machine_learning_methods-evalmlmethod),这需要一个状态作为参数以及特征来预测。
<a name="stochasticlinearregression-usage-fitting"></a>
**1.** 适合
**1.** 安装
可以使用这种查询。
@ -1807,28 +1805,28 @@ evalMLMethod(model, param1, param2) FROM test_data
stochasticLogisticRegression(1.0, 1.0, 10, 'SGD')
```
1. 适合
**1.** 安装
<!-- -->
See the `Fitting` section in the [stochasticLinearRegression](#stochasticlinearregression-usage-fitting) description.
参考stochasticLinearRegression相关文档
Predicted labels have to be in \[-1, 1\].
预测标签的取值范围为[-1, 1]
1. 预测
**2.** 预测
<!-- -->
Using saved state we can predict probability of object having label `1`.
使用已经保存的state我们可以预测标签为 `1` 的对象的概率。
``` sql
WITH (SELECT state FROM your_model) AS model SELECT
evalMLMethod(model, param1, param2) FROM test_data
```
The query will return a column of probabilities. Note that first argument of `evalMLMethod` is `AggregateFunctionState` object, next are columns of features.
查询结果返回一个列的概率。注意 `evalMLMethod` 的第一个参数是 `AggregateFunctionState` 对象,接下来的参数是列的特性。
We can also set a bound of probability, which assigns elements to different labels.
我们也可以设置概率的范围, 这样需要给元素指定不同的标签。
``` sql
SELECT ans < 1.1 AND ans > 0.5 FROM
@ -1836,14 +1834,14 @@ stochasticLogisticRegression(1.0, 1.0, 10, 'SGD')
evalMLMethod(model, param1, param2) AS ans FROM test_data)
```
Then the result will be labels.
结果是标签。
`test_data` is a table like `train_data` but may not contain target value.
`test_data` 是一个像 `train_data` 一样的表,但是不包含目标值。
**另请参阅**
- [随机指标线上回归](#agg_functions-stochasticlinearregression)
- [线性回归和逻辑回归之间的差异](https://stackoverflow.com/questions/12146914/what-is-the-difference-between-linear-regression-and-logistic-regression)
- [线性回归和逻辑回归之间的差异](https://stackoverflow.com/questions/12146914/what-is-the-difference-between-linear-regression-and-logistic-regression)
## groupBitmapAnd {#groupbitmapand}