Apache-tajo-aggregate-and-window-functions

提供:Dev Guides
移動先:案内検索

集計およびウィンドウ関数

この章では、集計関数とウィンドウ関数について詳しく説明します。

集計関数

集計関数は、一連の入力値から単一の結果を生成します。 次の表は、集計関数のリストを詳細に説明しています。

S.No. Function & Description
1

AVG(exp)

データソース内のすべてのレコードの列を平均します。

2

CORR(expression1, expression2)

数値ペアのセット間の相関係数を返します。

3

COUNT()

行数を返します。

4

MAX(expression)

選択した列の最大値を返します。

5

MIN(expression)

選択した列の最小値を返します。

6

SUM(expression)

指定された列の合計を返します。

7

LAST_VALUE(expression)

指定された列の最後の値を返します。

ウィンドウ機能

ウィンドウ関数は一連の行で実行され、クエリから各行に単一の値を返します。 ウィンドウという用語には、関数の行のセットという意味があります。

クエリのWindow関数は、OVER()句を使用してウィンドウを定義します。

  • OVER()*句には次の機能があります-
  • 行のグループを形成するウィンドウパーティションを定義します。 (PARTITION BY句)
  • パーティション内の行を並べ替えます。 (ORDER BY句)

次の表に、ウィンドウ関数の詳細を示します。

Function Return type Description
rank() int Returns rank of the current row with gaps.
row_num() int Returns the current row within its partition, counting from 1.
lead(value[, offset integer[, default any])] Same as input type Returns value evaluated at the row that is offset rows after the current row within the partition. If there is no such row, default value will be returned.
lag(value[, offset integer[, default any])] Same as input type Returns value evaluated at the row that is offset rows before the current row within the partition.
first_value(value) Same as input type Returns the first value of input rows.
last_value(value) Same as input type Returns the last value of input rows.