배열 원소 축약
| 항목 | 값 |
|---|---|
| 화면 이름 | Reduce array elements |
| 식별자 | reduceArrayElementsV1 |
| 지원 실행 방식 | Batch, Streaming |
| 범주 | 배열 (Array) |
| 반환 자료형 | T |
표현식을 사용해 배열 원소들을 축약합니다.
입력 인자
| 이름 | 지정 여부 | 자료형 | 의미와 조건 |
|---|---|---|---|
Array | 필수 | Expression<Array<Array<Boolean | Byte | Date | Double | Float | Integer | Long | Map<AnyType, AnyType> | Short | String | Timestamp> | Boolean | Byte | Date | Double | Float | Integer | Long | Map<AnyType, AnyType> | Short | String | Timestamp>> | 축약할 배열입니다. |
Expression to reduce | 필수 | Expression<T> | 배열의 각 원소에 한 번씩 적용할 표현식입니다. |
Initial value | 필수 | Expression<T> | 누산기를 초기화할 시작값입니다. 배열 길이가 0이면 이 값을 반환합니다. |
자료형 변수의 범위
T는Array<Boolean | Byte | Date | Double | Float | Integer | Long | Map<AnyType, AnyType> | Short | String | Timestamp> | Boolean | Byte | Date | Double | Float | Integer | Long | Map<AnyType, AnyType> | Short | String | Timestamp범위의 자료형을 받습니다.
입출력 예시
예시 1: 기본 동작
인자 값:
Array:milesExpression to reduce:
add(
expressions: [accumulator,element],
)Initial value: 0
| miles | 출력 |
|---|---|
| [ 12300, 12342 ] | 24642 |
예시 2: 기본 동작
배열에서 처음으로 null이 아닌 값을 반환합니다.
인자 값:
Array:milesExpression to reduce:
firstNonNull(
expressions: [accumulator,element],
)Initial value:init
| miles | init | 출력 |
|---|---|---|
| [ null, null, 12300, 12111 ] | null | 12300 |
예시 3: 기본 동작
인자 값:
Array:milesExpression to reduce:
concatStrings(
expressions: [accumulator,
cast(
expression:element,
type: String,
)],
separator: -,
)Initial value: empty string
| miles | 출력 |
|---|---|
| [ 12300, 12342 ] | -12300-12342 |
예시 4: null 처리
null 배열은 null을 반환합니다.
인자 값:
Array:milesExpression to reduce:
firstNonNull(
expressions: [accumulator,element],
)Initial value:init
| miles | init | 출력 |
|---|---|---|
| null | null | null |
예시 5: 경계 조건
빈 배열은 초기값을 반환합니다.
인자 값:
Array:milesExpression to reduce:
add(
expressions: [accumulator,element],
)Initial value: 0
| miles | 출력 |
|---|---|
| [ ] | 0 |