WIP update-aggregate-funcions-in-zh

This commit is contained in:
benbiti 2021-02-04 23:34:04 +08:00
parent af0930f62a
commit a6e9d9200b
3 changed files with 33 additions and 100 deletions

View File

@ -527,79 +527,6 @@ uniqExact(x[, ...])
- [uniqHLL12](#agg_function-uniqhll12) - [uniqHLL12](#agg_function-uniqhll12)
## groupArrayMovingSum {#agg_function-grouparraymovingsum}
计算输入值的移动和。
``` sql
groupArrayMovingSum(numbers_for_summing)
groupArrayMovingSum(window_size)(numbers_for_summing)
```
该函数可以将窗口大小作为参数。 如果未指定,则该函数的窗口大小等于列中的行数。
**参数**
- `numbers_for_summing` — [表达式](../syntax.md#syntax-expressions) 为数值数据类型值。
- `window_size` — 窗口大小。
**返回值**
- 与输入数据大小和类型相同的数组。
**示例**
样品表:
``` sql
CREATE TABLE t
(
`int` UInt8,
`float` Float32,
`dec` Decimal32(2)
)
ENGINE = TinyLog
```
``` text
┌─int─┬─float─┬──dec─┐
│ 1 │ 1.1 │ 1.10 │
│ 2 │ 2.2 │ 2.20 │
│ 4 │ 4.4 │ 4.40 │
│ 7 │ 7.77 │ 7.77 │
└─────┴───────┴──────┘
```
查询:
``` sql
SELECT
groupArrayMovingSum(int) AS I,
groupArrayMovingSum(float) AS F,
groupArrayMovingSum(dec) AS D
FROM t
```
``` text
┌─I──────────┬─F───────────────────────────────┬─D──────────────────────┐
│ [1,3,7,14] │ [1.1,3.3000002,7.7000003,15.47] │ [1.10,3.30,7.70,15.47] │
└────────────┴─────────────────────────────────┴────────────────────────┘
```
``` sql
SELECT
groupArrayMovingSum(2)(int) AS I,
groupArrayMovingSum(2)(float) AS F,
groupArrayMovingSum(2)(dec) AS D
FROM t
```
``` text
┌─I──────────┬─F───────────────────────────────┬─D──────────────────────┐
│ [1,3,6,11] │ [1.1,3.3000002,6.6000004,12.17] │ [1.10,3.30,6.60,12.17] │
└────────────┴─────────────────────────────────┴────────────────────────┘
```
## groupUniqArray(x), groupUniqArray(max_size)(x) {#groupuniqarrayx-groupuniqarraymax-sizex} ## groupUniqArray(x), groupUniqArray(max_size)(x) {#groupuniqarrayx-groupuniqarraymax-sizex}
从不同的参数值创建一个数组。 内存消耗是一样的 `uniqExact` 功能。 从不同的参数值创建一个数组。 内存消耗是一样的 `uniqExact` 功能。

View File

@ -4,27 +4,32 @@ toc_priority: 113
# groupArrayMovingSum {#agg_function-grouparraymovingsum} # groupArrayMovingSum {#agg_function-grouparraymovingsum}
Calculates the moving sum of input values.
计算输入值的移动和。
**语法**
``` sql ``` sql
groupArrayMovingSum(numbers_for_summing) groupArrayMovingSum(numbers_for_summing)
groupArrayMovingSum(window_size)(numbers_for_summing) groupArrayMovingSum(window_size)(numbers_for_summing)
``` ```
The function can take the window size as a parameter. If left unspecified, the function takes the window size equal to the number of rows in the column. 该函数可以将窗口大小作为参数。 如果未指定,则该函数的窗口大小等于列中的行数。
**Parameters** **参数**
- `numbers_for_summing` — [Expression](../../../sql-reference/syntax.md#syntax-expressions) resulting in a numeric data type value. - `numbers_for_summing` — [表达式](../../../sql-reference/syntax.md#syntax-expressions) 生成数值数据类型值。。
- `window_size`Size of the calculation window. - `window_size`窗口大小。
**Returned values** **返回值**
- Array of the same size and type as the input data. - 与输入数据大小相同的数组。
对于输入数据类型是[Decimal](../../../sql-reference/data-types/decimal.md) 数组元素类型是 `Decimal128`
对于其他的数值类型, 获取其对应的 `NearestFieldType`
**Example** **示例**
The sample table: 样表:
``` sql ``` sql
CREATE TABLE t CREATE TABLE t
@ -45,7 +50,7 @@ ENGINE = TinyLog
└─────┴───────┴──────┘ └─────┴───────┴──────┘
``` ```
The queries: 查询:
``` sql ``` sql
SELECT SELECT

View File

@ -4,29 +4,30 @@ toc_priority: 114
# groupArraySample {#grouparraysample} # groupArraySample {#grouparraysample}
Creates an array of sample argument values. The size of the resulting array is limited to `max_size` elements. Argument values are selected and added to the array randomly. 构建一个参数值的采样数组。
结果数组的大小限制为 `max_size` 个元素。参数值被随机选择并添加到数组中。
**Syntax** **语法**
``` sql ``` sql
groupArraySample(max_size[, seed])(x) groupArraySample(max_size[, seed])(x)
``` ```
**Parameters** **参数**
- `max_size`Maximum size of the resulting array. [UInt64](../../data-types/int-uint.md). - `max_size`结果数组的最大长度. [UInt64](../../data-types/int-uint.md)。
- `seed`Seed for the random number generator. Optional. [UInt64](../../data-types/int-uint.md). Default value: `123456`. - `seed`随机数发生器的种子. 可选。 [UInt64](../../data-types/int-uint.md)。 默认值: `123456`
- `x`Argument (column name or expression). - `x`参数 (列名 或者 表达式).
**Returned values** **返回值**
- Array of randomly selected `x` arguments. - 随机选取参数 `x` (的值)组成的数组。
Type: [Array](../../data-types/array.md). 类型: [Array](../../../data-types/array.md).
**Examples** **示例**
Consider table `colors`: 样表 `colors`:
``` text ``` text
┌─id─┬─color──┐ ┌─id─┬─color──┐
@ -38,13 +39,13 @@ Consider table `colors`:
└────┴────────┘ └────┴────────┘
``` ```
Query with column name as argument: 使用列名做参数查询:
``` sql ``` sql
SELECT groupArraySample(3)(color) as newcolors FROM colors; SELECT groupArraySample(3)(color) as newcolors FROM colors;
``` ```
Result: 结果:
```text ```text
┌─newcolors──────────────────┐ ┌─newcolors──────────────────┐
@ -52,13 +53,13 @@ Result:
└────────────────────────────┘ └────────────────────────────┘
``` ```
Query with column name and different seed: 使用列名和不同的(随机数)种子查询:
``` sql ``` sql
SELECT groupArraySample(3, 987654321)(color) as newcolors FROM colors; SELECT groupArraySample(3, 987654321)(color) as newcolors FROM colors;
``` ```
Result: 结果:
```text ```text
┌─newcolors──────────────────┐ ┌─newcolors──────────────────┐
@ -66,13 +67,13 @@ Result:
└────────────────────────────┘ └────────────────────────────┘
``` ```
Query with expression as argument: 使用表达式做参数查询:
``` sql ``` sql
SELECT groupArraySample(3)(concat('light-', color)) as newcolors FROM colors; SELECT groupArraySample(3)(concat('light-', color)) as newcolors FROM colors;
``` ```
Result: 结果:
```text ```text
┌─newcolors───────────────────────────────────┐ ┌─newcolors───────────────────────────────────┐