Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOCSUP-1954 initialize aggregation description #16793

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
toc_priority: 150
---

## initializeAggregation {#initializeaggregation}

Initializes aggregation for your input rows. It is intended for the functions with the suffix `State`.
Use it for tests or to process columns of types `AggregateFunction` and `AggregationgMergeTree`.

**Syntax**

``` sql
initializeAggregation (aggregate_function, column_1, column_2);
```

**Parameters**

- `aggregate_function` — Name of the aggregation function. The state of this function — the creating one. [String](../../../sql-reference/data-types/string.md#string).
- `column_n` — The column to translate it into the function as it's argument. [String](../../../sql-reference/data-types/string.md#string).

**Returned value(s)**

Returns the result of the aggregation for your input rows. The return type will be the same as the return type of function, that `initializeAgregation` takes as first argument.
For example for functions with the suffix `State` the return type will be `AggregateFunction`.

**Example**

Query:

```sql
SELECT uniqMerge(state) FROM (SELECT initializeAggregation('uniqState', number % 3) AS state FROM system.numbers LIMIT 10000);
```
Result:

┌─uniqMerge(state)─┐
│ 3 │
└──────────────────┘
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
toc_priority: 150
---

## initializeAggregation {#initializeaggregation}

Инициализирует агрегацию для введеных строчек. Предназначена для функций с суффиксом `State`.
Поможет вам проводить тесты или работать со столбцами типов: `AggregateFunction` и `AggregationgMergeTree`.

**Синтаксис**

``` sql
initializeAggregation (aggregate_function, column_1, column_2);
```

**Параметры**

- `aggregate_function` — название функции агрегации, состояние которой нужно создать. [String](../../../sql-reference/data-types/string.md#string).
- `column_n` — столбец, который передается в функцию агрегации как аргумент. [String](../../../sql-reference/data-types/string.md#string).

**Возвращаемое значение**

Возвращает результат агрегации введенной информации. Тип возвращаемого значения такой же, как и для функции, которая становится первым аргументом для `initializeAgregation`.

Пример:

Возвращаемый тип функций с суффиксом `State` — `AggregateFunction`.

**Пример**

Запрос:

```sql
SELECT uniqMerge(state) FROM (SELECT initializeAggregation('uniqState', number % 3) AS state FROM system.numbers LIMIT 10000);
```
Результат:

┌─uniqMerge(state)─┐
│ 3 │
└──────────────────┘