카테고리:

집계 함수 (Counting Distinct Values) , Window functions (Semi-structured Data Aggregation)

ARRAY_UNION_AGG

Returns an ARRAY that contains the union of the distinct values from the input arrays in a column. You can use this to aggregate distinct values in arrays produced by ARRAY_UNIQUE_AGG.

참고 항목:

ARRAY_UNIQUE_AGG , 배열을 사용하여 계층적 집계에 대한 고유 값 계산하기

구문

Aggregate function

ARRAY_UNION_AGG( <column> )
Copy

Window function

ARRAY_UNION_AGG( <column> ) OVER ( [ PARTITION BY <expr> ] )
Copy

For details about the OVER clause, see 윈도우 함수 구문 및 사용법.

인자

column

The column containing the arrays with the distinct values (the arrays produced by ARRAY_UNIQUE_AGG).

반환

The function returns an array containing the distinct values from the arrays in column. The values in the array are in no particular order, and the order is not deterministic.

Note that this function uses multiset semantics, which means that the maximum number of occurrences of an individual value in a single input array determines the number of occurrences of that value in the output array. See Examples.

The function ignores NULL values in column and in the arrays in column. If column contains only NULL values or the table containing column is empty, the function returns an empty array.

사용법 노트

  • 이 함수는 다음 유형의 함수 중 하나로 사용할 수 있습니다.

  • 이 함수가 윈도우 함수로 호출되는 경우에는 명시적 윈도우 프레임을 지원하지 않습니다.

  • 정형 배열 을 함수에 전달하면 함수는 동일한 유형의 정형 배열을 반환합니다.

집계: 배열의 합집합

The following example illustrates how the function returns the union of distinct values from two arrays:

CREATE TABLE union_test(a array);

INSERT INTO union_test
    SELECT PARSE_JSON('[ 1, 1, 2]')
    UNION ALL
    SELECT PARSE_JSON('[ 1, 2, 3]');

SELECT ARRAY_UNION_AGG(a) FROM union_test;
+-------------------------+
| ARRAY_UNION_AGG(A)      |
+-------------------------+
| [ 1, 1, 2, 3]           |
+-------------------------+
Copy

이 작업에서는 멀티세트 의미 체계를 사용합니다. 값 1 은 입력 배열 중 하나에서 두 번 나타나므로 출력에 두 번 나타납니다.

배열을 사용하여 계층적 집계에 대한 고유 값 계산하기 섹션을 참조하십시오.