ClickHouse/docs/ja/sql_reference/data_types/aggregatefunction.md
2020-04-04 12:15:31 +03:00

3.2 KiB

machine_translated machine_translated_rev toc_priority toc_title
true d734a8e46d 52 AggregateFunction(name,types_of_arguments)...)

AggregateFunction(name, types_of_arguments…)

Aggregate functions can have an implementation-defined intermediate state that can be serialized to an AggregateFunction(…) data type and stored in a table, usually, by means of マテリアライズドビュー. 集計関数の状態を生成する一般的な方法は、集計関数を呼び出すことです -State 接尾辞。 将来の集約の最終結果を得るには、同じ集計関数を使用する必要があります -Merge接尾辞。

AggregateFunction — parametric data type.

パラメータ

  • 集計関数の名前。

    If the function is parametric, specify its parameters too.
    
  • 集計関数の引数の型です。

例えば

CREATE TABLE t
(
    column1 AggregateFunction(uniq, UInt64),
    column2 AggregateFunction(anyIf, String, UInt8),
    column3 AggregateFunction(quantiles(0.5, 0.9), UInt64)
) ENGINE = ...

uniq,アーニフ (任意の+もし)と 分位数 ClickHouseでサポートされている集計関数です。

使い方

データ挿入

データを挿入するには INSERT SELECT 総計を使って -State-機能。

関数の例

uniqState(UserID)
quantilesState(0.5, 0.9)(SendTiming)

対応する機能とは対照的に uniqquantiles, -State-関数は、最終的な値の代わりに状態を返します。 言い換えれば、それらは次の値を返します AggregateFunction タイプ。

の結果で SELECT クエリ、値の AggregateFunction タイプは、すべてのClickHouse出力形式に対して実装固有のバイナリ表現を持ちます。 たとえば、データをダンプする場合, TabSeparated フォーマット SELECT このダンプは、次のようにロードされます INSERT クエリ。

データ選択

データを選択するとき AggregatingMergeTree テーブル、使用 GROUP BY 句とデータを挿入するときと同じ集約関数が、 -Merge接尾辞。

以下の集計関数 -Merge suffixは、状態のセットを取得し、それらを結合し、完全なデータ集約の結果を返します。

たとえば、次の二つのクエリは同じ結果を返します:

SELECT uniq(UserID) FROM table

SELECT uniqMerge(state) FROM (SELECT uniqState(UserID) AS state FROM table GROUP BY RegionID)

使用例

見る ツつィツ姪"ツつ"ツ債ツづュツつケ エンジンの説明。

元の記事