배열 함수 참조
배열 함수
| 이름 | 설명 |
ARRAY
|
각 입력 인수에 대해 하나의 요소를 포함하는 ARRAY를 반환합니다.
|
ARRAY_CONCAT
|
여러 배열을 단일 ARRAY로 연결합니다.
|
ARRAY_CONTAINS
|
지정된 ARRAY에 특정 값이 포함되어 있으면 TRUE를 반환합니다.
|
ARRAY_CONTAINS_ALL
|
모든 값이 ARRAY에 있으면 TRUE를 반환합니다.
|
ARRAY_CONTAINS_ANY
|
ARRAY에 값이 있으면 TRUE를 반환합니다.
|
ARRAY_FILTER
|
조건자를 충족하지 않는 ARRAY의 요소를 필터링합니다.
|
ARRAY_FIRST
|
ARRAY의 첫 번째 요소를 반환합니다.
|
ARRAY_FIRST_N
|
ARRAY의 첫 번째 n 요소를 반환합니다.
|
ARRAY_GET
|
ARRAY에서 지정된 색인의 요소를 반환합니다.
|
ARRAY_INDEX_OF
|
ARRAY에서 값이 처음으로 나타나는 색인을 반환합니다.
|
ARRAY_INDEX_OF_ALL
|
ARRAY에서 값의 모든 색인을 반환합니다.
|
ARRAY_LENGTH
|
ARRAY의 요소 수를 반환합니다.
|
ARRAY_LAST
|
ARRAY의 마지막 요소를 반환합니다.
|
ARRAY_LAST_N
|
ARRAY의 마지막 n 요소를 반환합니다.
|
ARRAY_REVERSE
|
ARRAY의 요소 순서를 반대로 합니다.
|
ARRAY_SLICE
|
ARRAY의 슬라이스를 반환합니다.
|
ARRAY_TRANSFORM
|
각 요소에 표현식을 적용하여 ARRAY의 요소를 변환합니다.
|
MAXIMUM
|
ARRAY의 최댓값을 반환합니다.
|
MAXIMUM_N
|
ARRAY에서 n번째로 큰 값을 반환합니다.
|
MINIMUM
|
ARRAY의 최솟값을 반환합니다.
|
MINIMUM_N
|
ARRAY에서 n번째로 작은 값을 반환합니다.
|
SUM
|
ARRAY에 있는 모든 NUMERIC 값의 합계를 반환합니다.
|
JOIN
|
ARRAY에 있는 요소의 연결을 STRING 값으로 생성합니다.
|
ARRAY
구문:
array(values: ANY...) -> ARRAY
설명:
지정된 요소에서 배열을 구성합니다.
- 인수가 없으면 결과 배열에서
NULL로 대체됩니다.
예:
| 값 | array(values) |
|---|---|
| () | [] |
| (1, 2, 3) | [1, 2, 3] |
| ("a", 1, true) | ["a", 1, true] |
| (1, null) | [1, null] |
| (1, [2, 3]) | [1, [2, 3]] |
ARRAY_CONCAT
구문:
array_concat(arrays: ARRAY...) -> ARRAY
설명:
두 개 이상의 배열을 하나의 ARRAY로 연결합니다.
예:
| arrays | array_concat(arrays) |
|---|---|
| ([1, 2], [3, 4]) | [1, 2, 3, 4] |
| (["a", "b"], ["c"]) | ["a", "b", "c"] |
| ([1], [2], [3]) | [1, 2, 3] |
| ([], [1, 2]) | [1, 2] |
Node.js
const result = await db.pipeline() .collection("books") .select(field("genre").arrayConcat([field("subGenre")]).as("allGenres")) .execute();
Swift
let result = try await db.pipeline() .collection("books") .select([Field("genre").arrayConcat([Field("subGenre")]).as("allGenres")]) .execute()
Kotlin
Android
val result = db.pipeline() .collection("books") .select(field("genre").arrayConcat(field("subGenre")).alias("allGenres")) .execute()
자바
Android
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select(field("genre").arrayConcat(field("subGenre")).alias("allGenres")) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select(Field.of("genre").array_concat(Field.of("subGenre")).as_("allGenres")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(arrayConcat(field("genre"), field("subGenre")).as("allGenres")) .execute() .get();
ARRAY_CONTAINS
구문:
array_contains(array: ARRAY, value: ANY) -> BOOLEAN
설명:
value가 array에 있으면 TRUE를 반환하고, 그렇지 않으면 FALSE를 반환합니다.
예:
| 배열 | 값 | array_contains(array, value) |
|---|---|---|
| [1, 2, 3] | 2 | 참 |
| [[1, 2], [3]] | [1, 2] | 참 |
| [1, null] | null | 참 |
| "abc" | 모두 | 오류 |
Node.js
const result = await db.pipeline() .collection("books") .select(field("genre").arrayContains(constant("mystery")).as("isMystery")) .execute();
웹
const result = await execute(db.pipeline() .collection("books") .select(field("genre").arrayContains(constant("mystery")).as("isMystery")) );
Swift
let result = try await db.pipeline() .collection("books") .select([Field("genre").arrayContains(Constant("mystery")).as("isMystery")]) .execute()
Kotlin
Android
val result = db.pipeline() .collection("books") .select(field("genre").arrayContains("mystery").alias("isMystery")) .execute()
자바
Android
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select(field("genre").arrayContains("mystery").alias("isMystery")) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select(Field.of("genre").array_contains("mystery").as_("isMystery")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(arrayContains(field("genre"), "mystery").as("isMystery")) .execute() .get();
ARRAY_CONTAINS_ALL
구문:
array_contains_all(array: ARRAY, search_values: ARRAY) -> BOOLEAN
설명:
모든 search_values가 array에 있으면 TRUE를 반환하고 그렇지 않으면 FALSE를 반환합니다.
예:
| 배열 | search_values | array_contains_all(array, search_values) |
|---|---|---|
| [1, 2, 3] | [1, 2] | 참 |
| [1, 2, 3] | [1, 4] | 거짓 |
| [1, null] | [null] | 참 |
| [NaN] | [NaN] | 참 |
| [] | [] | 참 |
| [1, 2, 3] | [] | 참 |
Node.js
const result = await db.pipeline() .collection("books") .select( field("genre") .arrayContainsAll([constant("fantasy"), constant("adventure")]) .as("isFantasyAdventure") ) .execute();
웹
const result = await execute(db.pipeline() .collection("books") .select( field("genre") .arrayContainsAll([constant("fantasy"), constant("adventure")]) .as("isFantasyAdventure") ) );
Swift
let result = try await db.pipeline() .collection("books") .select([ Field("genre") .arrayContainsAll([Constant("fantasy"), Constant("adventure")]) .as("isFantasyAdventure") ]) .execute()
Kotlin
Android
val result = db.pipeline() .collection("books") .select( field("genre") .arrayContainsAll(listOf("fantasy", "adventure")) .alias("isFantasyAdventure") ) .execute()
자바
Android
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( field("genre") .arrayContainsAll(Arrays.asList("fantasy", "adventure")) .alias("isFantasyAdventure") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select( Field.of("genre") .array_contains_all(["fantasy", "adventure"]) .as_("isFantasyAdventure") ) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select( arrayContainsAll(field("genre"), Arrays.asList("fantasy", "adventure")) .as("isFantasyAdventure")) .execute() .get();
ARRAY_CONTAINS_ANY
구문:
array_contains_any(array: ARRAY, search_values: ARRAY) -> BOOLEAN
설명:
search_values 중 하나라도 array에 있으면 TRUE를 반환하고, 그렇지 않으면 FALSE를 반환합니다.
예:
| 배열 | search_values | array_contains_any(array, search_values) |
|---|---|---|
| [1, 2, 3] | [4, 1] | 참 |
| [1, 2, 3] | [4, 5] | 거짓 |
| [1, 2, null] | [null] | 참 |
Node.js
const result = await db.pipeline() .collection("books") .select( field("genre") .arrayContainsAny([constant("fantasy"), constant("nonfiction")]) .as("isMysteryOrFantasy") ) .execute();
웹
const result = await execute(db.pipeline() .collection("books") .select( field("genre") .arrayContainsAny([constant("fantasy"), constant("nonfiction")]) .as("isMysteryOrFantasy") ) );
Swift
let result = try await db.pipeline() .collection("books") .select([ Field("genre") .arrayContainsAny([Constant("fantasy"), Constant("nonfiction")]) .as("isMysteryOrFantasy") ]) .execute()
Kotlin
Android
val result = db.pipeline() .collection("books") .select( field("genre") .arrayContainsAny(listOf("fantasy", "nonfiction")) .alias("isMysteryOrFantasy") ) .execute()
자바
Android
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( field("genre") .arrayContainsAny(Arrays.asList("fantasy", "nonfiction")) .alias("isMysteryOrFantasy") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select( Field.of("genre") .array_contains_any(["fantasy", "nonfiction"]) .as_("isMysteryOrFantasy") ) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select( arrayContainsAny(field("genre"), Arrays.asList("fantasy", "nonfiction")) .as("isMysteryOrFantasy")) .execute() .get();
ARRAY_FILTER
구문:
array_filter(array: ARRAY, predicate: (ANY) -> BOOLEAN) -> ARRAY
설명:
predicate 표현식을 사용하여 array를 필터링하고 조건자를 충족하는 요소만 있는 새 배열을 반환합니다.
array의 각 요소에 대해predicate가 평가됩니다.true를 반환하면 요소가 결과에 포함되고, 그렇지 않으면(false또는null을 반환하는 경우) 생략됩니다.predicate가 불리언이 아닌 값 또는 null이 아닌 값으로 평가되면 함수는 오류를 반환합니다.
예:
| 배열 | predicate | array_filter(array, predicate) |
|---|---|---|
| [1, 2, 3] | x -> x > 1 | [2, 3] |
| [1, null, 3] | x -> x > 1 | [3] |
| ["a", "b", "c"] | x -> x != "b" | ["a", "c"] |
| [] | x -> true | [] |
ARRAY_GET
구문:
array_get(array: ARRAY, index: INT64) -> ANY
설명:
array에서 0부터 시작하는 index의 요소를 반환합니다.
index가 음수이면 배열의 끝에서 요소에 액세스하며-1이 마지막 요소입니다.array가ARRAY유형이 아니고null도 아니면 오류를 반환합니다.index가 범위를 벗어나면 함수는 누락된 값을 반환합니다.index가INT64유형이 아니면 함수는 오류를 반환합니다.
예:
| 배열 | 색인 | array_get(array, index) |
|---|---|---|
| [1, 2, 3] | 0 | 1 |
| [1, 2, 3] | -1 | 3 |
| [1, 2, 3] | 3 | 없음 |
| [1, 2, 3] | -4 | 없음 |
| "abc" | 0 | 오류 |
| null | 0 | null |
Array |
"a" | 오류 |
Array |
2.0 | 오류 |
ARRAY_LENGTH
구문:
array_length(array: ARRAY) -> INT64
설명:
array의 요소 수를 반환합니다.
예:
| 배열 | array_length(array) |
|---|---|
| [1, 2, 3] | 3 |
| [] | 0 |
| [1, 1, 1] | 3 |
| [1, null] | 2 |
Node.js
const result = await db.pipeline() .collection("books") .select(field("genre").arrayLength().as("genreCount")) .execute();
웹
const result = await execute(db.pipeline() .collection("books") .select(field("genre").arrayLength().as("genreCount")) );
Swift
let result = try await db.pipeline() .collection("books") .select([Field("genre").arrayLength().as("genreCount")]) .execute()
Kotlin
Android
val result = db.pipeline() .collection("books") .select(field("genre").arrayLength().alias("genreCount")) .execute()
자바
Android
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select(field("genre").arrayLength().alias("genreCount")) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select(Field.of("genre").array_length().as_("genreCount")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(arrayLength(field("genre")).as("genreCount")) .execute() .get();
ARRAY_REVERSE
구문:
array_reverse(array: ARRAY) -> ARRAY
설명:
지정된 array를 반대로 합니다.
예:
| 배열 | array_reverse(array) |
|---|---|
| [1, 2, 3] | [3, 2, 1] |
| ["a", "b"] | ["b", "a"] |
| [1, 2, 2, 3] | [3, 2, 2, 1] |
Node.js
const result = await db.pipeline() .collection("books") .select(arrayReverse(field("genre")).as("reversedGenres")) .execute();
웹
const result = await execute(db.pipeline() .collection("books") .select(field("genre").arrayReverse().as("reversedGenres")) );
Swift
let result = try await db.pipeline() .collection("books") .select([Field("genre").arrayReverse().as("reversedGenres")]) .execute()
Kotlin
Android
val result = db.pipeline() .collection("books") .select(field("genre").arrayReverse().alias("reversedGenres")) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select(field("genre").arrayReverse().alias("reversedGenres")) .execute();
Android
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select(Field.of("genre").array_reverse().as_("reversedGenres")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(arrayReverse(field("genre")).as("reversedGenres")) .execute() .get();
ARRAY_FIRST
구문:
array_first(array: ARRAY) -> ANY
설명:
array의 첫 번째 요소를 반환합니다. array_get(array, 0)과 동일합니다.
array가 비어 있으면 누락된 값을 반환합니다.
예:
| 배열 | array_first(array) |
|---|---|
| [1, 2, 3] | 1 |
| [] | 없음 |
ARRAY_FIRST_N
구문:
array_first_n(array: ARRAY, n: INT64) -> ARRAY
설명:
array의 첫 번째 n 요소를 반환합니다. array_slice(array, 0, n)와 동일합니다.
n이 음수이면 오류를 반환합니다.
예:
| 배열 | n | array_first_n(array, n) |
|---|---|---|
| [1, 2, 3, 4, 5] | 3 | [1, 2, 3] |
| [1, 2] | 3 | [1, 2] |
| [1, 2, 3] | 0 | [] |
ARRAY_INDEX_OF
구문:
array_index_of(array: ARRAY, value: ANY) -> INT64
설명:
array에서 value가 처음으로 나타나는 위치의 0부터 시작하는 색인을 반환합니다. value를 찾을 수 없으면 -1을 반환합니다.
예:
| 배열 | 값 | array_index_of(array, value) |
|---|---|---|
| [1, 2, 3, 2] | 2 | 1 |
| [1, 2, 3] | 4 | -1 |
| [1, null, 3] | null | 1 |
ARRAY_INDEX_OF_ALL
구문:
array_index_of_all(array: ARRAY, value: ANY) -> ARRAY<INT64>
설명:
array에서 value가 발생하는 모든 위치의 0부터 시작하는 색인이 포함된 배열을 반환합니다. value을 찾을 수 없으면 []을 반환합니다.
예:
| 배열 | 값 | array_index_of_all(array, value) |
|---|---|---|
| [1, 2, 3, 2] | 2 | [1, 3] |
| [1, 2, 3] | 4 | [] |
| [1, null, 3, null] | null | [1, 3] |
ARRAY_LAST
구문:
array_last(array: ARRAY) -> ANY
설명:
array의 마지막 요소를 반환합니다. array_get(array, -1)과 동일합니다.
array가 비어 있으면 누락된 값을 반환합니다.
예:
| 배열 | array_last(array) |
|---|---|
| [1, 2, 3] | 3 |
| [] | 없음 |
ARRAY_LAST_N
구문:
array_last_n(array: ARRAY, n: INT64) -> ARRAY
설명:
array의 마지막 n 요소를 반환합니다.
n이 음수이면 오류를 반환합니다.
예:
| 배열 | n | array_last_n(array, n) |
|---|---|---|
| [1, 2, 3, 4, 5] | 3 | [3, 4, 5] |
| [1, 2] | 3 | [1, 2] |
| [1, 2, 3] | 0 | [] |
ARRAY_SLICE
구문:
array_slice(array: ARRAY, offset: INT64, length: INT64) -> ARRAY
설명:
0부터 시작하는 색인 offset에서 시작하여 length 요소를 포함하는 array의 하위 집합을 반환합니다.
offset이 음수이면 배열의 끝에서 시작 위치를 나타내며-1이 마지막 요소입니다.length가offset이후 배열에 남아 있는 요소 수보다 크면 결과가 배열의 끝까지 확장됩니다.length는 음수가 아니어야 합니다. 그렇지 않으면 오류가 반환됩니다.
예:
| 배열 | offset | 길이 | array_slice(array, offset, length) |
|---|---|---|---|
| [1, 2, 3, 4, 5] | 1 | 3 | [2, 3, 4] |
| [1, 2, 3, 4, 5] | -2 | 2 | [4, 5] |
| [1, 2, 3] | 1 | 5 | [2, 3] |
| [1, 2, 3] | 3 | 2 | [] |
ARRAY_TRANSFORM
구문:
array_transform(array: ARRAY, expression: (ANY) -> ANY) -> ARRAY
array_transform(array: ARRAY, expression: (ANY, INT64) -> ANY) -> ARRAY
설명:
각 요소에 expression을 적용하여 array를 변환하고 변환된 요소가 포함된 새 배열을 반환합니다. 출력 배열의 크기는 항상 입력 배열과 같습니다
expression은 단항 함수element -> result또는 이항 함수(element, index) -> result일 수 있습니다.expression이 단항인 경우array의 각 요소와 함께 호출됩니다.expression이 이항인 경우array의 각 요소와 요소에 해당하는 0부터 시작하는 색인으로 호출됩니다.
예:
| 배열 | 표현식 | array_transform(array, expression) |
|---|---|---|
| [1, 2, 3] | x -> x * 2 | [2, 4, 6] |
| [1, 2, 3] | x -> x + 1 | [2, 3, 4] |
| [10, 20] | (x, i) -> x + i | [10, 21] |
| [] | x -> 1 | [] |
MAXIMUM
구문:
maximum(array: ARRAY) -> ANY
설명:
array의 최댓값을 반환합니다.
- 비교하는 동안
NULL값은 무시됩니다. array가 비어 있거나NULL값만 포함하는 경우NULL을 반환합니다.
예:
| 배열 | maximum(array) |
|---|---|
| [1, 5, 2] | 5 |
| [1, null, 5] | 5 |
| ["a", "c", "b"] | "c" |
| [null, null] | null |
| [] | null |
MAXIMUM_N
구문:
maximum_n(array: ARRAY, n: INT64) -> ARRAY
설명:
array에서 n번째로 큰 값을 내림차순으로 정렬한 배열을 반환합니다.
NULL값은 무시됩니다.n이 음수이면 오류를 반환합니다.
예:
| 배열 | n | maximum_n(array, n) |
|---|---|---|
| [1, 5, 2, 4, 3] | 3 | [5, 4, 3] |
| [1, null, 5] | 3 | [5, 1] |
MINIMUM
구문:
minimum(array: ARRAY) -> ANY
설명:
array의 최솟값을 반환합니다.
- 비교하는 동안
NULL값은 무시됩니다. array가 비어 있거나NULL값만 포함하는 경우NULL을 반환합니다.
예:
| 배열 | minimum(array) |
|---|---|
| [1, 5, 2] | 1 |
| [5, null, 1] | 1 |
| ["a", "c", "b"] | "a" |
| [null, null] | null |
| [] | null |
MINIMUM_N
구문:
minimum_n(array: ARRAY, n: INT64) -> ARRAY
설명:
array에서 n번째로 작은 값을 오름차순으로 정렬한 배열을 반환합니다.
NULL값은 무시됩니다.n이 음수이면 오류를 반환합니다.
예:
| 배열 | n | minimum_n(array, n) |
|---|---|---|
| [1, 5, 2, 4, 3] | 3 | [1, 2, 3] |
| [5, null, 1] | 3 | [1, 5] |
SUM
구문:
sum(array: ARRAY) -> INT64 | FLOAT64
설명:
ARRAY에 있는 모든 NUMERIC 값의 합계를 반환합니다.
- 배열의 숫자가 아닌 값은 무시됩니다.
- 배열의 숫자 값이
NaN이면 함수는NaN을 반환합니다. - 반환 유형은 배열에서 가장 넓은 숫자 유형에 따라 결정됩니다(
INT64<FLOAT64). - 부동 소수점 값이 합산되기 전에 64비트 정수 오버플로가 발생하면 오류가 반환됩니다. 부동 소수점 값을 합산하면 오버플로로 인해 +/- 무한대가 발생합니다.
- 배열에 숫자 값이 전혀 포함되어 있지 않으면 함수는
NULL을 반환합니다.
예:
| 배열 | sum(array) |
|---|---|
| [1, 2, 3] | 6L |
| [1L, 2L, 3L] | 6L |
| [2000000000, 2000000000] | 4000000000L |
| [10, 20.5] | 30.5 |
| [1, "a", 2] | 3L |
| [INT64.MAX_VALUE, 1] | 오류 |
| [INT64.MAX_VALUE, 1, -1.0] | 오류 |
| [INT64.MAX_VALUE, 1.0] | 9.223372036854776e+18 |
참여
구문:
join[T <: STRING | BYTES](array: ARRAY<T>, delimiter: T) -> STRING
join[T <: STRING | BYTES](array: ARRAY<T>, delimiter: T, null_text: T) -> STRING
설명:
array에 있는 요소의 연결을 STRING으로 반환합니다. array는 STRING 또는 BYTES 데이터 유형일 수 있습니다.
array,delimiter,null_text의 모든 요소는 동일한 유형이어야 합니다. 모두STRING이거나 모두BYTES이어야 합니다.null_text가 제공되면array의 모든NULL값이null_text로 대체됩니다.null_text가 제공되지 않으면array의NULL값이 결과에서 생략됩니다.
예:
null_text가 제공되지 않는 경우:
| 배열 | 구분자 | join(array, delimiter) |
|---|---|---|
| ["a", "b", "c"] | "," | "a,b,c" |
| ["a", null, "c"] | "," | "a,c" |
| [b'a', b'b', b'c'] | b',' | b'a,b,c' |
| ["a", b'c'] | "," | 오류 |
| ["a", "c"] | b',' | 오류 |
| [b'a', b'c'] | "," | 오류 |
null_text가 제공되는 경우:
| 배열 | 구분자 | null_text | join(array, delimiter, null_text) |
|---|---|---|---|
| ["a", null, "c"] | "," | "MISSING" | "a,MISSING,c" |
| [b'a', null, b'c'] | b',' | b'NULL' | b'a,NULL,c' |
| [null, "b", null] | "," | "MISSING" | "MISSING,b,MISSING" |
| [b'a', null, null] | b',' | b'NULL' | b'a,NULL,NULL' |
| ["a", null] | "," | b'N' | 오류 |
| [b'a', null] | b',' | "N" | 오류 |
다음 단계
- 파이프라인 쿼리 개요를 참고하세요.