メインコンテンツまでスキップ
バージョン: 26.x

COLLECT_SET

デスクリプション

Aggregation関数は、指定されたカラムのすべての一意な値を集約し、重複する要素を削除して、set型の結果を返します。

Alias

  • GROUP_UNIQ_ARRAY

Syntax

COLLECT_SET(<expr> [,<max_size>])

パラメータ

Parameterデスクリプション
<expr>配列に配置される値を決定する式。サポートされる型: Bool, TinyInt, SmallInt, Integer, BigInt, LargeInt, Float, Double, Decimal, Date, Datetime, IPV4, IPV6, String, Array, Map, Struct。
<max_size>結果配列のサイズをmax_size要素に制限するオプションパラメータ。サポートされる型: Integer。

Return Value

ARRAY型を返し、重複除去後のすべての非NULL値を含みます。グループ内に有効なデータがない場合、空の配列を返します。

Example

-- setup
CREATE TABLE collect_set_test (
k1 INT,
k2 INT,
k3 STRING
) DISTRIBUTED BY HASH(k1) BUCKETS 1
PROPERTIES ("replication_num" = "1");
INSERT INTO collect_set_test VALUES (1, 10, 'a'), (1, 20, 'b'), (1, 10, 'a'), (2, 100, 'x'), (2, 200, 'y'), (3, NULL, NULL);
select collect_set(k1),collect_set(k1,2) from collect_set_test;
+-----------------+-------------------+
| collect_set(k1) | collect_set(k1,2) |
+-----------------+-------------------+
| [2, 1, 3] | [2, 1] |
+-----------------+-------------------+
select k1,collect_set(k2),collect_set(k3,1) from collect_set_test group by k1 order by k1;
+------+-----------------+-------------------+
| k1 | collect_set(k2) | collect_set(k3,1) |
+------+-----------------+-------------------+
| 1 | [20, 10] | ["a"] |
| 2 | [200, 100] | ["x"] |
| 3 | [] | [] |
+------+-----------------+-------------------+