집계
모든 집계 함수는 aggregate(...) 단계에서 최상위 표현식으로 사용할 수 있습니다.
| 이름 | 설명 |
COUNT
|
문서 수를 반환합니다. |
COUNT_IF
|
표현식이 TRUE로 평가되는 문서 수를 반환합니다.
|
COUNT_DISTINCT
|
NULL이 아닌 고유 값의 개수를 반환합니다.
|
SUM
|
모든 NUMERIC 값의 합계를 반환합니다.
|
AVERAGE
|
모든 NUMERIC 값의 평균을 반환합니다.
|
MINIMUM
|
NULL이 아닌 최솟값을 반환합니다.
|
MAXIMUM
|
NULL이 아닌 최댓값을 반환합니다.
|
FIRST
|
첫 번째 문서의 expression 값을 반환합니다.
|
LAST
|
마지막 문서의 expression 값을 반환합니다.
|
ARRAY_AGG
|
모든 입력 값의 배열을 반환합니다. |
ARRAY_AGG_DISTINCT
|
모든 고유 입력 값의 배열을 반환합니다. |
COUNT
구문:
count() -> INT64
count(expression: ANY) -> INT64
설명:
expression이 NULL이 아닌 값으로 평가되는 이전 단계의 문서 수를 반환합니다. expression이 제공되지 않으면 이전 단계의 총 문서 수를 반환합니다.
Node.js
// Total number of books in the collection const countOfAll = await db.pipeline() .collection("books") .aggregate(countAll().as("count")) .execute(); // Number of books with nonnull `ratings` field const countField = await db.pipeline() .collection("books") .aggregate(field("ratings").count().as("count")) .execute();
Web
// Total number of books in the collection const countOfAll = await execute(db.pipeline() .collection("books") .aggregate(countAll().as("count")) ); // Number of books with nonnull `ratings` field const countField = await execute(db.pipeline() .collection("books") .aggregate(field("ratings").count().as("count")) );
Swift
// Total number of books in the collection let countAll = try await db.pipeline() .collection("books") .aggregate([CountAll().as("count")]) .execute() // Number of books with nonnull `ratings` field let countField = try await db.pipeline() .collection("books") .aggregate([Field("ratings").count().as("count")]) .execute()
Kotlin
// Total number of books in the collection val countAll = db.pipeline() .collection("books") .aggregate(AggregateFunction.countAll().alias("count")) .execute() // Number of books with nonnull `ratings` field val countField = db.pipeline() .collection("books") .aggregate(AggregateFunction.count("ratings").alias("count")) .execute()
Java
// Total number of books in the collection Task<Pipeline.Snapshot> countAll = db.pipeline() .collection("books") .aggregate(AggregateFunction.countAll().alias("count")) .execute(); // Number of books with nonnull `ratings` field Task<Pipeline.Snapshot> countField = db.pipeline() .collection("books") .aggregate(AggregateFunction.count("ratings").alias("count")) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Count # Total number of books in the collection count_all = ( client.pipeline().collection("books").aggregate(Count().as_("count")).execute() ) # Number of books with nonnull `ratings` field count_field = ( client.pipeline() .collection("books") .aggregate(Count("ratings").as_("count")) .execute() )
자바
// Total number of books in the collection Pipeline.Snapshot countAll = firestore.pipeline().collection("books").aggregate(countAll().as("count")).execute().get(); // Number of books with nonnull `ratings` field Pipeline.Snapshot countField = firestore .pipeline() .collection("books") .aggregate(count("ratings").as("count")) .execute() .get();
COUNT_IF
구문:
count_if(expression: BOOLEAN) -> INT64
설명:
expression이 TRUE로 평가되는 이전 단계의 문서 수를 반환합니다.
Node.js
const result = await db.pipeline() .collection("books") .aggregate( field("rating").greaterThan(4).countIf().as("filteredCount") ) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .aggregate( field("rating").greaterThan(4).countIf().as("filteredCount") ) );
Swift
let result = try await db.pipeline() .collection("books") .aggregate([ AggregateFunction("count_if", [Field("rating").greaterThan(4)]).as("filteredCount") ]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .aggregate( AggregateFunction.countIf(field("rating").greaterThan(4)).alias("filteredCount") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .aggregate( AggregateFunction.countIf(field("rating").greaterThan(4)).alias("filteredCount") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .aggregate(Field.of("rating").greater_than(4).count_if().as_("filteredCount")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .aggregate(countIf(field("rating").greaterThan(4)).as("filteredCount")) .execute() .get();
COUNT_DISTINCT
구문:
count_distinct(expression: ANY) -> INT64
설명:
expression의 고유한 NULL이 아닌 값, ABSENT가 아닌 값의 수를 반환합니다.
Node.js
const result = await db.pipeline() .collection("books") .aggregate(field("author").countDistinct().as("unique_authors")) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .aggregate(field("author").countDistinct().as("unique_authors")) );
Swift
let result = try await db.pipeline() .collection("books") .aggregate([AggregateFunction("count_distinct", [Field("author")]).as("unique_authors")]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .aggregate(AggregateFunction.countDistinct("author").alias("unique_authors")) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .aggregate(AggregateFunction.countDistinct("author").alias("unique_authors")) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .aggregate(Field.of("author").count_distinct().as_("unique_authors")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .aggregate(countDistinct("author").as("unique_authors")) .execute() .get();
SUM
구문:
sum(expression: ANY) -> NUMBER
설명:
숫자가 아닌 값을 무시하고 모든 숫자 값의 합계를 반환합니다. 값이 NaN이면 NaN을 반환합니다.
출력은 다음 경우를 제외하고 가장 넓은 입력 유형과 동일한 유형을 갖습니다.
INTEGER는INTEGER로 표현할 수 없는 경우DOUBLE로 변환됩니다.
Node.js
const result = await db.pipeline() .collection("cities") .aggregate(field("population").sum().as("totalPopulation")) .execute();
Web
const result = await execute(db.pipeline() .collection("cities") .aggregate(field("population").sum().as("totalPopulation")) );
Swift
let result = try await db.pipeline() .collection("cities") .aggregate([Field("population").sum().as("totalPopulation")]) .execute()
Kotlin
val result = db.pipeline() .collection("cities") .aggregate(AggregateFunction.sum("population").alias("totalPopulation")) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("cities") .aggregate(AggregateFunction.sum("population").alias("totalPopulation")) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("cities") .aggregate(Field.of("population").sum().as_("totalPopulation")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("cities") .aggregate(sum("population").as("totalPopulation")) .execute() .get();
AVERAGE
구문:
average(expression: ANY) -> FLOAT64
설명:
숫자가 아닌 값을 무시하고 모든 숫자 값의 평균을 반환합니다.
값이 NaN이면 NaN으로 평가되고, 집계된 숫자 값이 없으면 NULL로 평가됩니다.
출력은 다음 경우를 제외하고 입력 유형과 동일한 유형을 갖습니다.
INTEGER는INTEGER로 표현할 수 없는 경우DOUBLE로 변환됩니다.
Node.js
const result = await db.pipeline() .collection("cities") .aggregate(field("population").average().as("averagePopulation")) .execute();
Web
const result = await execute(db.pipeline() .collection("cities") .aggregate(field("population").average().as("averagePopulation")) );
Swift
let result = try await db.pipeline() .collection("cities") .aggregate([Field("population").average().as("averagePopulation")]) .execute()
Kotlin
val result = db.pipeline() .collection("cities") .aggregate(AggregateFunction.average("population").alias("averagePopulation")) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("cities") .aggregate(AggregateFunction.average("population").alias("averagePopulation")) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("cities") .aggregate(Field.of("population").average().as_("averagePopulation")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("cities") .aggregate(average("population").as("averagePopulation")) .execute() .get();
MINIMUM
구문:
minimum(expression: ANY) -> ANY
설명:
각 문서에서 평가될 때 expression의 NULL이 아니고 누락되지 않은 최솟값을 반환합니다.
NULL이 아니고 누락되지 않은 값이 없으면 NULL이 반환됩니다. 문서가 고려되지 않는 경우도 포함됩니다.
동등한 최솟값이 여러 개 있는 경우 이러한 값 중 하나가 반환될 수 있습니다. 값 유형 순서는 문서화된 순서를 따릅니다.
Node.js
const result = await db.pipeline() .collection("books") .aggregate(field("price").minimum().as("minimumPrice")) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .aggregate(field("price").minimum().as("minimumPrice")) );
Swift
let result = try await db.pipeline() .collection("books") .aggregate([Field("price").minimum().as("minimumPrice")]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .aggregate(AggregateFunction.minimum("price").alias("minimumPrice")) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .aggregate(AggregateFunction.minimum("price").alias("minimumPrice")) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .aggregate(Field.of("price").minimum().as_("minimumPrice")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .aggregate(minimum("price").as("minimumPrice")) .execute() .get();
MAXIMUM
구문:
maximum(expression: ANY) -> ANY
설명:
각 문서에서 평가될 때 expression의 NULL이 아니고 누락되지 않은 최댓값을 반환합니다.
NULL이 아니고 누락되지 않은 값이 없으면 NULL이 반환됩니다. 문서가 고려되지 않는 경우도 포함됩니다.
동등한 최댓값이 여러 개 있는 경우 이러한 값 중 하나가 반환될 수 있습니다. 값 유형 순서는 문서화된 순서를 따릅니다.
Node.js
const result = await db.pipeline() .collection("books") .aggregate(field("price").maximum().as("maximumPrice")) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .aggregate(field("price").maximum().as("maximumPrice")) );
Swift
let result = try await db.pipeline() .collection("books") .aggregate([Field("price").maximum().as("maximumPrice")]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .aggregate(AggregateFunction.maximum("price").alias("maximumPrice")) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .aggregate(AggregateFunction.maximum("price").alias("maximumPrice")) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .aggregate(Field.of("price").maximum().as_("maximumPrice")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .aggregate(maximum("price").as("maximumPrice")) .execute() .get();
FIRST
구문:
first(expression: ANY) -> ANY
설명:
반환된 첫 번째 문서의 expression 값을 반환합니다.
LAST
구문:
last(expression: ANY) -> ANY
설명:
마지막으로 반환된 문서의 expression 값을 반환합니다.
ARRAY_AGG
구문:
array_agg(expression: ANY) -> ARRAY<ANY>
설명:
각 문서에서 평가될 때 expression의 모든 값을 포함하는 배열을 반환합니다.
표현식이 누락된 값으로 확인되면 NULL로 변환됩니다.
출력 배열의 요소 순서는 안정적이지 않으므로 이에 의존해서는 안 됩니다.
ARRAY_AGG_DISTINCT
구문:
array_agg_distinct(expression: ANY) -> ARRAY<ANY>
설명:
각 문서에서 평가할 때 expression의 모든 고유 값을 포함하는 배열을 반환합니다.
표현식이 누락된 값으로 확인되면 NULL로 변환됩니다.
출력 배열의 요소 순서는 안정적이지 않으므로 이에 의존해서는 안 됩니다.
산술 함수
Cloud Firestore의 모든 산술 함수는 다음과 같이 동작합니다.
- 입력 파라미터 중 하나가
NULL인 경우NULL로 평가됩니다. - 인수 중 하나가
NaN인 경우NaN으로 평가됩니다. - 오버플로 또는 언더플로가 발생하면 오류를 생성합니다.
또한 산술 함수가 유형이 다른 여러 숫자 인수를 사용하는 경우(예: add(5.0, 6)) Cloud Firestore는 인수를 가장 넓은 입력 유형으로 암시적으로 변환합니다. INT32 입력만 제공된 경우 반환 유형은 INT64입니다.
| 이름 | 설명 |
ABS
|
number의 절댓값을 반환합니다.
|
ADD
|
x + y의 값을 반환합니다.
|
SUBTRACT
|
x - y의 값을 반환합니다.
|
MULTIPLY
|
x * y의 값을 반환합니다.
|
DIVIDE
|
x / y의 값을 반환합니다.
|
MOD
|
x / y의 나눗셈의 나머지를 반환합니다.
|
CEIL
|
number의 천장값을 반환합니다.
|
FLOOR
|
number의 바닥값을 반환합니다.
|
ROUND
|
number를 소수점 places자리로 반올림합니다.
|
TRUNC
|
number를 소수점 places자리로 자릅니다.
|
POW
|
base^exponent의 값을 반환합니다.
|
SQRT
|
number의 제곱근을 반환합니다.
|
EXP
|
오일러 수의 exponent승 값을 반환합니다.
|
LN
|
number의 자연 로그를 반환합니다.
|
LOG
|
number의 로그를 반환합니다.
|
LOG10
|
밑이 10인 number의 로그를 반환합니다.
|
RAND
|
의사 랜덤 부동 소수점 수를 반환합니다. |
ABS
구문:
abs[N <: INT32 | INT64 | FLOAT64](number: N) -> N
설명:
number의 절댓값을 반환합니다.
- 함수가
INT32또는INT64값을 오버플로하면 오류가 발생합니다.
예:
| 숫자 | abs(number) |
|---|---|
| 10 | 10 |
| -10 | 10 |
| 10L | 10L |
| -0.0 | 0.0 |
| 10.5 | 10.5 |
| -10.5 | 10.5 |
| -231 | [error] |
| -263 | [error] |
추가
구문:
add[N <: INT32 | INT64 | FLOAT64](x: N, y: N) -> N
설명:
x + y의 값을 반환합니다.
예:
| x | y | add(x, y) |
|---|---|---|
| 20 | 3 | 23 |
| 10.0 | 1 | 11.0 |
| 22.5 | 2.0 | 24.5 |
| INT64.MAX | 1 | [error] |
| INT64.MIN | -1 | [error] |
Node.js
const result = await db.pipeline() .collection("books") .select(field("soldBooks").add(field("unsoldBooks")).as("totalBooks")) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .select(field("soldBooks").add(field("unsoldBooks")).as("totalBooks")) );
Swift
let result = try await db.pipeline() .collection("books") .select([Field("soldBooks").add(Field("unsoldBooks")).as("totalBooks")]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .select(Expression.add(field("soldBooks"), field("unsoldBooks")).alias("totalBooks")) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select(Expression.add(field("soldBooks"), field("unsoldBooks")).alias("totalBooks")) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select(Field.of("soldBooks").add(Field.of("unsoldBooks")).as_("totalBooks")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(add(field("soldBooks"), field("unsoldBooks")).as("totalBooks")) .execute() .get();
SUBTRACT
구문:
subtract[N <: INT32 | INT64 | FLOAT64](x: N, y: N) -> N
설명:
x - y의 값을 반환합니다.
예:
| x | y | subtract(x, y) |
|---|---|---|
| 20 | 3 | 17 |
| 10.0 | 1 | 9.0 |
| 22.5 | 2.0 | 20.5 |
| INT64.MAX | -1 | [error] |
| INT64.MIN | 1 | [error] |
Node.js
const storeCredit = 7; const result = await db.pipeline() .collection("books") .select(field("price").subtract(constant(storeCredit)).as("totalCost")) .execute();
Web
const storeCredit = 7; const result = await execute(db.pipeline() .collection("books") .select(field("price").subtract(constant(storeCredit)).as("totalCost")) );
Swift
let storeCredit = 7 let result = try await db.pipeline() .collection("books") .select([Field("price").subtract(Constant(storeCredit)).as("totalCost")]) .execute()
Kotlin
val storeCredit = 7 val result = db.pipeline() .collection("books") .select(Expression.subtract(field("price"), storeCredit).alias("totalCost")) .execute()
Java
int storeCredit = 7; Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select(Expression.subtract(field("price"), storeCredit).alias("totalCost")) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field store_credit = 7 result = ( client.pipeline() .collection("books") .select(Field.of("price").subtract(store_credit).as_("totalCost")) .execute() )
자바
int storeCredit = 7; Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(subtract(field("price"), storeCredit).as("totalCost")) .execute() .get();
MULTIPLY
구문:
multiply[N <: INT32 | INT64 | FLOAT64](x: N, y: N) -> N
설명:
x * y의 값을 반환합니다.
예:
| x | y | multiply(x, y) |
|---|---|---|
| 20 | 3 | 60 |
| 10.0 | 1 | 10.0 |
| 22.5 | 2.0 | 45.0 |
| INT64.MAX | 2 | [error] |
| INT64.MIN | 2 | [error] |
| FLOAT64.MAX | FLOAT64.MAX | +inf |
Node.js
const result = await db.pipeline() .collection("books") .select(field("price").multiply(field("soldBooks")).as("revenue")) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .select(field("price").multiply(field("soldBooks")).as("revenue")) );
Swift
let result = try await db.pipeline() .collection("books") .select([Field("price").multiply(Field("soldBooks")).as("revenue")]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .select(Expression.multiply(field("price"), field("soldBooks")).alias("revenue")) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select(Expression.multiply(field("price"), field("soldBooks")).alias("revenue")) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select(Field.of("price").multiply(Field.of("soldBooks")).as_("revenue")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(multiply(field("price"), field("soldBooks")).as("revenue")) .execute() .get();
DIVIDE
구문:
divide[N <: INT32 | INT64 | FLOAT64](x: N, y: N) -> N
설명:
x / y의 값을 반환합니다. 정수 나눗셈이 잘립니다.
예:
| x | y | divide(x, y) |
|---|---|---|
| 20 | 3 | 6 |
| 10.0 | 3 | 3.333... |
| 22.5 | 2 | 11.25 |
| 10 | 0 | [error] |
| 1.0 | 0.0 | +inf |
| -1.0 | 0.0 | -inf |
Node.js
const result = await db.pipeline() .collection("books") .select(field("ratings").divide(field("soldBooks")).as("reviewRate")) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .select(field("ratings").divide(field("soldBooks")).as("reviewRate")) );
Swift
let result = try await db.pipeline() .collection("books") .select([Field("ratings").divide(Field("soldBooks")).as("reviewRate")]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .select(Expression.divide(field("ratings"), field("soldBooks")).alias("reviewRate")) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select(Expression.divide(field("ratings"), field("soldBooks")).alias("reviewRate")) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select(Field.of("ratings").divide(Field.of("soldBooks")).as_("reviewRate")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(divide(field("ratings"), field("soldBooks")).as("reviewRate")) .execute() .get();
MOD
구문:
mod[N <: INT32 | INT64 | FLOAT64](x: N, y: N) -> N
설명:
x / y의 나머지를 반환합니다.
- 정수 유형(
INT64)의 경우y가 0이면error가 발생합니다. - 부동 소수점 유형(
FLOAT64)의 경우y가 0이면NaN을 반환합니다.
예:
| x | y | mod(x, y) |
|---|---|---|
| 20 | 3 | 2 |
| -10 | 3 | -1 |
| 10 | -3 | 1 |
| -10 | -3 | -1 |
| 10 | 1 | 0 |
| 22.5 | 2 | 0.5 |
| 22.5 | 0.0 | NaN |
| 25 | 0 | [error] |
Node.js
const displayCapacity = 1000; const result = await db.pipeline() .collection("books") .select(field("unsoldBooks").mod(constant(displayCapacity)).as("warehousedBooks")) .execute();
Web
const displayCapacity = 1000; const result = await execute(db.pipeline() .collection("books") .select(field("unsoldBooks").mod(constant(displayCapacity)).as("warehousedBooks")) );
Swift
let displayCapacity = 1000 let result = try await db.pipeline() .collection("books") .select([Field("unsoldBooks").mod(Constant(displayCapacity)).as("warehousedBooks")]) .execute()
Kotlin
val displayCapacity = 1000 val result = db.pipeline() .collection("books") .select(Expression.mod(field("unsoldBooks"), displayCapacity).alias("warehousedBooks")) .execute()
Java
int displayCapacity = 1000; Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select(Expression.mod(field("unsoldBooks"), displayCapacity).alias("warehousedBooks")) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field display_capacity = 1000 result = ( client.pipeline() .collection("books") .select(Field.of("unsoldBooks").mod(display_capacity).as_("warehousedBooks")) .execute() )
자바
int displayCapacity = 1000; Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(mod(field("unsoldBooks"), displayCapacity).as("warehousedBooks")) .execute() .get();
CEIL
구문:
ceil[N <: INT32 | INT64 | FLOAT64](number: N) -> N
설명:
number보다 작지 않은 가장 작은 정수 값을 반환합니다.
예:
| 숫자 | ceil(number) |
|---|---|
| 20 | 20 |
| 10 | 10 |
| 0 | 0 |
| 24L | 24L |
| -0.4 | -0.0 |
| 0.4 | 1.0 |
| 22.5 | 23.0 |
+inf |
+inf |
-inf |
-inf |
Node.js
const booksPerShelf = 100; const result = await db.pipeline() .collection("books") .select( field("unsoldBooks").divide(constant(booksPerShelf)).ceil().as("requiredShelves") ) .execute();
Web
const booksPerShelf = 100; const result = await execute(db.pipeline() .collection("books") .select( field("unsoldBooks").divide(constant(booksPerShelf)).ceil().as("requiredShelves") ) );
Swift
let booksPerShelf = 100 let result = try await db.pipeline() .collection("books") .select([ Field("unsoldBooks").divide(Constant(booksPerShelf)).ceil().as("requiredShelves") ]) .execute()
Kotlin
val booksPerShelf = 100 val result = db.pipeline() .collection("books") .select( Expression.divide(field("unsoldBooks"), booksPerShelf).ceil().alias("requiredShelves") ) .execute()
Java
int booksPerShelf = 100; Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( Expression.divide(field("unsoldBooks"), booksPerShelf).ceil().alias("requiredShelves") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field books_per_shelf = 100 result = ( client.pipeline() .collection("books") .select( Field.of("unsoldBooks") .divide(books_per_shelf) .ceil() .as_("requiredShelves") ) .execute() )
자바
int booksPerShelf = 100; Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(ceil(divide(field("unsoldBooks"), booksPerShelf)).as("requiredShelves")) .execute() .get();
FLOOR
구문:
floor[N <: INT32 | INT64 | FLOAT64](number: N) -> N
설명:
number보다 크지 않은 가장 큰 정수 값을 반환합니다.
예:
| 숫자 | floor(number) |
|---|---|
| 20 | 20 |
| 10 | 10 |
| 0 | 0 |
| 2147483648 | 2147483648 |
| -0.4 | -1.0 |
| 0.4 | 0.0 |
| 22.5 | 22.0 |
+inf |
+inf |
-inf |
-inf |
Node.js
const result = await db.pipeline() .collection("books") .addFields( field("wordCount").divide(field("pages")).floor().as("wordsPerPage") ) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .addFields( field("wordCount").divide(field("pages")).floor().as("wordsPerPage") ) );
Swift
let result = try await db.pipeline() .collection("books") .addFields([ Field("wordCount").divide(Field("pages")).floor().as("wordsPerPage") ]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .addFields( Expression.divide(field("wordCount"), field("pages")).floor().alias("wordsPerPage") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .addFields( Expression.divide(field("wordCount"), field("pages")).floor().alias("wordsPerPage") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .add_fields( Field.of("wordCount").divide(Field.of("pages")).floor().as_("wordsPerPage") ) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .addFields(floor(divide(field("wordCount"), field("pages"))).as("wordsPerPage")) .execute() .get();
ROUND
구문:
round[N <: INT32 | INT64 | FLOAT64 | DECIMAL128](number: N) -> N
round[N <: INT32 | INT64 | FLOAT64 | DECIMAL128](number: N, places: INT64) -> N
설명:
number의 places 자릿수를 반올림합니다. places가 양수이면 소수점 오른쪽의 자릿수를 반올림하고, 음수이면 소수점 왼쪽의 자릿수를 반올림합니다.
number만 제공된 경우 가장 가까운 정수 값으로 반올림합니다.- 중간값은 0에서 멀어지는 방향으로 반올림됩니다.
- 음수
places값으로 반올림하면 오버플로가 발생하는 경우error가 발생합니다.
예:
| 숫자 | 자리 | round(number, places) |
|---|---|---|
| 15.5 | 0 | 16.0 |
| -15.5 | 0 | -16.0 |
| 15 | 1 | 15 |
| 15 | 0 | 15 |
| 15 | -1 | 20 |
| 15 | -2 | 0 |
| 15.48924 | 1 | 15.5 |
| 231-1 | -1 | [error] |
| 263-1L | -1 | [error] |
Node.js
const result = await db.pipeline() .collection("books") .select(field("soldBooks").multiply(field("price")).round().as("partialRevenue")) .aggregate(field("partialRevenue").sum().as("totalRevenue")) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .select(field("soldBooks").multiply(field("price")).round().as("partialRevenue")) .aggregate(field("partialRevenue").sum().as("totalRevenue")) );
Swift
let result = try await db.pipeline() .collection("books") .select([Field("soldBooks").multiply(Field("price")).round().as("partialRevenue")]) .aggregate([Field("partialRevenue").sum().as("totalRevenue")]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .select(Expression.multiply(field("soldBooks"), field("price")).round().alias("partialRevenue")) .aggregate(AggregateFunction.sum("partialRevenue").alias("totalRevenue")) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select(Expression.multiply(field("soldBooks"), field("price")).round().alias("partialRevenue")) .aggregate(AggregateFunction.sum("partialRevenue").alias("totalRevenue")) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select( Field.of("soldBooks") .multiply(Field.of("price")) .round() .as_("partialRevenue") ) .aggregate(Field.of("partialRevenue").sum().as_("totalRevenue")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(round(multiply(field("soldBooks"), field("price"))).as("partialRevenue")) .aggregate(sum("partialRevenue").as("totalRevenue")) .execute() .get();
TRUNC
구문:
trunc[N <: Number](number: N) -> N
trunc[N <: Number](number: N, places: INT64) -> N
설명:
number를 지정된 소수점 places자리로 자릅니다. places가 양수이면 소수점 오른쪽의 자릿수를 자르고, 음수이면 소수점 왼쪽의 자릿수를 자릅니다.
number만 제공된 경우 0에 가장 가까운 정수 값으로 자릅니다.- 잘라내기로 인해 오버플로가 발생하는 경우
error가 발생합니다.
예:
| 숫자 | 자리 | trunc(number, places) |
|---|---|---|
| 15.5 | 0 | 15.0 |
| -15.5 | 0 | -15.0 |
| 15 | 1 | 15 |
| 15 | 0 | 15 |
| 15 | -1 | 10 |
| 15 | -2 | 0 |
| 15.48924 | 1 | 15.4 |
| -15.48924 | 2 | -15.48 |
POW
구문:
pow(base: FLOAT64, exponent: FLOAT64) -> FLOAT64
설명:
base의 exponent승 값을 반환합니다.
base <= 0및exponent가 음수이면 오류가 발생합니다.모든
exponent에 대해pow(1, exponent)는 1입니다.모든
base에 대해pow(base, 0)는 1입니다.
예:
| 밑 | 지수 | pow(base, exponent) |
|---|---|---|
| 2 | 3 | 8.0 |
| 2 | -3 | 0.125 |
+inf |
0 | 1.0 |
| 1 | +inf |
1.0 |
| -1 | 0.5 | [error] |
| 0 | -1 | [error] |
Node.js
const googleplex = { latitude: 37.4221, longitude: 122.0853 }; const result = await db.pipeline() .collection("cities") .addFields( field("lat").subtract(constant(googleplex.latitude)) .multiply(111 /* km per degree */) .pow(2) .as("latitudeDifference"), field("lng").subtract(constant(googleplex.longitude)) .multiply(111 /* km per degree */) .pow(2) .as("longitudeDifference") ) .select( field("latitudeDifference").add(field("longitudeDifference")).sqrt() // Inaccurate for large distances or close to poles .as("approximateDistanceToGoogle") ) .execute();
Web
const googleplex = { latitude: 37.4221, longitude: 122.0853 }; const result = await execute(db.pipeline() .collection("cities") .addFields( field("lat").subtract(constant(googleplex.latitude)) .multiply(111 /* km per degree */) .pow(2) .as("latitudeDifference"), field("lng").subtract(constant(googleplex.longitude)) .multiply(111 /* km per degree */) .pow(2) .as("longitudeDifference") ) .select( field("latitudeDifference").add(field("longitudeDifference")).sqrt() // Inaccurate for large distances or close to poles .as("approximateDistanceToGoogle") ) );
Swift
let googleplex = CLLocation(latitude: 37.4221, longitude: 122.0853) let result = try await db.pipeline() .collection("cities") .addFields([ Field("lat").subtract(Constant(googleplex.coordinate.latitude)) .multiply(111 /* km per degree */) .pow(2) .as("latitudeDifference"), Field("lng").subtract(Constant(googleplex.coordinate.latitude)) .multiply(111 /* km per degree */) .pow(2) .as("longitudeDifference") ]) .select([ Field("latitudeDifference").add(Field("longitudeDifference")).sqrt() // Inaccurate for large distances or close to poles .as("approximateDistanceToGoogle") ]) .execute()
Kotlin
val googleplex = GeoPoint(37.4221, -122.0853) val result = db.pipeline() .collection("cities") .addFields( field("lat").subtract(googleplex.latitude) .multiply(111 /* km per degree */) .pow(2) .alias("latitudeDifference"), field("lng").subtract(googleplex.longitude) .multiply(111 /* km per degree */) .pow(2) .alias("longitudeDifference") ) .select( field("latitudeDifference").add(field("longitudeDifference")).sqrt() // Inaccurate for large distances or close to poles .alias("approximateDistanceToGoogle") ) .execute()
Java
GeoPoint googleplex = new GeoPoint(37.4221, -122.0853); Task<Pipeline.Snapshot> result = db.pipeline() .collection("cities") .addFields( field("lat").subtract(googleplex.getLatitude()) .multiply(111 /* km per degree */) .pow(2) .alias("latitudeDifference"), field("lng").subtract(googleplex.getLongitude()) .multiply(111 /* km per degree */) .pow(2) .alias("longitudeDifference") ) .select( field("latitudeDifference").add(field("longitudeDifference")).sqrt() // Inaccurate for large distances or close to poles .alias("approximateDistanceToGoogle") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field googleplexLat = 37.4221 googleplexLng = -122.0853 result = ( client.pipeline() .collection("cities") .add_fields( Field.of("lat") .subtract(googleplexLat) .multiply(111) # km per degree .pow(2) .as_("latitudeDifference"), Field.of("lng") .subtract(googleplexLng) .multiply(111) # km per degree .pow(2) .as_("longitudeDifference"), ) .select( Field.of("latitudeDifference") .add(Field.of("longitudeDifference")) .sqrt() # Inaccurate for large distances or close to poles .as_("approximateDistanceToGoogle") ) .execute() )
자바
double googleplexLat = 37.4221; double googleplexLng = -122.0853; Pipeline.Snapshot result = firestore .pipeline() .collection("cities") .addFields( pow(multiply(subtract(field("lat"), googleplexLat), 111), 2) .as("latitudeDifference"), pow(multiply(subtract(field("lng"), googleplexLng), 111), 2) .as("longitudeDifference")) .select( sqrt(add(field("latitudeDifference"), field("longitudeDifference"))) // Inaccurate for large distances or close to poles .as("approximateDistanceToGoogle")) .execute() .get();
SQRT
구문:
sqrt[N <: FLOAT64 | DECIMAL128](number: N) -> N
설명:
number의 제곱근을 반환합니다.
number가 음수이면error가 발생합니다.
예:
| 숫자 | sqrt(number) |
|---|---|
| 25 | 5.0 |
| 12.002 | 3.464... |
| 0.0 | 0.0 |
NaN |
NaN |
+inf |
+inf |
-inf |
[error] |
x < 0 |
[error] |
Node.js
const googleplex = { latitude: 37.4221, longitude: 122.0853 }; const result = await db.pipeline() .collection("cities") .addFields( field("lat").subtract(constant(googleplex.latitude)) .multiply(111 /* km per degree */) .pow(2) .as("latitudeDifference"), field("lng").subtract(constant(googleplex.longitude)) .multiply(111 /* km per degree */) .pow(2) .as("longitudeDifference") ) .select( field("latitudeDifference").add(field("longitudeDifference")).sqrt() // Inaccurate for large distances or close to poles .as("approximateDistanceToGoogle") ) .execute();
Web
const googleplex = { latitude: 37.4221, longitude: 122.0853 }; const result = await execute(db.pipeline() .collection("cities") .addFields( field("lat").subtract(constant(googleplex.latitude)) .multiply(111 /* km per degree */) .pow(2) .as("latitudeDifference"), field("lng").subtract(constant(googleplex.longitude)) .multiply(111 /* km per degree */) .pow(2) .as("longitudeDifference") ) .select( field("latitudeDifference").add(field("longitudeDifference")).sqrt() // Inaccurate for large distances or close to poles .as("approximateDistanceToGoogle") ) );
Swift
let googleplex = CLLocation(latitude: 37.4221, longitude: 122.0853) let result = try await db.pipeline() .collection("cities") .addFields([ Field("lat").subtract(Constant(googleplex.coordinate.latitude)) .multiply(111 /* km per degree */) .pow(2) .as("latitudeDifference"), Field("lng").subtract(Constant(googleplex.coordinate.latitude)) .multiply(111 /* km per degree */) .pow(2) .as("longitudeDifference") ]) .select([ Field("latitudeDifference").add(Field("longitudeDifference")).sqrt() // Inaccurate for large distances or close to poles .as("approximateDistanceToGoogle") ]) .execute()
Kotlin
val googleplex = GeoPoint(37.4221, -122.0853) val result = db.pipeline() .collection("cities") .addFields( field("lat").subtract(googleplex.latitude) .multiply(111 /* km per degree */) .pow(2) .alias("latitudeDifference"), field("lng").subtract(googleplex.longitude) .multiply(111 /* km per degree */) .pow(2) .alias("longitudeDifference") ) .select( field("latitudeDifference").add(field("longitudeDifference")).sqrt() // Inaccurate for large distances or close to poles .alias("approximateDistanceToGoogle") ) .execute()
Java
GeoPoint googleplex = new GeoPoint(37.4221, -122.0853); Task<Pipeline.Snapshot> result = db.pipeline() .collection("cities") .addFields( field("lat").subtract(googleplex.getLatitude()) .multiply(111 /* km per degree */) .pow(2) .alias("latitudeDifference"), field("lng").subtract(googleplex.getLongitude()) .multiply(111 /* km per degree */) .pow(2) .alias("longitudeDifference") ) .select( field("latitudeDifference").add(field("longitudeDifference")).sqrt() // Inaccurate for large distances or close to poles .alias("approximateDistanceToGoogle") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field googleplexLat = 37.4221 googleplexLng = -122.0853 result = ( client.pipeline() .collection("cities") .add_fields( Field.of("lat") .subtract(googleplexLat) .multiply(111) # km per degree .pow(2) .as_("latitudeDifference"), Field.of("lng") .subtract(googleplexLng) .multiply(111) # km per degree .pow(2) .as_("longitudeDifference"), ) .select( Field.of("latitudeDifference") .add(Field.of("longitudeDifference")) .sqrt() # Inaccurate for large distances or close to poles .as_("approximateDistanceToGoogle") ) .execute() )
자바
double googleplexLat = 37.4221; double googleplexLng = -122.0853; Pipeline.Snapshot result = firestore .pipeline() .collection("cities") .addFields( pow(multiply(subtract(field("lat"), googleplexLat), 111), 2) .as("latitudeDifference"), pow(multiply(subtract(field("lng"), googleplexLng), 111), 2) .as("longitudeDifference")) .select( sqrt(add(field("latitudeDifference"), field("longitudeDifference"))) // Inaccurate for large distances or close to poles .as("approximateDistanceToGoogle")) .execute() .get();
EXP
구문:
exp(exponent: FLOAT64) -> FLOAT64
설명:
오일러 수의 exponent승 값을 반환합니다. 자연 지수 함수라고도 합니다.
예:
| 지수 | exp(exponent) |
|---|---|
| 0.0 | 1.0 |
| 10 | e^10(FLOAT64) |
+inf |
+inf |
-inf |
0 |
Node.js
const result = await db.pipeline() .collection("books") .select(field("rating").exp().as("expRating")) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .select(field("rating").exp().as("expRating")) );
Swift
let result = try await db.pipeline() .collection("books") .select([Field("rating").exp().as("expRating")]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .select(field("rating").exp().alias("expRating")) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select(field("rating").exp().alias("expRating")) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select(Field.of("rating").exp().as_("expRating")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(exp(field("rating")).as("expRating")) .execute() .get();
LN
구문:
ln(number: FLOAT64) -> FLOAT64
설명:
number의 자연 로그를 반환합니다. 이 함수는 log(number)와 동일합니다.
예:
| 숫자 | ln(number) |
|---|---|
| 1 | 0.0 |
| 2L | 0.693... |
| 1.0 | 0.0 |
e(FLOAT64) |
1.0 |
-inf |
NaN |
+inf |
+inf |
x <= 0 |
[error] |
Node.js
const result = await db.pipeline() .collection("books") .select(field("rating").ln().as("lnRating")) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .select(field("rating").ln().as("lnRating")) );
Swift
let result = try await db.pipeline() .collection("books") .select([Field("rating").ln().as("lnRating")]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .select(field("rating").ln().alias("lnRating")) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select(field("rating").ln().alias("lnRating")) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select(Field.of("rating").ln().as_("lnRating")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(ln(field("rating")).as("lnRating")) .execute() .get();
LOG
구문:
log(number: FLOAT64, base: FLOAT64) -> FLOAT64
log(number: FLOAT64) -> FLOAT64
설명:
base에 대해 number의 로그를 반환합니다.
number만 제공되면base에 대해number의 로그를 반환합니다(ln(number)와 동의어).
예:
| 숫자 | 밑 | log(number, base) |
|---|---|---|
| 100 | 10 | 2.0 |
-inf |
Numeric |
NaN |
Numeric. |
+inf |
NaN |
number <= 0 |
Numeric |
[error] |
Numeric |
base <= 0 |
[error] |
Numeric |
1.0 | [error] |
LOG10
구문:
log10(x: FLOAT64) -> FLOAT64
설명:
밑이 10인 number의 로그를 반환합니다.
예:
| 숫자 | log10(number) |
|---|---|
| 100 | 2.0 |
-inf |
NaN |
+inf |
+inf |
x <= 0 |
[error] |
RAND
구문:
rand() -> FLOAT64
설명:
0.0(포함)과 1.0(제외) 사이에서 균일하게 선택된 의사 랜덤 부동 소수점 숫자를 반환합니다.
배열 함수
| 이름 | 설명 |
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
val result = db.pipeline() .collection("books") .select(field("genre").arrayConcat(field("subGenre")).alias("allGenres")) .execute()
Java
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();
Web
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
val result = db.pipeline() .collection("books") .select(field("genre").arrayContains("mystery").alias("isMystery")) .execute()
Java
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();
Web
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
val result = db.pipeline() .collection("books") .select( field("genre") .arrayContainsAll(listOf("fantasy", "adventure")) .alias("isFantasyAdventure") ) .execute()
Java
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();
Web
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
val result = db.pipeline() .collection("books") .select( field("genre") .arrayContainsAny(listOf("fantasy", "nonfiction")) .alias("isMysteryOrFantasy") ) .execute()
Java
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();
Web
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
val result = db.pipeline() .collection("books") .select(field("genre").arrayLength().alias("genreCount")) .execute()
Java
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();
Web
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
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();
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" | 오류 |
비교 함수
| 이름 | 설명 |
EQUAL
|
등호 비교 |
GREATER_THAN
|
초과 비교 |
GREATER_THAN_OR_EQUAL
|
이상 비교 |
LESS_THAN
|
미만 비교 |
LESS_THAN_OR_EQUAL
|
이하 비교 |
NOT_EQUAL
|
부등 비교 |
CMP
|
일반적인 비교 |
EQUAL
구문:
equal(x: ANY, y: ANY) -> BOOLEAN
예:
x |
y |
equal(x, y) |
|---|---|---|
| 1L | 1L | TRUE |
| 1.0 | 1L | TRUE |
| -1.0 | 1L | FALSE |
| NaN | NaN | TRUE |
NULL |
NULL |
TRUE |
NULL |
ABSENT |
FALSE |
설명:
x와 y가 같으면 TRUE를 반환하고, 그렇지 않으면 FALSE를 반환합니다.
Node.js
const result = await db.pipeline() .collection("books") .select(field("rating").equal(5).as("hasPerfectRating")) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .select(field("rating").equal(5).as("hasPerfectRating")) );
Swift
let result = try await db.pipeline() .collection("books") .select([Field("rating").equal(5).as("hasPerfectRating")]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .select(field("rating").equal(5).alias("hasPerfectRating")) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select(field("rating").equal(5).alias("hasPerfectRating")) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select(Field.of("rating").equal(5).as_("hasPerfectRating")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(equal(field("rating"), 5).as("hasPerfectRating")) .execute() .get();
GREATER_THAN
구문:
greater_than(x: ANY, y: ANY) -> BOOLEAN
설명:
x이 y보다 크면 TRUE를 반환하고 그렇지 않으면 FALSE를 반환합니다.
x와 y를 비교할 수 없으면 FALSE를 반환합니다.
예:
x |
y |
greater_than(x, y) |
|---|---|---|
| 1L | 0.0 | TRUE |
| 1L | 1L | FALSE |
| 1L | 2L | FALSE |
| 'foo' | 0L | FALSE |
| 0L | 'foo' | FALSE |
| NaN | 0L | FALSE |
| 0L | NaN | FALSE |
NULL |
NULL |
FALSE |
Node.js
const result = await db.pipeline() .collection("books") .select(field("rating").greaterThan(4).as("hasHighRating")) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .select(field("rating").greaterThan(4).as("hasHighRating")) );
Swift
let result = try await db.pipeline() .collection("books") .select([Field("rating").greaterThan(4).as("hasHighRating")]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .select(field("rating").greaterThan(4).alias("hasHighRating")) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select(field("rating").greaterThan(4).alias("hasHighRating")) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select(Field.of("rating").greater_than(4).as_("hasHighRating")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(greaterThan(field("rating"), 4).as("hasHighRating")) .execute() .get();
GREATER_THAN_OR_EQUAL
구문:
greater_than_or_equal(x: ANY, y: ANY) -> BOOLEAN
설명:
x이 y보다 크거나 같으면 TRUE를 반환하고 그렇지 않으면 FALSE를 반환합니다.
x와 y를 비교할 수 없으면 FALSE를 반환합니다.
예:
x |
y |
greater_than_or_equal(x, y) |
|---|---|---|
| 1L | 0.0 | TRUE |
| 1L | 1L | TRUE |
| 1L | 2L | FALSE |
| 'foo' | 0L | FALSE |
| 0L | 'foo' | FALSE |
| NaN | 0L | FALSE |
| 0L | NaN | FALSE |
NULL |
NULL |
TRUE |
Node.js
const result = await db.pipeline() .collection("books") .select(field("published").greaterThanOrEqual(1900).as("publishedIn20thCentury")) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .select(field("published").greaterThanOrEqual(1900).as("publishedIn20thCentury")) );
Swift
let result = try await db.pipeline() .collection("books") .select([Field("published").greaterThanOrEqual(1900).as("publishedIn20thCentury")]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .select(field("published").greaterThanOrEqual(1900).alias("publishedIn20thCentury")) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select(field("published").greaterThanOrEqual(1900).alias("publishedIn20thCentury")) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select( Field.of("published") .greater_than_or_equal(1900) .as_("publishedIn20thCentury") ) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(greaterThanOrEqual(field("published"), 1900).as("publishedIn20thCentury")) .execute() .get();
LESS_THAN
구문:
less_than(x: ANY, y: ANY) -> BOOLEAN
설명:
x이 y보다 작으면 TRUE를 반환하고, 그렇지 않으면 FALSE를 반환합니다.
x와 y를 비교할 수 없으면 FALSE를 반환합니다.
예:
x |
y |
less_than(x, y) |
|---|---|---|
| 1L | 0.0 | FALSE |
| 1L | 1L | FALSE |
| 1L | 2L | TRUE |
| 'foo' | 0L | FALSE |
| 0L | 'foo' | FALSE |
| NaN | 0L | FALSE |
| 0L | NaN | FALSE |
NULL |
NULL |
FALSE |
Node.js
const result = await db.pipeline() .collection("books") .select(field("published").lessThan(1923).as("isPublicDomainProbably")) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .select(field("published").lessThan(1923).as("isPublicDomainProbably")) );
Swift
let result = try await db.pipeline() .collection("books") .select([Field("published").lessThan(1923).as("isPublicDomainProbably")]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .select(field("published").lessThan(1923).alias("isPublicDomainProbably")) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select(field("published").lessThan(1923).alias("isPublicDomainProbably")) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select(Field.of("published").less_than(1923).as_("isPublicDomainProbably")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(lessThan(field("published"), 1923).as("isPublicDomainProbably")) .execute() .get();
LESS_THAN_OR_EQUAL
구문:
less_than_or_equal(x: ANY, y: ANY) -> BOOLEAN
설명:
x이 y보다 작거나 같으면 TRUE를 반환하고 그렇지 않으면 FALSE를 반환합니다.
x와 y를 비교할 수 없으면 FALSE를 반환합니다.
예:
x |
y |
less_than(x, y) |
|---|---|---|
| 1L | 0.0 | FALSE |
| 1L | 1L | TRUE |
| 1L | 2L | TRUE |
| 'foo' | 0L | FALSE |
| 0L | 'foo' | FALSE |
| NaN | 0L | FALSE |
| 0L | NaN | FALSE |
NULL |
NULL |
TRUE |
Node.js
const result = await db.pipeline() .collection("books") .select(field("rating").lessThanOrEqual(2).as("hasBadRating")) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .select(field("rating").lessThanOrEqual(2).as("hasBadRating")) );
Swift
let result = try await db.pipeline() .collection("books") .select([Field("rating").lessThanOrEqual(2).as("hasBadRating")]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .select(field("rating").lessThanOrEqual(2).alias("hasBadRating")) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select(field("rating").lessThanOrEqual(2).alias("hasBadRating")) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select(Field.of("rating").less_than_or_equal(2).as_("hasBadRating")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(lessThanOrEqual(field("rating"), 2).as("hasBadRating")) .execute() .get();
NOT_EQUAL
구문:
not_equal(x: ANY, y: ANY) -> BOOLEAN
설명:
x이 y와 같지 않으면 TRUE를 반환하고, 그렇지 않으면 FALSE를 반환합니다.
예:
x |
y |
not_equal(x, y) |
|---|---|---|
| 1L | 1L | FALSE |
| 1.0 | 1L | FALSE |
| -1.0 | 1L | TRUE |
| NaN | 0L | TRUE |
| NaN | NaN | FALSE |
NULL |
NULL |
FALSE |
NULL |
ABSENT |
TRUE |
Node.js
const result = await db.pipeline() .collection("books") .select(field("title").notEqual("1984").as("not1984")) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .select(field("title").notEqual("1984").as("not1984")) );
Swift
let result = try await db.pipeline() .collection("books") .select([Field("title").notEqual("1984").as("not1984")]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .select(field("title").notEqual("1984").alias("not1984")) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select(field("title").notEqual("1984").alias("not1984")) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select(Field.of("title").not_equal("1984").as_("not1984")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(notEqual(field("title"), "1984").as("not1984")) .execute() .get();
CMP
구문:
cmp(x: ANY, y: ANY) -> Int64
설명:
x 및 y를 비교하여 다음을 반환합니다.
x가y보다 큰 경우1Lx가y보다 작은 경우-1L- 그 외의 경우
0L
다른 비교 함수와 달리 cmp(...) 함수는 sort(...) 단계에서 사용되는 동일한 순서를 따라 여러 유형에서 작동합니다. 유형 간 값 정렬 방식은 값 유형 순서를 참고하세요.
예:
x |
y |
cmp(x, y) |
|---|---|---|
| 1L | 1L | 0L |
| 1.0 | 1L | 0L |
| -1.0 | 1L | -1L |
| 42.5D | 'foo' | -1L |
NULL |
NULL |
0L |
NULL |
ABSENT |
0L |
디버깅 함수
| 이름 | 설명 |
EXISTS
|
값이 누락된 값이 아니면 TRUE를 반환합니다.
|
IS_ABSENT
|
값이 누락된 값인 경우 TRUE를 반환합니다.
|
IF_ABSENT
|
값이 누락된 경우 표현식으로 값을 대체합니다. |
IS_ERROR
|
기본 표현식에서 오류가 발생했는지 포착하고 확인합니다. |
IF_ERROR
|
오류가 발생한 경우 값을 표현식으로 바꿉니다. |
ERROR
|
평가를 종료하고 지정된 메시지와 함께 오류를 반환합니다. |
EXISTS
구문:
exists(value: ANY) -> BOOLEAN
설명:
value가 누락된 값이 아니면 TRUE를 반환합니다.
예:
value |
exists(value) |
|---|---|
| 0L | TRUE |
| 'foo' | TRUE |
NULL |
TRUE |
ABSENT |
FALSE |
Node.js
const result = await db.pipeline() .collection("books") .select(field("rating").exists().as("hasRating")) .execute();
Web
예:
const result = await execute(db.pipeline() .collection("books") .select(field("rating").exists().as("hasRating")) );
Swift
let result = try await db.pipeline() .collection("books") .select([Field("rating").exists().as("hasRating")]) .execute()
Kotlin
예:
val result = db.pipeline() .collection("books") .select(field("rating").exists().alias("hasRating")) .execute()
Java
예:
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select(field("rating").exists().alias("hasRating")) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select(Field.of("rating").exists().as_("hasRating")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(exists(field("rating")).as("hasRating")) .execute() .get();
IS_ABSENT
구문:
is_absent(value: ANY) -> BOOLEAN
설명:
value가 누락된 값이면 TRUE를 반환하고, 그렇지 않으면 FALSE를 반환합니다. 누락된 값은 문서 필드 누락과 같이 입력에서 누락된 값입니다.
예:
value |
is_absent(value) |
|---|---|
| 0L | FALSE |
| 'foo' | FALSE |
NULL |
FALSE |
ABSENT |
TRUE |
IF_ABSENT
구문:
if_absent(value: ANY, replacement: ANY) -> ANY
설명:
value가 누락된 값인 경우 평가하여 replacement를 반환합니다. 그렇지 않으면 value를 반환합니다.
예:
value |
replacement |
if_absent(value, replacement) |
|---|---|---|
| 5L | 0L | 5L |
NULL |
0L | NULL |
ABSENT |
0L | 0L |
IS_ERROR
구문:
is_error(try: ANY) -> BOOLEAN
설명:
try 평가 중에 오류가 발생하면 TRUE를 반환합니다. 그 밖의 경우에는 FALSE를 반환합니다.
IF_ERROR
구문:
if_error(try: ANY, catch: ANY) -> ANY
설명:
try 평가 중에 오류가 발생하면 replacement를 평가하고 반환합니다. 그렇지 않으면 try의 확인된 값을 반환합니다.
오류
구문:
error(message: STRING) -> ANY
설명:
error 함수를 평가하면 파이프라인이 오류와 함께 종료되도록 평가됩니다. 지정된 message가 오류에 포함됩니다.
예:
cond |
res |
switch_on(cond, res, error("no condition matched")) |
|---|---|---|
TRUE |
1L | 1L |
FALSE |
1L | ERROR ("no condition matched") |
참조 함수
REFERENCE 유형은 데이터베이스의 다른 문서(또는 다른 데이터베이스)에 대한 '포인터' 역할을 합니다. 다음 함수를 사용하면 쿼리 실행 중에 이 유형을 조작할 수 있습니다.
| 이름 | 설명 |
COLLECTION_ID
|
지정된 참조의 리프 컬렉션 ID를 반환합니다. |
DOCUMENT_ID
|
지정된 참조의 문서 ID를 반환합니다. |
PARENT
|
상위 참조를 반환합니다. |
REFERENCE_SLICE
|
지정된 참조에서 세그먼트의 하위 집합을 반환합니다. |
COLLECTION_ID
구문:
collection_id(ref: REFERENCE) -> STRING
설명:
지정된 REFERENCE의 리프 컬렉션 ID를 반환합니다.
예:
ref |
collection_id(ref) |
|---|---|
users/user1 |
"users" |
users/user1/posts/post1 |
"posts" |
DOCUMENT_ID
구문:
document_id(ref: REFERENCE) -> ANY
설명:
지정된 REFERENCE의 문서 ID를 반환합니다.
예:
ref |
document_id(ref) |
|---|---|
users/user1 |
"user1" |
users/user1/posts/post1 |
"post1" |
상위 항목
구문:
parent(ref: REFERENCE) -> REFERENCE
설명:
지정된 참조의 상위 REFERENCE를 반환하거나 참조가 이미 루트 참조인 경우 NULL을 반환합니다.
예:
ref |
parent(ref) |
|---|---|
/ |
NULL |
users/user1 |
/ |
users/user1/posts/post1 |
users/user1 |
REFERENCE_SLICE
구문:
reference_slice(ref: REFERENCE, offset: INT, length: INT) -> REFERENCE
설명:
REFERENCE는 (collection_id, document_id) 튜플 목록이며 이를 통해 array_slice(...)와 마찬가지로 목록을 볼 수 있습니다.
지정된 ref의 세그먼트 하위 집합인 새 REFERENCE를 반환합니다.
offset: 슬라이스의 시작 색인(0부터 시작)입니다. 음수이면 참조의 끝에서 오프셋입니다.length: 슬라이스에 포함할 세그먼트 수입니다.
예:
ref |
offset |
length |
reference_slice(ref, offset, length) |
|---|---|---|---|
a/1/b/2/c/3 |
1L | 2L | b/2/c/3 |
a/1/b/2/c/3 |
0L | 2L | a/1/b/2 |
a/1/b/2/c/3 |
-2L | 2L | c/3 |
논리 함수
| 이름 | 설명 |
AND
|
논리적 AND를 수행합니다. |
OR
|
논리적 OR을 수행합니다. |
XOR
|
논리적 XOR을 수행합니다. |
NOT
|
논리적 NOT을 수행합니다. |
NOR
|
논리적 NOR을 수행합니다. |
CONDITIONAL
|
조건식에 따라 평가를 분기합니다. |
IF_NULL
|
null이 아닌 첫 번째 값을 반환합니다. |
SWITCH_ON
|
일련의 조건에 따라 평가를 분기합니다. |
EQUAL_ANY
|
값이 배열의 요소와 같은지 확인합니다. |
NOT_EQUAL_ANY
|
값이 배열의 요소와 같지 않은지 확인합니다. |
MAXIMUM
|
값 집합의 최댓값을 반환합니다. |
MINIMUM
|
값 집합의 최솟값을 반환합니다. |
AND
구문:
and(x: BOOLEAN...) -> BOOLEAN
설명:
두 개 이상의 불리언 값의 논리적 AND를 반환합니다.
주어진 값 중 하나가 ABSENT 또는 NULL인 경우 결과를 도출할 수 없으므로 NULL을 반환합니다.
예:
x |
y |
and(x, y) |
|---|---|---|
TRUE |
TRUE |
TRUE |
FALSE |
TRUE |
FALSE |
NULL |
TRUE |
NULL |
ABSENT |
TRUE |
NULL |
NULL |
FALSE |
FALSE |
FALSE |
ABSENT |
FALSE |
Node.js
const result = await db.pipeline() .collection("books") .select( and(field("rating").greaterThan(4), field("price").lessThan(10)) .as("under10Recommendation") ) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .select( and(field("rating").greaterThan(4), field("price").lessThan(10)) .as("under10Recommendation") ) );
Swift
let result = try await db.pipeline() .collection("books") .select([ (Field("rating").greaterThan(4) && Field("price").lessThan(10)) .as("under10Recommendation") ]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .select( Expression.and(field("rating").greaterThan(4), field("price").lessThan(10)) .alias("under10Recommendation") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( Expression.and( field("rating").greaterThan(4), field("price").lessThan(10) ).alias("under10Recommendation") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field, And result = ( client.pipeline() .collection("books") .select( And( Field.of("rating").greater_than(4), Field.of("price").less_than(10) ).as_("under10Recommendation") ) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select( and(greaterThan(field("rating"), 4), lessThan(field("price"), 10)) .as("under10Recommendation")) .execute() .get();
또는
구문:
or(x: BOOLEAN...) -> BOOLEAN
설명:
두 개 이상의 불리언 값의 논리적 OR을 반환합니다.
주어진 값 중 하나가 ABSENT 또는 NULL인 경우 결과를 도출할 수 없으므로 NULL을 반환합니다.
예:
x |
y |
or(x, y) |
|---|---|---|
TRUE |
TRUE |
TRUE |
FALSE |
TRUE |
TRUE |
NULL |
TRUE |
TRUE |
ABSENT |
TRUE |
TRUE |
NULL |
FALSE |
NULL |
FALSE |
ABSENT |
NULL |
Node.js
const result = await db.pipeline() .collection("books") .select( or(field("genre").equal("Fantasy"), field("tags").arrayContains("adventure")) .as("matchesSearchFilters") ) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .select( or(field("genre").equal("Fantasy"), field("tags").arrayContains("adventure")) .as("matchesSearchFilters") ) );
Swift
let result = try await db.pipeline() .collection("books") .select([ (Field("genre").equal("Fantasy") || Field("tags").arrayContains("adventure")) .as("matchesSearchFilters") ]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .select( Expression.or(field("genre").equal("Fantasy"), field("tags").arrayContains("adventure")) .alias("matchesSearchFilters") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( Expression.or( field("genre").equal("Fantasy"), field("tags").arrayContains("adventure") ).alias("matchesSearchFilters") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field, And, Or result = ( client.pipeline() .collection("books") .select( Or( Field.of("genre").equal("Fantasy"), Field.of("tags").array_contains("adventure"), ).as_("matchesSearchFilters") ) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select( or(equal(field("genre"), "Fantasy"), arrayContains(field("tags"), "adventure")) .as("matchesSearchFilters")) .execute() .get();
XOR
구문:
xor(x: BOOLEAN...) -> BOOLEAN
설명:
두 개 이상의 불리언 값의 논리적 XOR을 반환합니다.
지정된 값 중 하나가 ABSENT 또는 NULL이면 NULL을 반환합니다.
예:
x |
y |
xor(x, y) |
|---|---|---|
TRUE |
TRUE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
TRUE |
TRUE |
NULL |
TRUE |
NULL |
ABSENT |
TRUE |
NULL |
NULL |
FALSE |
NULL |
FALSE |
ABSENT |
NULL |
Node.js
const result = await execute(db.pipeline() .collection("books") .select( xor(field("tags").arrayContains("magic"), field("tags").arrayContains("nonfiction")) .as("matchesSearchFilters") ) );
Web
const result = await execute(db.pipeline() .collection("books") .select( xor(field("tags").arrayContains("magic"), field("tags").arrayContains("nonfiction")) .as("matchesSearchFilters") ) );
Swift
let result = try await db.pipeline() .collection("books") .select([ (Field("tags").arrayContains("magic") ^ Field("tags").arrayContains("nonfiction")) .as("matchesSearchFilters") ]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .select( Expression.xor(field("tags").arrayContains("magic"), field("tags").arrayContains("nonfiction")) .alias("matchesSearchFilters") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( Expression.xor( field("tags").arrayContains("magic"), field("tags").arrayContains("nonfiction") ).alias("matchesSearchFilters") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field, Xor result = ( client.pipeline() .collection("books") .select( Xor( [ Field.of("tags").array_contains("magic"), Field.of("tags").array_contains("nonfiction"), ] ).as_("matchesSearchFilters") ) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select( xor( arrayContains(field("tags"), "magic"), arrayContains(field("tags"), "nonfiction")) .as("matchesSearchFilters")) .execute() .get();
NOR
구문:
nor(x: BOOLEAN...) -> BOOLEAN
설명:
두 개 이상의 불리언 값의 논리적 NOR을 반환합니다.
주어진 값 중 하나가 ABSENT 또는 NULL인 경우 결과를 도출할 수 없으므로 NULL을 반환합니다.
예:
x |
y |
nor(x, y) |
|---|---|---|
TRUE |
TRUE |
FALSE |
FALSE |
TRUE |
FALSE |
FALSE |
FALSE |
TRUE |
NULL |
TRUE |
FALSE |
ABSENT |
TRUE |
FALSE |
NULL |
FALSE |
NULL |
FALSE |
ABSENT |
NULL |
NOT
구문:
not(x: BOOLEAN) -> BOOLEAN
설명:
불리언 값의 논리적 NOT을 반환합니다.
Node.js
const result = await execute(db.pipeline() .collection("books") .select( field("tags").arrayContains("nonfiction").not() .as("isFiction") ) );
Web
const result = await execute(db.pipeline() .collection("books") .select( field("tags").arrayContains("nonfiction").not() .as("isFiction") ) );
Swift
let result = try await db.pipeline() .collection("books") .select([ (!Field("tags").arrayContains("nonfiction")) .as("isFiction") ]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .select( Expression.not( field("tags").arrayContains("nonfiction") ).alias("isFiction") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( Expression.not( field("tags").arrayContains("nonfiction") ).alias("isFiction") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field, Not result = ( client.pipeline() .collection("books") .select(Not(Field.of("tags").array_contains("nonfiction")).as_("isFiction")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(not(arrayContains(field("tags"), "nonfiction")).as("isFiction")) .execute() .get();
CONDITIONAL
구문:
conditional(condition: BOOLEAN, true_case: ANY, false_case: ANY) -> ANY
설명:
condition이 TRUE로 평가되면 true_case를 평가하고 반환합니다.
조건이 FALSE, NULL 또는 ABSENT 값으로 확인되면 false_case를 평가하고 반환합니다.
예:
condition |
true_case |
false_case |
conditional(condition, true_case, false_case) |
|---|---|---|---|
TRUE |
1L | 0L | 1L |
FALSE |
1L | 0L | 0L |
NULL |
1L | 0L | 0L |
ABSENT |
1L | 0L | 0L |
Node.js
const result = await execute(db.pipeline() .collection("books") .select( field("tags").arrayConcat([ field("pages").greaterThan(100) .conditional(constant("longRead"), constant("shortRead")) ]).as("extendedTags") ) );
Web
const result = await execute(db.pipeline() .collection("books") .select( field("tags").arrayConcat([ field("pages").greaterThan(100) .conditional(constant("longRead"), constant("shortRead")) ]).as("extendedTags") ) );
Swift
let result = try await db.pipeline() .collection("books") .select([ Field("tags").arrayConcat([ ConditionalExpression( Field("pages").greaterThan(100), then: Constant("longRead"), else: Constant("shortRead") ) ]).as("extendedTags") ]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .select( field("tags").arrayConcat( Expression.conditional( field("pages").greaterThan(100), constant("longRead"), constant("shortRead") ) ).alias("extendedTags") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( field("tags").arrayConcat( Expression.conditional( field("pages").greaterThan(100), constant("longRead"), constant("shortRead") ) ).alias("extendedTags") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import ( Field, Constant, Conditional, ) result = ( client.pipeline() .collection("books") .select( Field.of("tags") .array_concat( Conditional( Field.of("pages").greater_than(100), Constant.of("longRead"), Constant.of("shortRead"), ) ) .as_("extendedTags") ) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select( arrayConcat( field("tags"), conditional( greaterThan(field("pages"), 100), constant("longRead"), constant("shortRead"))) .as("extendedTags")) .execute() .get();
IF_NULL
구문:
if_null(expr: ANY, replacement: ANY) -> ANY
설명:
NULL이 아니면 expr을 반환하고, 그렇지 않으면 replacement를 평가하여 반환합니다. expr을 사용하는 경우 replacement 표현식이 평가되지 않습니다.
예:
expr |
replacement |
if_null(expr, replacement) |
|---|---|---|
| 1L | 2L | 1L |
NULL |
2L | 2L |
ABSENT |
2L | ABSENT |
SWITCH_ON
구문:
switch_on(cond1: BOOLEAN, res1: ANY, cond2: BOOLEAN, res2: ANY, ..., [default: ANY]) -> ANY
설명:
일련의 조건을 평가하고 첫 번째 TRUE 조건과 연결된 결과를 반환합니다. TRUE로 평가되는 조건이 없으면 default 값이 제공된 경우 반환됩니다. default 값이 제공되지 않고 TRUE로 평가된 다른 조건이 없으면 오류가 발생합니다.
default 값을 제공하려면 인수가 홀수 개수가 되도록 마지막 인수로 전달합니다.
예:
x |
switch_on(eq(x, 1L), "one", eq(x, 2L), "two", "other") |
|---|---|
| 1L | '하나' |
| 2L | '둘' |
| 3L | "other" |
EQUAL_ANY
구문:
equal_any(value: ANY, search_space: ARRAY) -> BOOLEAN
설명:
value가 search_space 배열에 있으면 TRUE를 반환합니다.
예:
value |
search_space |
equal_any(value, search_space) |
|---|---|---|
| 0L | [1L, 2L, 3L] | FALSE |
| 2L | [1L, 2L, 3L] | TRUE |
NULL |
[1L, 2L, 3L] | FALSE |
NULL |
[1L, NULL] |
TRUE |
ABSENT |
[1L, NULL] |
FALSE |
| NaN | [1L, NaN, 3L] | TRUE |
Node.js
const result = await execute(db.pipeline() .collection("books") .select( field("genre").equalAny(["Science Fiction", "Psychological Thriller"]) .as("matchesGenreFilters") ) );
Web
const result = await execute(db.pipeline() .collection("books") .select( field("genre").equalAny(["Science Fiction", "Psychological Thriller"]) .as("matchesGenreFilters") ) );
Swift
let result = try await db.pipeline() .collection("books") .select([ Field("genre").equalAny(["Science Fiction", "Psychological Thriller"]) .as("matchesGenreFilters") ]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .select( field("genre").equalAny(listOf("Science Fiction", "Psychological Thriller")) .alias("matchesGenreFilters") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( field("genre").equalAny(Arrays.asList("Science Fiction", "Psychological Thriller")) .alias("matchesGenreFilters") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select( Field.of("genre") .equal_any(["Science Fiction", "Psychological Thriller"]) .as_("matchesGenreFilters") ) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select( equalAny(field("genre"), Arrays.asList("Science Fiction", "Psychological Thriller")) .as("matchesGenreFilters")) .execute() .get();
NOT_EQUAL_ANY
구문:
not_equal_any(value: ANY, search_space: ARRAY) -> BOOLEAN
설명:
value가 search_space 배열에 없으면 TRUE를 반환합니다.
예:
value |
search_space |
not_equal_any(value, search_space) |
|---|---|---|
| 0L | [1L, 2L, 3L] | TRUE |
| 2L | [1L, 2L, 3L] | FALSE |
NULL |
[1L, 2L, 3L] | TRUE |
NULL |
[1L, NULL] |
FALSE |
ABSENT |
[1L, NULL] |
TRUE |
| NaN | [1L, NaN, 3L] | FALSE |
Node.js
const result = await execute(db.pipeline() .collection("books") .select( field("author").notEqualAny(["George Orwell", "F. Scott Fitzgerald"]) .as("byExcludedAuthors") ) );
Web
const result = await execute(db.pipeline() .collection("books") .select( field("author").notEqualAny(["George Orwell", "F. Scott Fitzgerald"]) .as("byExcludedAuthors") ) );
Swift
let result = try await db.pipeline() .collection("books") .select([ Field("author").notEqualAny(["George Orwell", "F. Scott Fitzgerald"]) .as("byExcludedAuthors") ]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .select( field("author").notEqualAny(listOf("George Orwell", "F. Scott Fitzgerald")) .alias("byExcludedAuthors") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( field("author").notEqualAny(Arrays.asList("George Orwell", "F. Scott Fitzgerald")) .alias("byExcludedAuthors") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select( Field.of("author") .not_equal_any(["George Orwell", "F. Scott Fitzgerald"]) .as_("byExcludedAuthors") ) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select( notEqualAny(field("author"), Arrays.asList("George Orwell", "F. Scott Fitzgerald")) .as("byExcludedAuthors")) .execute() .get();
MAXIMUM
구문:
maximum(x: ANY...) -> ANY
maximum(x: ARRAY) -> ANY
설명:
일련의 ABSENT 값에서 NULL이 아니고 x가 아닌 최댓값을 반환합니다.
NULL이 아니며 ABSENT가 아닌 값이 없으면 NULL이 반환됩니다.
동등한 최댓값이 여러 개 있는 경우 이러한 값 중 하나가 반환될 수 있습니다. 값 유형 순서는 문서화된 순서를 따릅니다.
예:
x |
y |
maximum(x, y) |
|---|---|---|
FALSE |
TRUE |
TRUE |
FALSE |
-10L | -10L |
| 0.0 | -5L | 0.0 |
| 'foo' | 'bar' | 'foo' |
| 'foo' | ["foo"] | ["foo"] |
ABSENT |
ABSENT |
NULL |
NULL |
NULL |
NULL |
Node.js
const result = await execute(db.pipeline() .collection("books") .aggregate(field("price").maximum().as("maximumPrice")) );
Web
const result = await execute(db.pipeline() .collection("books") .aggregate(field("price").maximum().as("maximumPrice")) );
Swift
let result = try await db.pipeline() .collection("books") .select([ Field("rating").logicalMaximum([1]).as("flooredRating") ]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .select( field("rating").logicalMaximum(1).alias("flooredRating") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( field("rating").logicalMaximum(1).alias("flooredRating") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select(Field.of("rating").logical_maximum(1).as_("flooredRating")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(logicalMaximum(field("rating"), 1).as("flooredRating")) .execute() .get();
MINIMUM
구문:
minimum(x: ANY...) -> ANY
minimum(x: ARRAY) -> ANY
설명:
일련의 x 값에서 NULL이 아니고 ABSENT가 아닌 최솟값을 반환합니다.
NULL이 아니며 ABSENT가 아닌 값이 없으면 NULL이 반환됩니다.
동등한 최솟값이 여러 개 있는 경우 이러한 값 중 하나가 반환될 수 있습니다. 값 유형 순서는 문서화된 순서를 따릅니다.
예:
x |
y |
minimum(x, y) |
|---|---|---|
FALSE |
TRUE |
FALSE |
FALSE |
-10L | FALSE |
| 0.0 | -5L | -5L |
| 'foo' | 'bar' | 'bar' |
| 'foo' | ["foo"] | 'foo' |
ABSENT |
ABSENT |
NULL |
NULL |
NULL |
NULL |
Node.js
const result = await execute(db.pipeline() .collection("books") .aggregate(field("price").minimum().as("minimumPrice")) );
Web
const result = await execute(db.pipeline() .collection("books") .aggregate(field("price").minimum().as("minimumPrice")) );
Swift
let result = try await db.pipeline() .collection("books") .select([ Field("rating").logicalMinimum([5]).as("cappedRating") ]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .select( field("rating").logicalMinimum(5).alias("cappedRating") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( field("rating").logicalMinimum(5).alias("cappedRating") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select(Field.of("rating").logical_minimum(5).as_("cappedRating")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(logicalMinimum(field("rating"), 5).as("cappedRating")) .execute() .get();
맵 함수
| 이름 | 설명 |
MAP
|
일련의 키-값 쌍에서 맵 값을 구성합니다. |
MAP_GET
|
지정된 키가 주어지면 맵의 값을 반환합니다. |
MAP_SET
|
일련의 업데이트된 키가 포함된 맵의 사본을 반환합니다. |
MAP_REMOVE
|
일련의 키가 삭제된 맵의 사본을 반환합니다. |
MAP_MERGE
|
일련의 맵을 병합합니다. |
CURRENT_CONTEXT
|
현재 컨텍스트를 맵으로 반환합니다. |
MAP_KEYS
|
맵의 모든 키 배열을 반환합니다. |
MAP_VALUES
|
맵의 모든 값의 배열을 반환합니다. |
MAP_ENTRIES
|
맵의 키-값 쌍 배열을 반환합니다. |
MAP
구문:
map(key: STRING, value: ANY, ...) -> MAP
설명:
일련의 키-값 쌍에서 맵을 구성합니다.
MAP_GET
구문:
map_get(map: ANY, key: STRING) -> ANY
설명:
지정된 키가 주어지면 맵의 값을 반환합니다. key가 맵에 없거나 map 인수가 MAP이 아닌 경우 ABSENT 값을 반환합니다.
Node.js
const result = await db.pipeline() .collection("books") .select( field("awards").mapGet("pulitzer").as("hasPulitzerAward") ) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .select( field("awards").mapGet("pulitzer").as("hasPulitzerAward") ) );
Swift
let result = try await db.pipeline() .collection("books") .select([ Field("awards").mapGet("pulitzer").as("hasPulitzerAward") ]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .select( field("awards").mapGet("pulitzer").alias("hasPulitzerAward") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( field("awards").mapGet("pulitzer").alias("hasPulitzerAward") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select(Field.of("awards").map_get("pulitzer").as_("hasPulitzerAward")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(mapGet(field("awards"), "pulitzer").as("hasPulitzerAward")) .execute() .get();
MAP_SET
구문:
map_set(map: MAP, key: STRING, value: ANY, ...) -> MAP
설명:
일련의 키-값 쌍으로 콘텐츠가 업데이트된 map 값의 사본을 반환합니다.
주어진 값이 누락된 값으로 확인되면 연결된 키가 맵에서 삭제됩니다.
map 인수가 MAP이 아니면 누락된 값을 반환합니다.
MAP_REMOVE
구문:
map_remove(map: MAP, key: STRING...) -> MAP
설명:
일련의 키가 삭제된 map 값의 사본을 반환합니다.
MAP_MERGE
구문:
map_merge(maps: MAP...) -> MAP
두 개 이상의 맵의 콘텐츠를 병합합니다. 여러 맵에 충돌하는 값이 있는 경우 마지막 값이 사용됩니다.
CURRENT_CONTEXT
구문:
current_context() -> MAP
현재 실행 지점에서 사용 가능한 모든 필드로 구성된 맵을 반환합니다.
MAP_KEYS
구문:
map_keys(map: MAP) -> ARRAY<STRING>
설명:
map 값의 모든 키가 포함된 배열을 반환합니다.
MAP_VALUES
구문:
map_values(map: MAP) -> ARRAY<ANY>
설명:
map 값의 모든 값이 포함된 배열을 반환합니다.
MAP_ENTRIES
구문:
map_entries(map: MAP) -> ARRAY<MAP>
설명:
map 값의 모든 키-값 쌍이 포함된 배열을 반환합니다.
각 키-값 쌍은 k 및 v의 두 항목이 있는 맵 형식입니다.
예:
map |
map_entries(map) |
|---|---|
| {} | [] |
| {"foo" : 2L} | [{"k": "foo", "v" : 2L}] |
| {"foo" : "bar", "bar" : "foo"} | [{"k": "foo", "v" : "bar" }, {"k" : "bar", "v": "foo"}] |
문자열 함수
| 이름 | 설명 |
BYTE_LENGTH
|
STRING 또는 BYTES 값에 있는 BYTES의 수를 반환합니다.
|
CHAR_LENGTH
|
STRING 값의 유니코드 문자 수를 반환합니다.
|
STARTS_WITH
|
STRING이 지정된 프리픽스로 시작하면 TRUE를 반환합니다.
|
ENDS_WITH
|
STRING이 지정된 포스트픽스로 끝나면 TRUE를 반환합니다.
|
LIKE
|
STRING이 패턴과 일치하면 TRUE를 반환합니다.
|
REGEX_CONTAINS
|
값이 정규 표현식과 부분적으로 또는 완전히 일치하면 TRUE를 반환합니다.
|
REGEX_MATCH
|
값의 일부가 정규 표현식과 일치하면 TRUE를 반환합니다.
|
STRING_CONCAT
|
여러 STRING을 하나의 STRING으로 연결합니다.
|
STRING_CONTAINS
|
값이 STRING을 포함하는 경우 TRUE를 반환합니다.
|
STRING_INDEX_OF
|
STRING 또는 BYTES 값이 처음으로 나타나는 위치의 0부터 시작하는 색인을 반환합니다.
|
TO_UPPER
|
STRING 또는 BYTES 값을 대문자로 변환합니다.
|
TO_LOWER
|
STRING 또는 BYTES 값을 소문자로 변환합니다.
|
SUBSTRING
|
STRING 또는 BYTES 값의 하위 문자열을 가져옵니다.
|
STRING_REVERSE
|
STRING 또는 BYTES 값을 반전합니다.
|
STRING_REPEAT
|
STRING 또는 BYTES 값을 지정된 횟수만큼 반복합니다.
|
STRING_REPLACE_ALL
|
STRING 또는 BYTES 값의 모든 일치하는 항목을 대체합니다.
|
STRING_REPLACE_ONE
|
STRING 또는 BYTES 값의 첫 번째 일치하는 항목을 대체합니다.
|
TRIM
|
STRING 또는 BYTES 값에서 선행 및 후행 문자를 자릅니다.
|
LTRIM
|
STRING 또는 BYTES 값에서 선행 문자를 자릅니다.
|
RTRIM
|
STRING 또는 BYTES 값에서 후행 문자를 자릅니다.
|
SPLIT
|
STRING 또는 BYTES 값을 배열로 분할합니다.
|
BYTE_LENGTH
구문:
byte_length[T <: STRING | BYTES](value: T) -> INT64
설명:
STRING 또는 BYTES 값에 있는 BYTES의 수를 반환합니다.
예:
| 값 | byte_length(value) |
|---|---|
| "abc" | 3 |
| "xyzabc" | 6 |
| b"abc" | 3 |
Node.js
const result = await db.pipeline() .collection("books") .select( field("title").byteLength().as("titleByteLength") ) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .select( field("title").byteLength().as("titleByteLength") ) );
Swift
let result = try await db.pipeline() .collection("books") .select([ Field("title").byteLength().as("titleByteLength") ]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .select( field("title").byteLength().alias("titleByteLength") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( field("title").byteLength().alias("titleByteLength") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select(Field.of("title").byte_length().as_("titleByteLength")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(byteLength(field("title")).as("titleByteLength")) .execute() .get();
CHAR_LENGTH
구문:
char_length(value: STRING) -> INT64
설명:
STRING 값의 유니코드 코드 포인트 수를 반환합니다.
예:
| 값 | char_length(value) |
|---|---|
| "abc" | 3 |
| "hello" | 5 |
| "world" | 5 |
Node.js
const result = await db.pipeline() .collection("books") .select( field("title").charLength().as("titleCharLength") ) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .select( field("title").charLength().as("titleCharLength") ) );
Swift
let result = try await db.pipeline() .collection("books") .select([ Field("title").charLength().as("titleCharLength") ]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .select( field("title").charLength().alias("titleCharLength") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( field("title").charLength().alias("titleCharLength") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select(Field.of("title").char_length().as_("titleCharLength")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(charLength(field("title")).as("titleCharLength")) .execute() .get();
STARTS_WITH
구문:
starts_with(value: STRING, prefix: STRING) -> BOOLEAN
설명:
value가 prefix로 시작하면 TRUE를 반환합니다.
예:
| 값 | 접두사 | starts_with(value, prefix) |
|---|---|---|
| "abc" | "a" | 참 |
| "abc" | "b" | 거짓 |
| "abc" | "" | 참 |
Node.js
const result = await db.pipeline() .collection("books") .select( field("title").startsWith("The") .as("needsSpecialAlphabeticalSort") ) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .select( field("title").startsWith("The") .as("needsSpecialAlphabeticalSort") ) );
Swift
let result = try await db.pipeline() .collection("books") .select([ Field("title").startsWith("The") .as("needsSpecialAlphabeticalSort") ]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .select( field("title").startsWith("The") .alias("needsSpecialAlphabeticalSort") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( field("title").startsWith("The") .alias("needsSpecialAlphabeticalSort") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select( Field.of("title").starts_with("The").as_("needsSpecialAlphabeticalSort") ) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(startsWith(field("title"), "The").as("needsSpecialAlphabeticalSort")) .execute() .get();
ENDS_WITH
구문:
ends_with(value: STRING, postfix: STRING) -> BOOLEAN
설명:
value가 postfix로 끝나면 TRUE를 반환합니다.
예:
| 값 | postfix | ends_with(value, postfix) |
|---|---|---|
| "abc" | "c" | 참 |
| "abc" | "b" | 거짓 |
| "abc" | "" | 참 |
Node.js
const result = await db.pipeline() .collection("inventory/devices/laptops") .select( field("name").endsWith("16 inch") .as("16InLaptops") ) .execute();
Swift
let result = try await db.pipeline() .collection("inventory/devices/laptops") .select([ Field("name").endsWith("16 inch") .as("16InLaptops") ]) .execute()
Kotlin
val result = db.pipeline() .collection("inventory/devices/laptops") .select( field("name").endsWith("16 inch") .alias("16InLaptops") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("inventory/devices/laptops") .select( field("name").endsWith("16 inch") .alias("16InLaptops") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("inventory/devices/laptops") .select(Field.of("name").ends_with("16 inch").as_("16InLaptops")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("inventory/devices/laptops") .select(endsWith(field("name"), "16 inch").as("16InLaptops")) .execute() .get();
LIKE
구문:
like(value: STRING, pattern: STRING) -> BOOLEAN
설명:
value가 pattern과 일치하면 TRUE를 반환합니다.
예:
| 값 | 패턴 | like(value, pattern) |
|---|---|---|
| "Firestore" | "Fire%" | 참 |
| "Firestore" | "%store" | 참 |
| "Datastore" | "Data_tore" | 참 |
| "100%" | "100\%" | 참 |
Node.js
const result = await db.pipeline() .collection("books") .select( field("genre").like("%Fiction") .as("anyFiction") ) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .select( field("genre").like("%Fiction") .as("anyFiction") ) );
Swift
let result = try await db.pipeline() .collection("books") .select([ Field("genre").like("%Fiction") .as("anyFiction") ]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .select( field("genre").like("%Fiction") .alias("anyFiction") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( field("genre").like("%Fiction") .alias("anyFiction") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select(Field.of("genre").like("%Fiction").as_("anyFiction")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(like(field("genre"), "%Fiction").as("anyFiction")) .execute() .get();
REGEX_CONTAINS
구문:
regex_contains(value: STRING, pattern: STRING) -> BOOLEAN
설명:
value의 일부가 pattern과 일치하면 TRUE를 반환합니다. pattern이 유효한 정규 표현식이 아니면 이 함수는 error를 반환합니다.
정규 표현식은 re2 라이브러리의 구문을 따릅니다.
예:
| 값 | 패턴 | regex_contains(value, pattern) |
|---|---|---|
| "Firestore" | "Fire" | 참 |
| "Firestore" | "store$" | 참 |
| "Firestore" | "data" | 거짓 |
Node.js
const result = await db.pipeline() .collection("documents") .select( field("title").regexContains("Firestore (Enterprise|Standard)") .as("isFirestoreRelated") ) .execute();
Web
const result = await execute(db.pipeline() .collection("documents") .select( field("title").regexContains("Firestore (Enterprise|Standard)") .as("isFirestoreRelated") ) );
Swift
let result = try await db.pipeline() .collection("documents") .select([ Field("title").regexContains("Firestore (Enterprise|Standard)") .as("isFirestoreRelated") ]) .execute()
Kotlin
val result = db.pipeline() .collection("documents") .select( field("title").regexContains("Firestore (Enterprise|Standard)") .alias("isFirestoreRelated") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("documents") .select( field("title").regexContains("Firestore (Enterprise|Standard)") .alias("isFirestoreRelated") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("documents") .select( Field.of("title") .regex_contains("Firestore (Enterprise|Standard)") .as_("isFirestoreRelated") ) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("documents") .select( regexContains(field("title"), "Firestore (Enterprise|Standard)") .as("isFirestoreRelated")) .execute() .get();
REGEX_MATCH
구문:
regex_match(value: STRING, pattern: STRING) -> BOOLEAN
설명:
value가 pattern과 완전히 일치하면 TRUE를 반환합니다. pattern이 유효한 정규 표현식이 아니면 이 함수는 error를 반환합니다.
정규 표현식은 re2 라이브러리의 구문을 따릅니다.
예:
| 값 | 패턴 | regex_match(value, pattern) |
|---|---|---|
| "Firestore" | "F.*store" | 참 |
| "Firestore" | "Fire" | 거짓 |
| "Firestore" | "^F.*e$" | 참 |
Node.js
const result = await db.pipeline() .collection("documents") .select( field("title").regexMatch("Firestore (Enterprise|Standard)") .as("isFirestoreExactly") ) .execute();
Web
const result = await execute(db.pipeline() .collection("documents") .select( field("title").regexMatch("Firestore (Enterprise|Standard)") .as("isFirestoreExactly") ) );
Swift
let result = try await db.pipeline() .collection("documents") .select([ Field("title").regexMatch("Firestore (Enterprise|Standard)") .as("isFirestoreExactly") ]) .execute()
Kotlin
val result = db.pipeline() .collection("documents") .select( field("title").regexMatch("Firestore (Enterprise|Standard)") .alias("isFirestoreExactly") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("documents") .select( field("title").regexMatch("Firestore (Enterprise|Standard)") .alias("isFirestoreExactly") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("documents") .select( Field.of("title") .regex_match("Firestore (Enterprise|Standard)") .as_("isFirestoreExactly") ) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("documents") .select( regexMatch(field("title"), "Firestore (Enterprise|Standard)") .as("isFirestoreExactly")) .execute() .get();
STRING_CONCAT
구문:
string_concat(values: STRING...) -> STRING
설명:
둘 이상의 STRING 값을 하나의 결과로 연결합니다.
예:
| 인수 | string_concat(values...) |
|---|---|
() |
오류 |
("a") |
"a" |
("abc", "def") |
"abcdef" |
("a", "", "c") |
"ac" |
Node.js
const result = await db.pipeline() .collection("books") .select( field("title").stringConcat(" by ", field("author")) .as("fullyQualifiedTitle") ) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .select( field("title").stringConcat(" by ", field("author")) .as("fullyQualifiedTitle") ) );
Swift
let result = try await db.pipeline() .collection("books") .select([ Field("title").concat([" by ", Field("author")]) .as("fullyQualifiedTitle") ]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .select( field("title").concat(" by ", field("author")) .alias("fullyQualifiedTitle") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( field("title").concat(" by ", field("author")) .alias("fullyQualifiedTitle") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select( Field.of("title") .concat(" by ", Field.of("author")) .as_("fullyQualifiedTitle") ) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(stringConcat(field("title"), " by ", field("author")).as("fullyQualifiedTitle")) .execute() .get();
STRING_CONTAINS
구문:
string_contains(value: STRING, substring: STRING) -> BOOLEAN
설명:
value에 리터럴 문자열 substring이 포함되어 있는지 확인합니다.
예:
| 값 | substring | string_contains(value, substring) |
|---|---|---|
| "abc" | "b" | 참 |
| "abc" | "d" | 거짓 |
| "abc" | "" | 참 |
| "a.c" | "." | 참 |
| "☃☃☃" | "☃" | 참 |
Node.js
const result = await db.pipeline() .collection("articles") .select( field("body").stringContains("Firestore") .as("isFirestoreRelated") ) .execute();
Web
const result = await execute(db.pipeline() .collection("articles") .select( field("body").stringContains("Firestore") .as("isFirestoreRelated") ) );
Swift
let result = try await db.pipeline() .collection("articles") .select([ Field("body").stringContains("Firestore") .as("isFirestoreRelated") ]) .execute()
Kotlin
val result = db.pipeline() .collection("articles") .select( field("body").stringContains("Firestore") .alias("isFirestoreRelated") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("articles") .select( field("body").stringContains("Firestore") .alias("isFirestoreRelated") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("articles") .select(Field.of("body").string_contains("Firestore").as_("isFirestoreRelated")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("articles") .select(stringContains(field("body"), "Firestore").as("isFirestoreRelated")) .execute() .get();
STRING_INDEX_OF
구문:
string_index_of[T <: STRING | BYTES](value: T, search: T) -> INT64
설명:
value에서 search가 처음으로 나타나는 위치의 0부터 시작하는 색인을 반환합니다.
search를 찾을 수 없으면-1을 반환합니다.value가STRING값인 경우 결과는 유니코드 코드 포인트로 측정됩니다.BYTES값인 경우 바이트로 측정됩니다.search가 빈STRING또는BYTES값인 경우 결과는0입니다.
예:
| 값 | 검색 | string_index_of(value, search) |
|---|---|---|
| "hello world" | "o" | 4 |
| "hello world" | "l" | 2 |
| "hello world" | "z" | -1 |
| "banana" | "na" | 2 |
| "abc" | "" | 0 |
| b"abc" | b"b" | 1 |
| "é" | "é" | 0 |
| b"é" | b"é" | 0 |
TO_UPPER
구문:
to_upper[T <: STRING | BYTES](value: T) -> T
설명:
STRING 또는 BYTES 값을 대문자로 변환합니다.
바이트 또는 문자가 UTF-8 소문자 알파벳 문자에 해당하지 않으면 변경되지 않고 전달됩니다.
예:
| 값 | to_upper(value) |
|---|---|
| "abc" | "ABC" |
| "AbC" | "ABC" |
| b"abc" | b"ABC" |
| b"a1c" | b"A1C" |
Node.js
const result = await db.pipeline() .collection("authors") .select( field("name").toUpper() .as("uppercaseName") ) .execute();
Web
const result = await execute(db.pipeline() .collection("authors") .select( field("name").toUpper() .as("uppercaseName") ) );
Swift
let result = try await db.pipeline() .collection("authors") .select([ Field("name").toUpper() .as("uppercaseName") ]) .execute()
Kotlin
val result = db.pipeline() .collection("authors") .select( field("name").toUpper() .alias("uppercaseName") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("authors") .select( field("name").toUpper() .alias("uppercaseName") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("authors") .select(Field.of("name").to_upper().as_("uppercaseName")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("authors") .select(toUpper(field("name")).as("uppercaseName")) .execute() .get();
TO_LOWER
구문:
to_lower[T <: STRING | BYTES](value: T) -> T
설명:
STRING 또는 BYTES 값을 소문자로 변환합니다.
바이트 또는 문자가 UTF-8 대문자 알파벳 문자에 해당하지 않으면 변경되지 않고 전달됩니다.
예:
| 값 | to_lower(value) |
|---|---|
| "ABC" | "abc" |
| "AbC" | "abc" |
| "A1C" | "a1c" |
| b"ABC" | b"abc" |
Node.js
const result = await db.pipeline() .collection("authors") .select( field("genre").toLower().equal("fantasy") .as("isFantasy") ) .execute();
Web
const result = await execute(db.pipeline() .collection("authors") .select( field("genre").toLower().equal("fantasy") .as("isFantasy") ) );
Swift
let result = try await db.pipeline() .collection("authors") .select([ Field("genre").toLower().equal("fantasy") .as("isFantasy") ]) .execute()
Kotlin
val result = db.pipeline() .collection("authors") .select( field("genre").toLower().equal("fantasy") .alias("isFantasy") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("authors") .select( field("genre").toLower().equal("fantasy") .alias("isFantasy") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("authors") .select(Field.of("genre").to_lower().equal("fantasy").as_("isFantasy")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("authors") .select(equal(toLower(field("genre")), "fantasy").as("isFantasy")) .execute() .get();
SUBSTRING
구문:
substring[T <: STRING | BYTES](input: T, position: INT64) -> T
substring[T <: STRING | BYTES](input: T, position: INT64, length: INT64) -> T
설명:
position(0부터 시작하는 색인)에서 시작하여 최대 length 항목을 포함하는 input의 하위 문자열을 반환합니다. length가 제공되지 않으면 position부터 input 끝까지의 하위 문자열을 반환합니다.
input이STRING값인 경우position및length는 유니코드 코드 포인트로 측정됩니다.BYTES값인 경우 바이트로 측정됩니다.position이input의 길이보다 크면 빈 하위 문자열이 반환됩니다.position더하기length가input의 길이보다 크면 하위 문자열이input의 끝으로 잘립니다.position이 음수이면 입력의 끝에서 위치를 가져옵니다. 음수position이 입력 크기보다 크면 위치가 0으로 설정됩니다.length는 음수가 아니어야 합니다.
예:
length가 제공되지 않는 경우:
| 입력 | 위치 | substring(input, position) |
|---|---|---|
| "abc" | 0 | "abc" |
| "abc" | 1 | "bc" |
| "abc" | 3 | "" |
| "abc" | -1 | "c" |
| b"abc" | 1 | b"bc" |
length가 제공되는 경우:
| 입력 | 위치 | 길이 | substring(input, position, length) |
|---|---|---|---|
| "abc" | 0 | 1 | "a" |
| "abc" | 1 | 2 | "bc" |
| "abc" | -1 | 1 | "c" |
| b"abc" | 0 | 1 | b"a" |
Node.js
const result = await db.pipeline() .collection("books") .where(field("title").startsWith("The ")) .select( field("title").substring(4) .as("titleWithoutLeadingThe") ) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .where(field("title").startsWith("The ")) .select( field("title").substring(4) .as("titleWithoutLeadingThe") ) );
Swift
let result = try await db.pipeline() .collection("books") .where(Field("title").startsWith("The ")) .select([ Field("title").substring(position: 4) .as("titleWithoutLeadingThe") ]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .where(field("title").startsWith("The ")) .select( field("title") .substring(constant(4), field("title").charLength().subtract(4)) .alias("titleWithoutLeadingThe") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .where(field("title").startsWith("The ")) .select( field("title").substring( constant(4), field("title").charLength().subtract(4)) .alias("titleWithoutLeadingThe") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .where(Field.of("title").starts_with("The ")) .select(Field.of("title").substring(4).as_("titleWithoutLeadingThe")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .where(startsWith(field("title"), "The ")) .select( substring(field("title"), constant(4), field("title").charLength()) .as("titleWithoutLeadingThe")) .execute() .get();
STRING_REVERSE
구문:
string_reverse[T <: STRING | BYTES](input: T) -> T
설명:
제공된 입력을 역순으로 반환합니다.
입력이 STRING인 경우 문자는 유니코드 코드 포인트로 구분되고, 입력이 BYTES 값인 경우 바이트로 구분됩니다.
예:
| 입력 | string_reverse(input) |
|---|---|
| "abc" | "cba" |
| "a🌹b" | "b🌹a" |
| "hello" | "olleh" |
| b"abc" | b"cba" |
Node.js
const result = await db.pipeline() .collection("books") .select( field("name").reverse().as("reversedName") ) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .select( field("name").reverse().as("reversedName") ) );
Swift
let result = try await db.pipeline() .collection("books") .select([ Field("name").reverse().as("reversedName") ]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .select( field("name").reverse().alias("reversedName") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( field("name").reverse().alias("reversedName") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select(Field.of("name").string_reverse().as_("reversedName")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(reverse(field("name")).as("reversedName")) .execute() .get();
STRING_REPEAT
구문:
string_repeat[T <: STRING | BYTES](input: T, repetitions: INT64) -> T
설명:
input을 repetitions번 반복한 값을 반환합니다.
repetitions은 음이 아닌 정수여야 합니다.repetitions이0이면input과 동일한 유형의 빈 값을 반환합니다.- 결과가 허용되는 최대 크기(1MB)를 초과하면 오류가 반환됩니다.
예:
| 입력 | 반복 | string_repeat(input, repetitions) |
|---|---|---|
| 'foo' | 3 | "foofoofoo" |
| 'foo' | 0 | "" |
| "a " | 3 | "a a a " |
| b"ab" | 2 | b"abab" |
| "é🦆" | 2 | "é🦆é🦆" |
STRING_REPLACE_ALL
구문:
string_replace_all[T <: STRING | BYTES](input: T, find: T, replacement: T) -> T
설명:
input에서 find의 겹치지 않는 모든 일치하는 항목을 replacement로 바꿉니다.
- 일치 항목은 대소문자를 구분합니다.
find가 비어 있으면 값이 바뀌지 않습니다.
예:
| 입력 | find | replacement | string_replace_all(input, find, replacement) |
|---|---|---|---|
| "foobarfoo" | 'foo' | 'baz' | "bazbarbaz" |
| "ababab" | "aba" | "c" | "cbab" |
| "foobar" | "o" | "" | "fbar" |
| "é🦆🌎🦆" | "🦆" | "a" | "éa🌎a" |
| b"abc" | b"b" | b"d" | b"adc" |
STRING_REPLACE_ONE
구문:
string_replace_one[T <: STRING | BYTES](input: T, find: T, replacement: T) -> T
설명:
input에서 find의 첫 번째 일치하는 항목을 replacement로 바꿉니다.
- 일치 항목은 대소문자를 구분합니다.
find가 비어 있으면 값이 바뀌지 않습니다.
예:
| 입력 | find | replacement | string_replace_one(input, find, replacement) |
|---|---|---|---|
| "foobarfoo" | 'foo' | 'baz' | "bazbarfoo" |
| "é" | "é" | "a" | "a" |
| b"foobar" | b"o" | b"z" | b"fzoobar" |
TRIM
구문:
trim[T <: STRING | BYTES](input: T, values_to_trim: T) -> T
trim[T <: STRING | BYTES](input: T) -> T
설명:
제공된 input의 시작과 끝에서 지정된 BYTES 또는 CHARS 집합을 자릅니다.
values_to_trim이 제공되지 않으면 공백 문자를 자릅니다.
예:
values_to_trim가 제공되지 않는 경우:
| 입력 | trim(input) |
|---|---|
| " foo " | 'foo' |
| b" foo " | b"foo" |
| 'foo' | 'foo' |
| "" | "" |
| " " | "" |
| "\t foo \n" | 'foo' |
| b"\t foo \n" | b"foo" |
| "\r\f\v foo \r\f\v" | 'foo' |
| b"\r\f\v foo \r\f\v" | b"foo" |
values_to_trim이 제공되는 경우:
| 입력 | values_to_trim | trim(input, values_to_trim) |
|---|---|---|
| "abcbfooaacb" | "abc" | 'foo' |
| "abcdaabadbac" | "abc" | "daabad" |
| b"C1C2C3" | b"C1" | b"C2C3" |
| b"C1C2" | 'foo' | 오류 |
| 'foo' | b"C1" | 오류 |
Web
const result = await execute(db.pipeline() .collection("books") .select( field("name").trim().as("whitespaceTrimmedName") ) );
Swift
let result = try await db.pipeline() .collection("books") .select([ Field("name").trim(" \n\t").as("whitespaceTrimmedName") ]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .select( field("name").trim().alias("whitespaceTrimmedName") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( field("name").trim().alias("whitespaceTrimmedName") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select(Field.of("name").trim().as_("whitespaceTrimmedName")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(trim(field("name")).as("whitespaceTrimmedName")) .execute() .get();
LTRIM
구문:
ltrim[T <: STRING | BYTES](value: T, to_trim: T) -> T
ltrim[T <: STRING | BYTES](value: T) -> T
설명:
제공된 value의 시작에서 지정된 BYTES 또는 CHARS 집합을 자릅니다.
to_trim이 제공되지 않으면 선행 공백 문자를 자릅니다.
예:
to_trim가 제공되지 않는 경우:
| 값 | ltrim(value) |
|---|---|
| " foo " | "foo " |
| 'foo' | 'foo' |
to_trim가 제공되는 경우:
| 값 | to_trim | ltrim(value, to_trim) |
|---|---|---|
| "aaabc" | "a" | "bc" |
| "abacaba" | 'ba' | "caba" |
| "é" | "é" | "" |
RTRIM
구문:
rtrim[T <: STRING | BYTES](value: T, to_trim: T) -> T
rtrim[T <: STRING | BYTES](value: T) -> T
설명:
제공된 value의 끝에서 지정된 BYTES 또는 CHARS 집합을 자릅니다.
to_trim이 제공되지 않으면 후행 공백 문자를 자릅니다.
예:
to_trim가 제공되지 않는 경우:
| 값 | rtrim(value) |
|---|---|
| " foo " | " foo" |
| 'foo' | 'foo' |
to_trim가 제공되는 경우:
| 값 | to_trim | rtrim(value, to_trim) |
|---|---|---|
| "abccc" | "c" | "ab" |
| "abacaba" | 'ba' | "abac" |
| "é" | "é" | "" |
SPLIT
구문:
split(input: STRING) -> ARRAY<STRING>
split[T <: STRING | BYTES](input: T, delimiter: T) -> ARRAY<T>
설명:
구분자를 사용하여 STRING 또는 BYTES 값을 분할합니다.
STRING에서 기본 구분자는 쉼표(,)입니다. 구분자는 단일 문자열로 처리됩니다.BYTES에서는 구분 기호를 지정해야 합니다.비어 있는 구분자로 분할하면
STRING값의 경우에는 유니코드 코드 포인트 배열이,BYTES값의 경우에는BYTES의 배열이 생성됩니다.비어 있는
STRING을 분할하면 비어 있는STRING이 하나 있는ARRAY가 반환됩니다.
예:
delimiter가 제공되지 않는 경우:
| 입력 | split(input) |
|---|---|
| "foo,bar,foo" | ["foo", "bar", "foo"] |
| 'foo' | ["foo"] |
| ",foo," | ["", "foo", ""] |
| "" | [""] |
| b"C120C2C4" | 오류 |
delimiter가 제공되는 경우:
| 입력 | 구분자 | split(input, delimiter) |
|---|---|---|
| "foo bar foo" | " " | ["foo", "bar", "foo"] |
| "foo bar foo" | "z" | ["foo bar foo"] |
| "abc" | "" | ["a", "b", "c"] |
| b"C1,C2,C4" | b"," | [b"C1", b"C2", b"C4"] |
| b"ABC" | b"" | [b"A", b"B", b"C"] |
| 'foo' | b"C1" | 오류 |
타임스탬프 함수
| 이름 | 설명 |
CURRENT_TIMESTAMP
|
요청 시간에 해당하는 TIMESTAMP를 생성합니다.
|
TIMESTAMP_TRUNC
|
TIMESTAMP를 지정된 단위로 자릅니다.
|
UNIX_MICROS_TO_TIMESTAMP
|
1970-01-01 00:00:00 UTC 이후의 마이크로초 수를 TIMESTAMP로 변환합니다.
|
UNIX_MILLIS_TO_TIMESTAMP
|
1970-01-01 00:00:00 UTC 이후의 밀리초 수를 TIMESTAMP로 변환합니다.
|
UNIX_SECONDS_TO_TIMESTAMP
|
1970-01-01 00:00:00 UTC 이후의 초 수를 TIMESTAMP로 변환합니다.
|
TIMESTAMP_ADD
|
TIMESTAMP에 시간 간격을 추가합니다.
|
TIMESTAMP_SUB
|
시간 간격을 TIMESTAMP로 뺍니다.
|
TIMESTAMP_TO_UNIX_MICROS
|
TIMESTAMP를 1970-01-01 00:00:00 UTC 이후의 마이크로초 수로 변환합니다.
|
TIMESTAMP_TO_UNIX_MILLIS
|
TIMESTAMP를 1970-01-01 00:00:00 UTC 이후의 밀리초 수로 변환합니다.
|
TIMESTAMP_TO_UNIX_SECONDS
|
TIMESTAMP를 1970-01-01 00:00:00 UTC 이후의 초 수로 변환합니다.
|
TIMESTAMP_DIFF
|
두 TIMESTAMP 사이의 지정된 unit 간격의 정수를 반환합니다.
|
TIMESTAMP_EXTRACT
|
TIMESTAMP에서 특정 part(예: 연도, 월, 일)를 추출합니다.
|
CURRENT_TIMESTAMP
구문:
current_timestamp() -> TIMESTAMP
설명:
요청 시간 input의 시작 부분에 있는 타임스탬프를 가져옵니다(1970-01-01 00:00:00 UTC 이후의 마이크로초 수로 해석됨).
이는 쿼리 내에서 안정적이며 여러 번 호출해도 항상 동일한 값으로 확인됩니다.
TIMESTAMP_TRUNC
구문:
timestamp_trunc(timestamp: TIMESTAMP, granularity: STRING[, timezone: STRING]) -> TIMESTAMP
설명:
타임스탬프를 지정된 단위로 자릅니다.
granularity 인수는 문자열이어야 하며 다음 중 하나여야 합니다.
microsecondmillisecondsecondminutehourdayweekweek([weekday])monthquarteryearisoyear
timezone 인수가 제공되면 지정된 시간대의 캘린더 경계(예: 지정된 시간대의 자정으로 잘리는 일)를 기준으로 잘립니다. 잘림은 일광 절약 시간을 고려합니다.
timezone이 제공되지 않으면 UTC 캘린더 경계를 기준으로 잘립니다.
timezone 인수는 tz 데이터베이스의 시간대 문자열 표현이어야 합니다(예: America/New_York). GMT의 오프셋을 지정하여 커스텀 타임스탬프를 사용할 수도 있습니다.
예:
timestamp |
granularity |
timezone |
timestamp_trunc(timestamp, granularity, timezone) |
|---|---|---|---|
| 2000-01-01 10:20:30:123456 UTC | 'second' | 입력하지 않음 | 2001-01-01 10:20:30 UTC |
| 1997-05-31 04:30:30 UTC | 'day' | 입력하지 않음 | 1997-05-31 00:00:00 UTC |
| 1997-05-31 04:30:30 UTC | 'day' | 'America/Los_Angeles' | 1997-05-30 07:00:00 UTC |
| 2001-03-16 04:00:00 UTC | 'week(friday)' | 입력하지 않음 | 2001-03-16 00:00:00 UTC |
| 2001-03-23 04:00:00 UTC | 'week(friday)' | 'America/Los_Angeles' | 2001-03-23 17:00:00 UTC |
| 2026-01-24 20:00:00 UTC | 'month' | 'GMT+06:32:43' | 2026-01-01T06:32:43 UTC |
UNIX_MICROS_TO_TIMESTAMP
구문:
unix_micros_to_timestamp(input: INT64) -> TIMESTAMP
설명:
input(1970-01-01 00:00:00 UTC 이후의 마이크로초 수로 해석됨)을 TIMESTAMP로 변환합니다. input을 유효한 TIMESTAMP로 변환할 수 없는 경우 error가 발생합니다.
예:
input |
unix_micros_to_timestamp(input) |
|---|---|
| 0L | 1970-01-01 00:00:00 UTC |
| 400123456L | 1970-01-01 00:06:40.123456 UTC |
| -1000000L | 1969-12-31 23:59:59 UTC |
Node.js
const result = await db.pipeline() .collection("documents") .select( field("createdAtMicros").unixMicrosToTimestamp().as("createdAtString") ) .execute();
Web
const result = await execute(db.pipeline() .collection("documents") .select( field("createdAtMicros").unixMicrosToTimestamp().as("createdAtString") ) );
Swift
let result = try await db.pipeline() .collection("documents") .select([ Field("createdAtMicros").unixMicrosToTimestamp().as("createdAtString") ]) .execute()
Kotlin
val result = db.pipeline() .collection("documents") .select( field("createdAtMicros").unixMicrosToTimestamp().alias("createdAtString") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("documents") .select( field("createdAtMicros").unixMicrosToTimestamp().alias("createdAtString") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("documents") .select( Field.of("createdAtMicros") .unix_micros_to_timestamp() .as_("createdAtString") ) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("documents") .select(unixMicrosToTimestamp(field("createdAtMicros")).as("createdAtString")) .execute() .get();
UNIX_MILLIS_TO_TIMESTAMP
구문:
unix_millis_to_timestamp(input: INT64) -> TIMESTAMP
설명:
input(1970-01-01 00:00:00 UTC 이후의 밀리초 수로 해석됨)을 TIMESTAMP로 변환합니다. input을 유효한 TIMESTAMP로 변환할 수 없는 경우 error가 발생합니다.
예:
input |
unix_millis_to_timestamp(input) |
|---|---|
| 0L | 1970-01-01 00:00:00 UTC |
| 4000123L | 1970-01-01 01:06:40.123 UTC |
| -1000000L | 1969-12-31 23:43:20 UTC |
Node.js
const result = await db.pipeline() .collection("documents") .select( field("createdAtMillis").unixMillisToTimestamp().as("createdAtString") ) .execute();
Web
const result = await execute(db.pipeline() .collection("documents") .select( field("createdAtMillis").unixMillisToTimestamp().as("createdAtString") ) );
Swift
let result = try await db.pipeline() .collection("documents") .select([ Field("createdAtMillis").unixMillisToTimestamp().as("createdAtString") ]) .execute()
Kotlin
val result = db.pipeline() .collection("documents") .select( field("createdAtMillis").unixMillisToTimestamp().alias("createdAtString") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("documents") .select( field("createdAtMillis").unixMillisToTimestamp().alias("createdAtString") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("documents") .select( Field.of("createdAtMillis") .unix_millis_to_timestamp() .as_("createdAtString") ) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("documents") .select(unixMillisToTimestamp(field("createdAtMillis")).as("createdAtString")) .execute() .get();
UNIX_SECONDS_TO_TIMESTAMP
구문:
unix_seconds_to_timestamp(input: INT64) -> TIMESTAMP
설명:
input(1970-01-01 00:00:00 UTC 이후의 초 수로 해석됨)를 TIMESTAMP로 변환합니다. input을 유효한 TIMESTAMP로 변환할 수 없는 경우 error가 발생합니다.
예:
input |
unix_seconds_to_timestamp(input) |
|---|---|
| 0L | 1970-01-01 00:00:00 UTC |
| 60L | 1970-01-01 00:01:00 UTC |
| -300L | 1969-12-31 23:55:00 UTC |
Node.js
const result = await db.pipeline() .collection("documents") .select( field("createdAtSeconds").unixSecondsToTimestamp().as("createdAtString") ) .execute();
Web
const result = await execute(db.pipeline() .collection("documents") .select( field("createdAtSeconds").unixSecondsToTimestamp().as("createdAtString") ) );
Swift
let result = try await db.pipeline() .collection("documents") .select([ Field("createdAtSeconds").unixSecondsToTimestamp().as("createdAtString") ]) .execute()
Kotlin
val result = db.pipeline() .collection("documents") .select( field("createdAtSeconds").unixSecondsToTimestamp().alias("createdAtString") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("documents") .select( field("createdAtSeconds").unixSecondsToTimestamp().alias("createdAtString") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("documents") .select( Field.of("createdAtSeconds") .unix_seconds_to_timestamp() .as_("createdAtString") ) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("documents") .select(unixSecondsToTimestamp(field("createdAtSeconds")).as("createdAtString")) .execute() .get();
TIMESTAMP_ADD
구문:
timestamp_add(timestamp: TIMESTAMP, unit: STRING, amount: INT64) -> TIMESTAMP
설명:
timestamp에서 unit의 amount를 추가합니다. amount 인수는 음수일 수 있으며, 이 경우 TIMESTAMP_SUB와 동일합니다.
unit 인수는 문자열이어야 하며 다음 중 하나여야 합니다.
microsecondmillisecondsecondminutehourday
결과 타임스탬프가 TIMESTAMP 범위에 맞지 않으면 오류가 발생합니다.
예:
timestamp |
unit |
amount |
timestamp_add(timestamp, unit, amount) |
|---|---|---|---|
| 2025-02-20 00:00:00 UTC | 'minute' | 2L | 2025-02-20 00:02:00 UTC |
| 2025-02-20 00:00:00 UTC | 'hour' | -4L | 2025-02-19 20:00:00 UTC |
| 2025-02-20 00:00:00 UTC | 'day' | 5L | 2025-02-25 00:00:00 UTC |
Node.js
const result = await db.pipeline() .collection("documents") .select( field("createdAt").timestampAdd("day", 3653).as("expiresAt") ) .execute();
Web
const result = await execute(db.pipeline() .collection("documents") .select( field("createdAt").timestampAdd("day", 3653).as("expiresAt") ) );
Swift
let result = try await db.pipeline() .collection("documents") .select([ Field("createdAt").timestampAdd(3653, .day).as("expiresAt") ]) .execute()
Kotlin
val result = db.pipeline() .collection("documents") .select( field("createdAt") .timestampAdd("day", 3653) .alias("expiresAt") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("documents") .select( field("createdAt").timestampAdd("day", 3653).alias("expiresAt") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("documents") .select(Field.of("createdAt").timestamp_add("day", 3653).as_("expiresAt")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("documents") .select(timestampAdd(field("createdAt"), "day", 3653).as("expiresAt")) .execute() .get();
TIMESTAMP_SUB
구문:
timestamp_sub(timestamp: TIMESTAMP, unit: STRING, amount: INT64) -> TIMESTAMP
설명:
timestamp에서 unit의 amount를 뺍니다. amount 인수는 음수일 수 있으며, 이 경우 TIMESTAMP_ADD와 동일합니다.
unit 인수는 문자열이어야 하며 다음 중 하나여야 합니다.
microsecondmillisecondsecondminutehourday
결과 타임스탬프가 TIMESTAMP 범위에 맞지 않으면 오류가 발생합니다.
예:
timestamp |
unit |
amount |
timestamp_sub(timestamp, unit, amount) |
|---|---|---|---|
| 2026-07-04 00:00:00 UTC | 'minute' | 40L | 2026-07-03 23:20:00 UTC |
| 2026-07-04 00:00:00 UTC | 'hour' | -24L | 2026-07-05 00:00:00 UTC |
| 2026-07-04 00:00:00 UTC | 'day' | 3L | 2026-07-01 00:00:00 UTC |
Node.js
const result = await db.pipeline() .collection("documents") .select( field("expiresAt").timestampSubtract("day", 14).as("sendWarningTimestamp") ) .execute();
Web
const result = await execute(db.pipeline() .collection("documents") .select( field("expiresAt").timestampSubtract("day", 14).as("sendWarningTimestamp") ) );
Swift
let result = try await db.pipeline() .collection("documents") .select([ Field("expiresAt").timestampSubtract(14, .day).as("sendWarningTimestamp") ]) .execute()
Kotlin
val result = db.pipeline() .collection("documents") .select( field("expiresAt") .timestampSubtract("day", 14) .alias("sendWarningTimestamp") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("documents") .select( field("expiresAt").timestampSubtract("day", 14).alias("sendWarningTimestamp") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("documents") .select( Field.of("expiresAt") .timestamp_subtract("day", 14) .as_("sendWarningTimestamp") ) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("documents") .select(timestampSubtract(field("expiresAt"), "day", 14).as("sendWarningTimestamp")) .execute() .get();
TIMESTAMP_TO_UNIX_MICROS
구문:
timestamp_to_unix_micros(input: TIMESTAMP) -> INT64
설명:
input을 1970-01-01 00:00:00 UTC 이후의 마이크로초 수로 변환합니다. 마이크로초 시작 부분으로 반내림하여 높은 정밀도 수준을 자릅니다.
예:
input |
timestamp_to_unix_micros(input) |
|---|---|
| 1970-01-01 00:00:00 UTC | 0L |
| 1970-01-01 00:06:40.123456 UTC | 400123456L |
| 1969-12-31 23:59:59 UTC | -1000000L |
Node.js
const result = await db.pipeline() .collection("documents") .select( field("dateString").timestampToUnixMicros().as("unixMicros") ) .execute();
Web
const result = await execute(db.pipeline() .collection("documents") .select( field("dateString").timestampToUnixMicros().as("unixMicros") ) );
Swift
let result = try await db.pipeline() .collection("documents") .select([ Field("dateString").timestampToUnixMicros().as("unixMicros") ]) .execute()
Kotlin
val result = db.pipeline() .collection("documents") .select( field("dateString").timestampToUnixMicros().alias("unixMicros") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("documents") .select( field("dateString").timestampToUnixMicros().alias("unixMicros") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("documents") .select(Field.of("dateString").timestamp_to_unix_micros().as_("unixMicros")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("documents") .select(timestampToUnixMicros(field("dateString")).as("unixMicros")) .execute() .get();
TIMESTAMP_TO_UNIX_MILLIS
구문:
timestamp_to_unix_millis(input: TIMESTAMP) -> INT64
설명:
input을 1970-01-01 00:00:00 UTC 이후의 밀리초 수로 변환합니다. 밀리초 시작 부분으로 반내림하여 높은 정밀도 수준을 자릅니다.
예:
input |
timestamp_to_unix_millis(input) |
|---|---|
| 1970-01-01 00:00:00 UTC | 0L |
| 1970-01-01 01:06:40.123 UTC | 4000123L |
| 1969-12-31 23:43:20 | -1000000L |
Node.js
const result = await db.pipeline() .collection("documents") .select( field("dateString").timestampToUnixMillis().as("unixMillis") ) .execute();
Web
const result = await execute(db.pipeline() .collection("documents") .select( field("dateString").timestampToUnixMillis().as("unixMillis") ) );
Swift
let result = try await db.pipeline() .collection("documents") .select([ Field("dateString").timestampToUnixMillis().as("unixMillis") ]) .execute()
Kotlin
val result = db.pipeline() .collection("documents") .select( field("dateString").timestampToUnixMillis().alias("unixMillis") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("documents") .select( field("dateString").timestampToUnixMillis().alias("unixMillis") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("documents") .select(Field.of("dateString").timestamp_to_unix_millis().as_("unixMillis")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("documents") .select(timestampToUnixMillis(field("dateString")).as("unixMillis")) .execute() .get();
TIMESTAMP_TO_UNIX_SECONDS
구문:
timestamp_to_unix_seconds(input: TIMESTAMP) -> INT64
설명:
input을 1970-01-01 00:00:00 UTC 이후의 초 수로 변환합니다. 초 시작 부분으로 반내림하여 높은 정밀도 수준을 자릅니다.
예:
input |
timestamp_to_unix_seconds(input) |
|---|---|
| 1970-01-01 00:00:00 UTC | 0L |
| 1970-01-01 00:01:00 UTC | 60L |
| 1969-12-31 23:55:00 UTC | -300L |
Node.js
const result = await db.pipeline() .collection("documents") .select( field("dateString").timestampToUnixSeconds().as("unixSeconds") ) .execute();
Web
const result = await execute(db.pipeline() .collection("documents") .select( field("dateString").timestampToUnixSeconds().as("unixSeconds") ) );
Swift
let result = try await db.pipeline() .collection("documents") .select([ Field("dateString").timestampToUnixSeconds().as("unixSeconds") ]) .execute()
Kotlin
val result = db.pipeline() .collection("documents") .select( field("dateString").timestampToUnixSeconds().alias("unixSeconds") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("documents") .select( field("dateString").timestampToUnixSeconds().alias("unixSeconds") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("documents") .select(Field.of("dateString").timestamp_to_unix_seconds().as_("unixSeconds")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("documents") .select(timestampToUnixSeconds(field("dateString")).as("unixSeconds")) .execute() .get();
TIMESTAMP_DIFF
구문:
timestamp_diff(end: TIMESTAMP, start: TIMESTAMP, unit: STRING) -> INT64
설명:
두 TIMESTAMP 사이의 지정된 unit 간격의 정수를 반환합니다.
end가start보다 앞이면 음수 값을 반환합니다.- 분수 단위를 자릅니다. 예를 들어
timestamp_diff("2021-01-01 00:00:01", "2021-01-01 00:00:00", "minute")는0를 반환합니다.
unit 인수는 문자열이어야 하며 다음 중 하나여야 합니다.
microsecondmillisecondsecondminutehourday
예:
end |
start |
unit |
timestamp_diff(end, start, unit) |
|---|---|---|---|
| 2026-07-04 00:01:00 UTC | 2026-07-04 00:00:00 UTC | 'second' | 60L |
| 2026-07-04 00:00:00 UTC | 2026-07-05 00:00:00 UTC | 'day' | -1L |
| 2026-07-04 00:00:59 UTC | 2026-07-04 00:00:00 UTC | 'minute' | 0L |
TIMESTAMP_EXTRACT
구문:
timestamp_extract(timestamp: TIMESTAMP, part: STRING[, timezone: STRING]) -> INT64
설명:
timestamp에서 특정 part(예: 연도, 월, 일)를 추출합니다.
part 인수는 문자열이어야 하며 다음 중 하나여야 합니다.
microsecondmillisecondsecondminutehourdaydayofweek: 1(일요일)에서 7(토요일) 사이의 값을 반환합니다.dayofyearweek: 연도의 첫 번째 일요일을 1부터 시작하는 연도의 주 번호를 반환합니다.week([weekday]): 지정된weekday부터 시작하는 연도의 주 번호를 반환합니다.monthquarteryearisoweek: ISO 8601 주 번호를 반환합니다.isoyear: ISO 8601 주 번호 지정 연도를 반환합니다.
timezone 인수가 제공되면 지정된 시간대의 캘린더를 기준으로 추출됩니다. 추출은 일광 절약 시간을 고려합니다.
timezone이 제공되지 않으면 UTC를 기준으로 추출됩니다.
timezone 인수는 시간대 데이터베이스의 시간대 문자열 표현이어야 합니다(예: America/New_York). GMT의 오프셋을 지정하여 커스텀 타임스탬프를 사용할 수도 있습니다.
예:
timestamp |
part |
timezone |
timestamp_extract(timestamp, part, timezone) |
|---|---|---|---|
| 2025-02-20 10:20:30 UTC | "year" | 입력하지 않음 | 2025 |
| 2025-02-20 10:20:30 UTC | 'day' | 입력하지 않음 | 20 |
| 2025-12-31 23:59:59 UTC | "year" | "Asia/Tokyo" | 2026 |
유형 함수
| 이름 | 설명 |
TYPE
|
값의 유형을 STRING으로 반환합니다.
|
IS_TYPE
|
값이 지정된 유형과 일치하면 true를 반환합니다.
|
TYPE
구문:
type(input: ANY) -> STRING
설명:
input 유형의 문자열 표현을 반환합니다.
값이 없는 경우 NULL을 반환합니다.
예:
input |
type(input) |
|---|---|
| NULL | "null" |
| 참 | "boolean" |
| 1 | "int32" |
| -3L | "int64" |
| 3.14 | "float64" |
| 2024-01-01T00:00:00Z UTC | "timestamp" |
| 'foo' | "string" |
| b"foo" | "bytes" |
| [1, 2] | "array" |
| {"a": 1} | "map" |
path("c/d") |
"reference" |
vector([1.0, 2.0]) |
"vector" |
| ABSENT | NULL |
클라이언트 예시
Node.js
const result = await db.pipeline() .collection("books") .select(field("title").notEqual("1984").as("not1984")) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .select(field("title").notEqual("1984").as("not1984")) );
Swift
let result = try await db.pipeline() .collection("books") .select([Field("title").notEqual("1984").as("not1984")]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .select(field("title").notEqual("1984").alias("not1984")) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select(field("title").notEqual("1984").alias("not1984")) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select(Field.of("title").not_equal("1984").as_("not1984")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(notEqual(field("title"), "1984").as("not1984")) .execute() .get();
IS_TYPE
구문:
is_type(input: ANY, type: STRING) -> BOOLEAN
설명:
input이 지정된 type과 일치하면 true를 반환하고, 그렇지 않으면 false를 반환합니다.
input이 없는 경우 NULL을 반환합니다.
지원되는 type 문자열은 다음과 같습니다.
"null""boolean""int32""int64""float64""decimal128""number""timestamp""string""bytes""array""map""reference""vector""geo_point""max_key""min_key""object_id""regex""bson_timestamp"
예:
input |
type |
is_type(input, type) |
|---|---|---|
| NULL | "null" | 참 |
| 참 | "boolean" | 참 |
| 3.14 | "float64" | 참 |
| 'foo' | "string" | 참 |
| b"foo" | "string" | 거짓 |
| [1, 2] | "array" | 참 |
| {"a": 1} | "map" | 참 |
vector([1.0, 2.0]) |
"vector" | 참 |
| ABSENT | "string" | NULL |
| 'bar' | "other" | 오류 |
벡터 함수
| 이름 | 설명 |
COSINE_DISTANCE
|
두 벡터 간의 코사인 거리를 반환합니다. |
DOT_PRODUCT
|
두 벡터 간의 내적을 반환합니다. |
EUCLIDEAN_DISTANCE
|
두 벡터 간의 유클리드 거리를 반환합니다. |
MANHATTAN_DISTANCE
|
두 벡터 간의 맨해튼 거리를 반환합니다. |
VECTOR_LENGTH
|
벡터의 요소 수를 반환합니다. |
COSINE_DISTANCE
구문:
cosine_distance(x: VECTOR, y: VECTOR) -> FLOAT64
설명:
x와 y 사이의 코사인 거리를 반환합니다.
Node.js
const sampleVector = [0.0, 1, 2, 3, 4, 5]; const result = await db.pipeline() .collection("books") .select( field("embedding").cosineDistance(sampleVector).as("cosineDistance") ) .execute();
Web
const sampleVector = [0.0, 1, 2, 3, 4, 5]; const result = await execute(db.pipeline() .collection("books") .select( field("embedding").cosineDistance(sampleVector).as("cosineDistance")));
Swift
let sampleVector = [0.0, 1, 2, 3, 4, 5] let result = try await db.pipeline() .collection("books") .select([ Field("embedding").cosineDistance(sampleVector).as("cosineDistance") ]) .execute()
Kotlin
val sampleVector = doubleArrayOf(0.0, 1.0, 2.0, 3.0, 4.0, 5.0) val result = db.pipeline() .collection("books") .select( field("embedding").cosineDistance(sampleVector).alias("cosineDistance") ) .execute()
Java
double[] sampleVector = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0}; Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( field("embedding").cosineDistance(sampleVector).alias("cosineDistance") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field from google.cloud.firestore_v1.vector import Vector sample_vector = Vector([0.0, 1.0, 2.0, 3.0, 4.0, 5.0]) result = ( client.pipeline() .collection("books") .select( Field.of("embedding").cosine_distance(sample_vector).as_("cosineDistance") ) .execute() )
자바
double[] sampleVector = new double[] {0.0, 1.0, 2.0, 3.0, 4.0, 5.0}; Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(cosineDistance(field("embedding"), sampleVector).as("cosineDistance")) .execute() .get();
DOT_PRODUCT
구문:
dot_product(x: VECTOR, y: VECTOR) -> FLOAT64
설명:
x와 y의 내적을 반환합니다.
Node.js
const sampleVector = [0.0, 1, 2, 3, 4, 5]; const result = await db.pipeline() .collection("books") .select( field("embedding").dotProduct(sampleVector).as("dotProduct") ) .execute();
Web
const sampleVector = [0.0, 1, 2, 3, 4, 5]; const result = await execute(db.pipeline() .collection("books") .select( field("embedding").dotProduct(sampleVector).as("dotProduct") ) );
Swift
let sampleVector = [0.0, 1, 2, 3, 4, 5] let result = try await db.pipeline() .collection("books") .select([ Field("embedding").dotProduct(sampleVector).as("dotProduct") ]) .execute()
Kotlin
val sampleVector = doubleArrayOf(0.0, 1.0, 2.0, 3.0, 4.0, 5.0) val result = db.pipeline() .collection("books") .select( field("embedding").dotProduct(sampleVector).alias("dotProduct") ) .execute()
Java
double[] sampleVector = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0}; Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( field("embedding").dotProduct(sampleVector).alias("dotProduct") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field from google.cloud.firestore_v1.vector import Vector sample_vector = Vector([0.0, 1.0, 2.0, 3.0, 4.0, 5.0]) result = ( client.pipeline() .collection("books") .select(Field.of("embedding").dot_product(sample_vector).as_("dotProduct")) .execute() )
자바
double[] sampleVector = new double[] {0.0, 1.0, 2.0, 3.0, 4.0, 5.0}; Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(dotProduct(field("embedding"), sampleVector).as("dotProduct")) .execute() .get();
EUCLIDEAN_DISTANCE
구문:
euclidean_distance(x: VECTOR, y: VECTOR) -> FLOAT64
설명:
x와 y 사이의 유클리드 거리를 계산합니다.
Node.js
const sampleVector = [0.0, 1, 2, 3, 4, 5]; const result = await db.pipeline() .collection("books") .select( field("embedding").euclideanDistance(sampleVector).as("euclideanDistance") ) .execute();
Web
const sampleVector = [0.0, 1, 2, 3, 4, 5]; const result = await execute(db.pipeline() .collection("books") .select( field("embedding").euclideanDistance(sampleVector).as("euclideanDistance") ) );
Swift
let sampleVector = [0.0, 1, 2, 3, 4, 5] let result = try await db.pipeline() .collection("books") .select([ Field("embedding").euclideanDistance(sampleVector).as("euclideanDistance") ]) .execute()
Kotlin
val sampleVector = doubleArrayOf(0.0, 1.0, 2.0, 3.0, 4.0, 5.0) val result = db.pipeline() .collection("books") .select( field("embedding").euclideanDistance(sampleVector).alias("euclideanDistance") ) .execute()
Java
double[] sampleVector = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0}; Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( field("embedding").euclideanDistance(sampleVector).alias("euclideanDistance") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field from google.cloud.firestore_v1.vector import Vector sample_vector = Vector([0.0, 1.0, 2.0, 3.0, 4.0, 5.0]) result = ( client.pipeline() .collection("books") .select( Field.of("embedding") .euclidean_distance(sample_vector) .as_("euclideanDistance") ) .execute() )
자바
double[] sampleVector = new double[] {0.0, 1.0, 2.0, 3.0, 4.0, 5.0}; Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(euclideanDistance(field("embedding"), sampleVector).as("euclideanDistance")) .execute() .get();
MANHATTAN_DISTANCE
구문:
manhattan_distance(x: VECTOR, y: VECTOR) -> FLOAT64
설명:
x와 y 사이의 맨해튼 거리를 계산합니다.
VECTOR_LENGTH
구문:
vector_length(vector: VECTOR) -> INT64
설명:
VECTOR의 요소 수를 반환합니다.
Node.js
const result = await db.pipeline() .collection("books") .select( field("embedding").vectorLength().as("vectorLength") ) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .select( field("embedding").vectorLength().as("vectorLength") ) );
Swift
let result = try await db.pipeline() .collection("books") .select([ Field("embedding").vectorLength().as("vectorLength") ]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .select( field("embedding").vectorLength().alias("vectorLength") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( field("embedding").vectorLength().alias("vectorLength") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select(Field.of("embedding").vector_length().as_("vectorLength")) .execute() )
자바
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(vectorLength(field("embedding")).as("vectorLength")) .execute() .get();