Aggregate
Alle Aggregatfunktionen können als Ausdrücke auf oberster Ebene in der aggregate(...)-Phase verwendet werden.
| Name | Beschreibung |
COUNT
|
Gibt die Anzahl der Dokumente zurück. |
COUNT_IF
|
Gibt die Anzahl der Dokumente zurück, bei denen ein Ausdruck als TRUE ausgewertet wird
|
COUNT_DISTINCT
|
Gibt die Anzahl der eindeutigen Werte zurück, die nicht NULL sind.
|
SUM
|
Gibt die Summe aller NUMERIC-Werte zurück
|
AVERAGE
|
Gibt den Durchschnitt aller NUMERIC-Werte zurück.
|
MINIMUM
|
Gibt den Mindestwert ungleich NULL zurück.
|
MAXIMUM
|
Gibt den maximalen Wert ungleich NULL zurück.
|
FIRST
|
Gibt den Wert expression für das erste Dokument zurück.
|
LAST
|
Gibt den Wert expression für das letzte Dokument zurück.
|
ARRAY_AGG
|
Gibt ein Array aller Eingabewerte zurück. |
ARRAY_AGG_DISTINCT
|
Gibt ein Array aller eindeutigen Eingabewerte zurück. |
COUNT
Syntax:
count() -> INT64
count(expression: ANY) -> INT64
Beschreibung:
Gibt die Anzahl der Dokumente aus der vorherigen Phase zurück, in denen expression als ein beliebiger Wert außer NULL ausgewertet wird. Wenn kein expression angegeben ist, wird die Gesamtzahl der Dokumente aus der vorherigen Phase zurückgegeben.
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() )
Java
// 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();
Go
// Total number of books in the collection countAll, err := client.Pipeline().Collection("books"). Aggregate(firestore.Accumulators(firestore.CountAll().As("count"))). Execute(ctx).Results().GetAll() if err != nil { fmt.Fprintf(w, "GetAll failed: %v", err) return err } // Number of books with nonnull `ratings` field countField, err := client.Pipeline(). Collection("books"). Aggregate(firestore.Accumulators(firestore.Count("ratings").As("count"))). Execute(ctx).Results().GetAll() if err != nil { fmt.Fprintf(w, "GetAll failed: %v", err) return err }
COUNT_IF
Syntax:
count_if(expression: BOOLEAN) -> INT64
Beschreibung:
Gibt die Anzahl der Dokumente aus der vorherigen Phase zurück, in denen expression als TRUE ausgewertet wird.
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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .aggregate(countIf(field("rating").greaterThan(4)).as("filteredCount")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Aggregate(firestore.Accumulators( firestore.CountIf(firestore.FieldOf("rating").GreaterThan(4)).As("filteredCount"), )). Execute(ctx)
COUNT_DISTINCT
Syntax:
count_distinct(expression: ANY) -> INT64
Beschreibung:
Gibt die Anzahl der eindeutigen Nicht-NULL- und Nicht-ABSENT-Werte von expression zurück.
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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .aggregate(countDistinct("author").as("unique_authors")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Aggregate(firestore.Accumulators( firestore.CountDistinct("author").As("unique_authors"), )). Execute(ctx)
SUM
Syntax:
sum(expression: ANY) -> NUMBER
Beschreibung:
Gibt die Summe aller numerischen Werte zurück, wobei nicht numerische Werte ignoriert werden. Gibt NaN zurück, wenn Werte NaN sind.
Die Ausgabe hat denselben Typ wie der breiteste Eingabetyp, außer in den folgenden Fällen:
- Ein
INTEGERwird in einenDOUBLEumgewandelt, wenn er nicht alsINTEGERdargestellt werden kann.
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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("cities") .aggregate(sum("population").as("totalPopulation")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("cities"). Aggregate(firestore.Accumulators( firestore.Sum("population").As("totalPopulation"), )). Execute(ctx)
AVERAGE
Syntax:
average(expression: ANY) -> FLOAT64
Beschreibung:
Gibt den Durchschnitt aller numerischen Werte zurück, wobei nicht numerische Werte ignoriert werden.
Wird mit NaN ausgewertet, wenn Werte NaN sind, oder mit NULL, wenn keine numerischen Werte aggregiert werden.
Die Ausgabe hat denselben Typ wie der Eingabetyp, außer in den folgenden Fällen:
- Ein
INTEGERwird in einenDOUBLEumgewandelt, wenn er nicht alsINTEGERdargestellt werden kann.
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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("cities") .aggregate(average("population").as("averagePopulation")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("cities"). Aggregate(firestore.Accumulators( firestore.Average("population").As("averagePopulation"), )). Execute(ctx)
MINIMUM
Syntax:
minimum(expression: ANY) -> ANY
Beschreibung:
Gibt den Mindestwert ungleich NULL und ungleich „nicht vorhanden“ von expression zurück, wenn er für jedes Dokument ausgewertet wird.
Wenn keine Werte vorhanden sind, die weder NULL noch nicht vorhanden sind, wird NULL zurückgegeben. Das gilt auch, wenn keine Dokumente berücksichtigt werden.
Wenn es mehrere minimale äquivalente Werte gibt, kann jeder dieser Werte zurückgegeben werden. Die Reihenfolge der Werttypen entspricht der dokumentierten Reihenfolge.
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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .aggregate(minimum("price").as("minimumPrice")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Aggregate(firestore.Accumulators( firestore.Minimum("price").As("minimumPrice"), )). Execute(ctx)
MAXIMAL
Syntax:
maximum(expression: ANY) -> ANY
Beschreibung:
Gibt den maximalen Wert ungleich NULL und ungleich „nicht vorhanden“ von expression zurück, wenn er für jedes Dokument ausgewertet wird.
Wenn keine Werte vorhanden sind, die weder NULL noch nicht vorhanden sind, wird NULL zurückgegeben. Das gilt auch, wenn keine Dokumente berücksichtigt werden.
Wenn es mehrere maximale äquivalente Werte gibt, kann jeder dieser Werte zurückgegeben werden. Die Reihenfolge der Werttypen entspricht der dokumentierten Reihenfolge.
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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .aggregate(maximum("price").as("maximumPrice")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Aggregate(firestore.Accumulators( firestore.Maximum("price").As("maximumPrice"), )). Execute(ctx)
FIRST
Syntax:
first(expression: ANY) -> ANY
Beschreibung:
Gibt den Wert von expression für das erste zurückgegebene Dokument zurück.
LETZTE
Syntax:
last(expression: ANY) -> ANY
Beschreibung:
Gibt den Wert von expression für das zuletzt zurückgegebene Dokument zurück.
ARRAY_AGG
Syntax:
array_agg(expression: ANY) -> ARRAY<ANY>
Beschreibung:
Gibt ein Array zurück, das alle Werte von expression enthält, wenn es für jedes Dokument ausgewertet wird.
Wenn der Ausdruck zu einem fehlenden Wert aufgelöst wird, wird er in NULL konvertiert.
Die Reihenfolge der Elemente im Ausgabearray ist nicht stabil und sollte nicht als Grundlage verwendet werden.
ARRAY_AGG_DISTINCT
Syntax:
array_agg_distinct(expression: ANY) -> ARRAY<ANY>
Beschreibung:
Gibt ein Array mit allen eindeutigen Werten von expression zurück, wenn es für jedes Dokument ausgewertet wird.
Wenn der Ausdruck zu einem fehlenden Wert aufgelöst wird, wird er in NULL konvertiert.
Die Reihenfolge der Elemente im Ausgabearray ist nicht stabil und sollte nicht als Grundlage verwendet werden.
Arithmetische Funktionen
Alle arithmetischen Funktionen in Cloud Firestore verhalten sich in folgender Weise:
- Wird mit
NULLausgewertet, wenn einer der EingabeparameterNULList. - Wird mit
NaNausgewertet, wenn eines der ArgumenteNaNist. - Erzeugt einen Fehler, wenn ein Überlauf oder Unterlauf auftritt.
Cloud Firestore führt eine Erweiterung des numerischen Typs basierend auf der folgenden Hierarchie durch: INT32 < INT64 < FLOAT64 < DECIMAL128. Wenn eine arithmetische Funktion mehrere numerische Argumente unterschiedlicher Typen (z. B. add(5.0D, 6L)) akzeptiert, werden engere Typen implizit in den breitesten Typ konvertiert, der unter den Operanden vorhanden ist. Im vorherigen Beispiel wird 6L auf 6.0D erweitert, sodass der Ausdruck einen FLOAT64-Typ zurückgibt.
Eine implizite Umwandlung von INT64 -> FLOAT64 kann zu einem Genauigkeitsverlust führen, da der umgewandelte Wert seine am wenigsten signifikanten Bits verlieren kann. Der resultierende Wert ist eine gerundete Version des ursprünglichen Ganzzahlwerts im IEEE 754-Modus „Auf den nächsten Wert runden“.
| Name | Beschreibung |
ABS
|
Gibt den Absolutwert eines number zurück
|
ADD
|
Gibt den Wert von x + y zurück.
|
SUBTRACT
|
Gibt den Wert von x - y zurück.
|
MULTIPLY
|
Gibt den Wert von x * y zurück.
|
DIVIDE
|
Gibt den Wert von x / y zurück.
|
MOD
|
Gibt den Rest der Division von x / y zurück
|
CEIL
|
Gibt die Obergrenze eines number zurück
|
FLOOR
|
Gibt die Abrundung eines number zurück
|
ROUND
|
Rundet einen number-Wert auf places Dezimalstellen
|
TRUNC
|
Kürzt einen number-Wert auf places Dezimalstellen.
|
POW
|
Gibt den Wert von base^exponent zurück.
|
SQRT
|
Gibt die Quadratwurzel eines number zurück
|
EXP
|
Gibt die Eulersche Zahl potenziert mit exponent zurück
|
LN
|
Gibt den natürlichen Logarithmus eines number zurück
|
LOG
|
Gibt den Logarithmus eines number zurück
|
LOG10
|
Gibt den Logarithmus von number zur Basis 10 zurück
|
RAND
|
Gibt eine pseudozufällige Gleitkommazahl zurück |
ABS
Syntax:
abs[N <: INT32 | INT64 | FLOAT64 | DECIMAL128](number: N) -> N
Beschreibung:
Gibt den Absolutwert eines number zurück.
- Löst einen Fehler aus, wenn die Funktion einen
INT32- oderINT64-Wert überlaufen würde.
Beispiele:
| number | abs(number) |
|---|---|
| 10 | 10 |
| -10 | 10 |
| 10L | 10L |
| -0,0 | 0,0 |
| 10.5 | 10.5 |
| -10,5 | 10.5 |
| -231 | [error] |
| -263 | [error] |
HINZUFÜGEN
Syntax:
add[N <: INT32 | INT64 | FLOAT64 | DECIMAL128](x: N, y: N) -> N
Beschreibung:
Gibt den Wert von x + y zurück.
Beispiele:
| x | z | add(x, y) |
|---|---|---|
| 20 | 3 | 23 |
| 10 | 1 | 11.0 |
| 22,5 | 2 | 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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(add(field("soldBooks"), field("unsoldBooks")).as("totalBooks")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.Add(firestore.FieldOf("soldBooks"), firestore.FieldOf("unsoldBooks")).As("totalBooks"), )). Execute(ctx)
SUBTRACT
Syntax:
subtract[N <: INT32 | INT64 | FLOAT64 | DECIMAL128](x: N, y: N) -> N
Beschreibung:
Gibt den Wert von x - y zurück.
Beispiele:
| x | z | subtract(x, y) |
|---|---|---|
| 20 | 3 | 17 |
| 10 | 1 | 9.0 |
| 22,5 | 2 | 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() )
Java
int storeCredit = 7; Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(subtract(field("price"), storeCredit).as("totalCost")) .execute() .get();
Go
storeCredit := 7 snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.Subtract(firestore.FieldOf("price"), storeCredit).As("totalCost"), )). Execute(ctx)
MULTIPLY
Syntax:
multiply[N <: INT32 | INT64 | FLOAT64 | DECIMAL128](x: N, y: N) -> N
Beschreibung:
Gibt den Wert von x * y zurück.
Beispiele:
| x | z | multiply(x, y) |
|---|---|---|
| 20 | 3 | 60 |
| 10 | 1 | 10 |
| 22,5 | 2 | 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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(multiply(field("price"), field("soldBooks")).as("revenue")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.Multiply(firestore.FieldOf("price"), firestore.FieldOf("soldBooks")).As("revenue"), )). Execute(ctx)
DIVIDE
Syntax:
divide[N <: INT32 | INT64 | FLOAT64 | DECIMAL128](x: N, y: N) -> N
Beschreibung:
Gibt den Wert von x / y zurück. Die Ganzzahldivision wird abgeschnitten.
Beispiele:
| x | z | divide(x, y) |
|---|---|---|
| 20 | 3 | 6 |
| 10 | 3 | 3,333... |
| 22,5 | 2 | 11.25 |
| 10 | 0 | [error] |
| 1.0 | 0,0 | +inf |
| -1,0 | 0,0 | -inf |
| 0,0 | 0,0 | NaN |
+inf |
+inf |
NaN |
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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(divide(field("ratings"), field("soldBooks")).as("reviewRate")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.Divide(firestore.FieldOf("ratings"), firestore.FieldOf("soldBooks")).As("reviewRate"), )). Execute(ctx)
MOD
Syntax:
mod[N <: INT32 | INT64 | FLOAT64 | DECIMAL128](x: N, y: N) -> N
Beschreibung:
Gibt den Rest von x / y zurück.
- Löst einen
erroraus, wennyfür Ganzzahltypen (INT64) null ist. - Gibt
NaNzurück, wennyfür Gleitkommatypen (FLOAT64) null ist.
Beispiele:
| x | z | 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() )
Java
int displayCapacity = 1000; Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(mod(field("unsoldBooks"), displayCapacity).as("warehousedBooks")) .execute() .get();
Go
displayCapacity := 1000 snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.Mod(firestore.FieldOf("unsoldBooks"), displayCapacity).As("warehousedBooks"), )). Execute(ctx)
CEIL
Syntax:
ceil[N <: INT32 | INT64 | FLOAT64 | DECIMAL128](number: N) -> N
Beschreibung:
Gibt den kleinsten Ganzzahlwert zurück, der nicht kleiner als number ist.
Beispiele:
| number | ceil(number) |
|---|---|
| 20 | 20 |
| 10 | 10 |
| 0 | 0 |
| 24L | 24L |
| -0,4 | -0,0 |
| 0,4 | 1.0 |
| 22,5 | 23,0 |
NaN |
NaN |
+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() )
Java
int booksPerShelf = 100; Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(ceil(divide(field("unsoldBooks"), booksPerShelf)).as("requiredShelves")) .execute() .get();
Go
booksPerShelf := 100 snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.Ceil(firestore.Divide(firestore.FieldOf("unsoldBooks"), booksPerShelf)).As("requiredShelves"), )). Execute(ctx)
FLOOR
Syntax:
floor[N <: INT32 | INT64 | FLOAT64 | DECIMAL128](number: N) -> N
Beschreibung:
Gibt den größten Ganzzahlwert zurück, der nicht größer als number ist.
Beispiele:
| number | floor(number) |
|---|---|
| 20 | 20 |
| 10 | 10 |
| 0 | 0 |
| 2147483648 | 2147483648 |
| -0,4 | -1,0 |
| 0,4 | 0,0 |
| 22,5 | 22,0 |
NaN |
NaN |
+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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .addFields(floor(divide(field("wordCount"), field("pages"))).as("wordsPerPage")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). AddFields(firestore.Selectables( firestore.Floor(firestore.Divide(firestore.FieldOf("wordCount"), firestore.FieldOf("pages"))).As("wordsPerPage"), )). Execute(ctx)
ROUND
Syntax:
round[N <: INT32 | INT64 | FLOAT64 | DECIMAL128](number: N) -> N
round[N <: INT32 | INT64 | FLOAT64 | DECIMAL128](number: N, places: INT64) -> N
Beschreibung:
Rundet places Ziffern von number ab. Rundet Ziffern rechts vom
Dezimaltrennzeichen, wenn places positiv ist, und links vom Dezimaltrennzeichen, wenn
negativ ist.
- Wenn nur
numberangegeben ist, wird auf den nächsten ganzzahligen Wert gerundet. - Rundet halbe Zahlen von null weg.
- Ein
errorwird ausgegeben, wenn das Runden mit einem negativenplaces-Wert zu einem Überlauf führt.
Beispiele:
| number | Orte | 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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(round(multiply(field("soldBooks"), field("price"))).as("partialRevenue")) .aggregate(sum("partialRevenue").as("totalRevenue")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.Round(firestore.Multiply(firestore.FieldOf("soldBooks"), firestore.FieldOf("price"))).As("partialRevenue"), )). Aggregate(firestore.Accumulators( firestore.Sum("partialRevenue").As("totalRevenue"), )). Execute(ctx)
TRUNC
Syntax:
trunc[N <: Number](number: N) -> N
trunc[N <: Number](number: N, places: INT64) -> N
Beschreibung:
Schneidet einen number-Wert auf eine angegebene Anzahl von places-Dezimalstellen ab. Schneidet
Ziffern rechts vom Dezimaltrennzeichen ab, wenn places positiv ist, und
links vom Dezimaltrennzeichen, wenn negativ ist.
- Wenn nur
numberangegeben ist, wird auf den nächsten ganzzahligen Wert in Richtung null gekürzt. - Wenn das Abschneiden zu einem Überlauf führt, wird ein
errorausgegeben.
Beispiele:
| number | Orte | 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
Syntax:
pow(base: FLOAT64, exponent: FLOAT64) -> FLOAT64
Beschreibung:
Gibt den Wert base potenziert mit exponent zurück.
Gibt einen Fehler aus, wenn
base <= 0undexponentnegativ sind.Für alle
exponent(einschließlichNaN) istpow(1, exponent)= 1.Für alle
base(einschließlichNaN) istpow(base, 0)= 1.
Beispiele:
| Basis | Basis des natürlichen Logarithmus | pow(base, exponent) |
|---|---|---|
| 2 | 3 | 8.0 |
| 2 | -3 | 0,125 |
+inf |
0 | 1.0 |
| 1 | +inf |
1.0 |
NaN |
0 | 1.0 |
| 1 | NaN |
1.0 |
NaN |
Numeric |
NaN |
Numeric |
NaN |
NaN |
| -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() )
Java
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();
Go
googleplexLat := 37.4221 googleplexLng := -122.0853 snapshot := client.Pipeline(). Collection("cities"). AddFields(firestore.Selectables( firestore.Pow(firestore.Multiply(firestore.Subtract(firestore.FieldOf("lat"), googleplexLat), 111), 2).As("latitudeDifference"), firestore.Pow(firestore.Multiply(firestore.Subtract(firestore.FieldOf("lng"), googleplexLng), 111), 2).As("longitudeDifference"), )). Select(firestore.Fields( firestore.Sqrt(firestore.Add(firestore.FieldOf("latitudeDifference"), firestore.FieldOf("longitudeDifference"))). // Inaccurate for large distances or close to poles As("approximateDistanceToGoogle"), )). Execute(ctx)
SQRT
Syntax:
sqrt[N <: FLOAT64 | DECIMAL128](number: N) -> N
Beschreibung:
Gibt die Quadratwurzel eines number zurück.
- Gibt einen
erroraus, wennnumbernegativ ist.
Beispiele:
| number | sqrt(number) |
|---|---|
| 25 | 5 |
| 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() )
Java
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();
Go
googleplexLat := 37.4221 googleplexLng := -122.0853 snapshot := client.Pipeline(). Collection("cities"). AddFields(firestore.Selectables( firestore.Pow(firestore.Multiply(firestore.Subtract(firestore.FieldOf("lat"), googleplexLat), 111), 2).As("latitudeDifference"), firestore.Pow(firestore.Multiply(firestore.Subtract(firestore.FieldOf("lng"), googleplexLng), 111), 2).As("longitudeDifference"), )). Select(firestore.Fields( firestore.Sqrt(firestore.Add(firestore.FieldOf("latitudeDifference"), firestore.FieldOf("longitudeDifference"))). // Inaccurate for large distances or close to poles As("approximateDistanceToGoogle"), )). Execute(ctx)
EXP
Syntax:
exp(exponent: FLOAT64) -> FLOAT64
Beschreibung:
Gibt den Wert der Eulerschen Zahl potenziert mit exponent zurück, auch natürliche Exponentialfunktion genannt.
Beispiele:
| Basis des natürlichen Logarithmus | exp(exponent) |
|---|---|
| 0,0 | 1.0 |
| 10 | e^10 (FLOAT64) |
NaN |
NaN |
+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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(exp(field("rating")).as("expRating")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.Exp(firestore.FieldOf("rating")).As("expRating"), )). Execute(ctx)
LN
Syntax:
ln(number: FLOAT64) -> FLOAT64
Beschreibung:
Gibt den natürlichen Logarithmus von number zurück. Diese Funktion entspricht log(number).
Beispiele:
| number | ln(number) |
|---|---|
| 1 | 0,0 |
| 2L | 0,693... |
| 1.0 | 0,0 |
e (FLOAT64) |
1.0 |
NaN |
NaN |
-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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(ln(field("rating")).as("lnRating")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.Ln(firestore.FieldOf("rating")).As("lnRating"), )). Execute(ctx)
LOG
Syntax:
log(number: FLOAT64, base: FLOAT64) -> FLOAT64
log(number: FLOAT64) -> FLOAT64
Beschreibung:
Gibt den Logarithmus eines number zur Basis base zurück.
- Wenn nur
numberangegeben ist, wird der Logarithmus vonnumberzur Basisbasezurückgegeben (gleichbedeutend mitln(number)).
Beispiele:
| number | Basis | log(number, base) |
|---|---|---|
| 100 | 10 | 2 |
NaN |
Numeric |
NaN |
Numeric |
NaN |
NaN |
-inf |
Numeric |
NaN |
Numeric. |
+inf |
NaN |
number <= 0 |
Numeric |
[error] |
Numeric |
base <= 0 |
[error] |
Numeric |
1.0 | [error] |
LOG10
Syntax:
log10(x: FLOAT64) -> FLOAT64
Beschreibung:
Gibt den Logarithmus von number zur Basis 10 zurück.
Beispiele:
| number | log10(number) |
|---|---|
| 100 | 2 |
NaN |
NaN |
-inf |
NaN |
+inf |
+inf |
x <= 0 |
[error] |
RAND
Syntax:
rand() -> FLOAT64
Beschreibung:
Gibt eine pseudozufällige Gleitkommazahl zurück, die gleichmäßig zwischen 0.0 (einschließlich) und 1.0 (ausschließlich) ausgewählt wird.
Arrayfunktionen
| Name | Beschreibung |
ARRAY
|
Gibt ein ARRAY mit einem Element für jedes Eingabeargument zurück
|
ARRAY_CONCAT
|
Verkettet mehrere Arrays zu einem einzelnen ARRAY.
|
ARRAY_CONTAINS
|
Gibt TRUE zurück, wenn ein bestimmter ARRAY einen bestimmten Wert enthält.
|
ARRAY_CONTAINS_ALL
|
Gibt TRUE zurück, wenn alle Werte in ARRAY vorhanden sind.
|
ARRAY_CONTAINS_ANY
|
Gibt TRUE zurück, wenn einer der Werte in ARRAY vorhanden ist.
|
ARRAY_FILTER
|
Filtert Elemente aus einem ARRAY heraus, die ein Prädikat nicht erfüllen
|
ARRAY_FIRST
|
Gibt das erste Element in einem ARRAY zurück.
|
ARRAY_FIRST_N
|
Gibt die ersten n Elemente in einem ARRAY zurück
|
ARRAY_GET
|
Gibt das Element an einem bestimmten Index in einem ARRAY zurück.
|
ARRAY_INDEX_OF
|
Gibt den Index des ersten Vorkommens eines Werts in einem ARRAY zurück
|
ARRAY_INDEX_OF_ALL
|
Gibt alle Indexe eines Werts in einem ARRAY zurück
|
ARRAY_LENGTH
|
Gibt die Anzahl der Elemente in einem ARRAY zurück.
|
ARRAY_LAST
|
Gibt das letzte Element in einem ARRAY zurück.
|
ARRAY_LAST_N
|
Gibt die letzten n Elemente in einem ARRAY zurück
|
ARRAY_REVERSE
|
Kehrt die Reihenfolge der Elemente in einem ARRAY um
|
ARRAY_SLICE
|
Gibt ein Segment eines ARRAY zurück
|
ARRAY_TRANSFORM
|
Transformiert Elemente in einem ARRAY, indem ein Ausdruck auf jedes Element angewendet wird
|
MAXIMUM
|
Gibt den Maximalwert in einem ARRAY zurück.
|
MAXIMUM_N
|
Gibt die n größten Werte in einem ARRAY zurück
|
MINIMUM
|
Gibt den Mindestwert in einem ARRAY zurück.
|
MINIMUM_N
|
Gibt die n kleinsten Werte in einem ARRAY zurück
|
SUM
|
Gibt die Summe aller NUMERIC-Werte in einem ARRAY zurück.
|
JOIN
|
Erzeugt eine Verkettung der Elemente in einem ARRAY als STRING-Wert.
|
ARRAY
Syntax:
array(values: ANY...) -> ARRAY
Beschreibung:
Erstellt ein Array aus den angegebenen Elementen.
- Wenn ein Argument nicht vorhanden ist, wird es im resultierenden Array durch
NULLersetzt.
Beispiele:
| Werte | 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
Syntax:
array_concat(arrays: ARRAY...) -> ARRAY
Beschreibung:
Verkettet zwei oder mehr Arrays zu einem einzelnen ARRAY.
Beispiele:
| 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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(arrayConcat(field("genre"), field("subGenre")).as("allGenres")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.ArrayConcat(firestore.FieldOf("genre"), firestore.FieldOf("subGenre")).As("allGenres"), )). Execute(ctx)
ARRAY_CONTAINS
Syntax:
array_contains(array: ARRAY, value: ANY) -> BOOLEAN
Beschreibung:
Gibt TRUE zurück, wenn value in array gefunden wird, andernfalls FALSE.
Beispiele:
| array | Wert | array_contains(array, value) |
|---|---|---|
| [1, 2, 3] | 2 | wahr |
| [[1, 2], [3]] | [1, 2] | wahr |
| [1, null] | null | wahr |
| "abc" | ALLE | Fehler |
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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(arrayContains(field("genre"), "mystery").as("isMystery")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.ArrayContains(firestore.FieldOf("genre"), "mystery").As("isMystery"), )). Execute(ctx)
ARRAY_CONTAINS_ALL
Syntax:
array_contains_all(array: ARRAY, search_values: ARRAY) -> BOOLEAN
Beschreibung:
Gibt TRUE zurück, wenn alle search_values in den array gefunden werden, andernfalls FALSE.
Beispiele:
| array | search_values | array_contains_all(array, search_values) |
|---|---|---|
| [1, 2, 3] | [1, 2] | wahr |
| [1, 2, 3] | [1, 4] | falsch |
| [1, null] | [null] | wahr |
| [NaN] | [NaN] | wahr |
| [] | [] | wahr |
| [1, 2, 3] | [] | wahr |
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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select( arrayContainsAll(field("genre"), Arrays.asList("fantasy", "adventure")) .as("isFantasyAdventure")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.ArrayContainsAll(firestore.FieldOf("genre"), []string{"fantasy", "adventure"}).As("isFantasyAdventure"), )). Execute(ctx)
ARRAY_CONTAINS_ANY
Syntax:
array_contains_any(array: ARRAY, search_values: ARRAY) -> BOOLEAN
Beschreibung:
Gibt TRUE zurück, wenn einer der search_values in array gefunden wird, andernfalls FALSE.
Beispiele:
| array | search_values | array_contains_any(array, search_values) |
|---|---|---|
| [1, 2, 3] | [4, 1] | wahr |
| [1, 2, 3] | [4, 5] | falsch |
| [1, 2, null] | [null] | wahr |
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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select( arrayContainsAny(field("genre"), Arrays.asList("fantasy", "nonfiction")) .as("isMysteryOrFantasy")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.ArrayContainsAny(firestore.FieldOf("genre"), []string{"fantasy", "nonfiction"}).As("isMysteryOrFantasy"), )). Execute(ctx)
ARRAY_FILTER
Syntax:
array_filter(array: ARRAY, predicate: (ANY) -> BOOLEAN) -> ARRAY
Beschreibung:
Filtert array mithilfe eines predicate-Ausdrucks und gibt ein neues Array mit nur den Elementen zurück, die das Prädikat erfüllen.
- Für jedes Element in
arraywirdpredicateausgewertet. Wenntruezurückgegeben wird, wird das Element in das Ergebnis aufgenommen. Andernfalls (wennfalseodernullzurückgegeben wird) wird es weggelassen. - Wenn
predicateals Wert ausgewertet wird, der weder ein boolescher Wert noch ein Nullwert ist, gibt die Funktion einen Fehler zurück.
Beispiele:
| array | 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
Syntax:
array_get(array: ARRAY, index: INT64) -> ANY
Beschreibung:
Gibt das Element am 0-basierten index in array zurück.
- Wenn
indexnegativ ist, wird auf Elemente ab dem Ende des Arrays zugegriffen, wobei-1das letzte Element ist. - Wenn
arraynicht vom TypARRAYund nichtnullist, wird ein Fehler zurückgegeben. - Wenn
indexaußerhalb des zulässigen Bereichs liegt, gibt die Funktion einen fehlenden Wert zurück. - Wenn
indexnicht vom TypINT64ist, gibt die Funktion einen Fehler zurück.
Beispiele:
| array | Index | array_get(array, index) |
|---|---|---|
| [1, 2, 3] | 0 | 1 |
| [1, 2, 3] | -1 | 3 |
| [1, 2, 3] | 3 | abwesend |
| [1, 2, 3] | -4 | abwesend |
| "abc" | 0 | Fehler |
| null | 0 | null |
Array |
„a“ | Fehler |
Array |
2 | Fehler |
ARRAY_LENGTH
Syntax:
array_length(array: ARRAY) -> INT64
Beschreibung:
Gibt die Anzahl der Elemente in array zurück.
Beispiele:
| 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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(arrayLength(field("genre")).as("genreCount")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.ArrayLength(firestore.FieldOf("genre")).As("genreCount"), )). Execute(ctx)
ARRAY_REVERSE
Syntax:
array_reverse(array: ARRAY) -> ARRAY
Beschreibung:
Kehrt die angegebene array um.
Beispiele:
| 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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(arrayReverse(field("genre")).as("reversedGenres")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.ArrayReverse(firestore.FieldOf("genre")).As("reversedGenres"), )). Execute(ctx)
ARRAY_FIRST
Syntax:
array_first(array: ARRAY) -> ANY
Beschreibung:
Gibt das erste Element in array zurück. Dies entspricht array_get(array, 0).
- Wenn
arrayleer ist, wird ein fehlender Wert zurückgegeben.
Beispiele:
| array | array_first(array) |
|---|---|
| [1, 2, 3] | 1 |
| [] | abwesend |
ARRAY_FIRST_N
Syntax:
array_first_n(array: ARRAY, n: INT64) -> ARRAY
Beschreibung:
Gibt die ersten n Elemente von array zurück. Dies entspricht array_slice(array, 0, n).
- Wenn
nnegativ ist, wird ein Fehler zurückgegeben.
Beispiele:
| array | 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
Syntax:
array_index_of(array: ARRAY, value: ANY) -> INT64
Beschreibung:
Gibt den 0-basierten Index des ersten Vorkommens von value in array zurück. Gibt -1 zurück, wenn value nicht gefunden wird.
Beispiele:
| array | Wert | 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
Syntax:
array_index_of_all(array: ARRAY, value: ANY) -> ARRAY<INT64>
Beschreibung:
Gibt ein Array mit den 0-basierten Indexen aller Vorkommen von value in array zurück. Gibt [] zurück, wenn value nicht gefunden wird.
Beispiele:
| array | Wert | 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
Syntax:
array_last(array: ARRAY) -> ANY
Beschreibung:
Gibt das letzte Element in array zurück. Dies entspricht array_get(array, -1).
- Wenn
arrayleer ist, wird ein fehlender Wert zurückgegeben.
Beispiele:
| array | array_last(array) |
|---|---|
| [1, 2, 3] | 3 |
| [] | abwesend |
ARRAY_LAST_N
Syntax:
array_last_n(array: ARRAY, n: INT64) -> ARRAY
Beschreibung:
Gibt die letzten n Elemente von array zurück.
- Wenn
nnegativ ist, wird ein Fehler zurückgegeben.
Beispiele:
| array | 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
Syntax:
array_slice(array: ARRAY, offset: INT64, length: INT64) -> ARRAY
Beschreibung:
Gibt eine Teilmenge von array zurück, beginnend mit dem 0-basierten Index offset und einschließlich length Elementen.
- Wenn
offsetnegativ ist, gibt es die Startposition ab dem Ende des Arrays an, wobei-1das letzte Element ist. - Wenn
lengthgrößer ist als die Anzahl der Elemente, die nachoffsetim Array verbleiben, erstreckt sich das Ergebnis bis zum Ende des Arrays. lengthdarf nicht negativ sein, andernfalls wird ein Fehler zurückgegeben.
Beispiele:
| array | offset | Länge | 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
Syntax:
array_transform(array: ARRAY, expression: (ANY) -> ANY) -> ARRAY
array_transform(array: ARRAY, expression: (ANY, INT64) -> ANY) -> ARRAY
Beschreibung:
Transformiert array, indem expression auf jedes Element angewendet wird, und gibt ein neues Array mit transformierten Elementen zurück. Das Ausgabearray hat immer dieselbe Größe wie das Eingabearray.
expressionkann eine unäre Funktionelement -> resultoder eine binäre Funktion(element, index) -> resultsein.- Wenn
expressionunär ist, wird es mit jedem Element vonarrayaufgerufen. - Wenn
expressionbinär ist, wird sie mit jedem Element vonarrayund dem entsprechenden nullbasierten Index aufgerufen.
Beispiele:
| array | Ausdruck | 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 | [] |
MAXIMAL
Syntax:
maximum(array: ARRAY) -> ANY
Beschreibung:
Gibt den Maximalwert in array zurück.
NULL-Werte werden beim Vergleich ignoriert.- Wenn
arrayleer ist oder nurNULL-Werte enthält, wirdNULLzurückgegeben.
Beispiele:
| array | maximum(array) |
|---|---|
| [1, 5, 2] | 5 |
| [1, null, 5] | 5 |
| ["a", "c", "b"] | "c" |
| [null, null] | null |
| [] | null |
MAXIMUM_N
Syntax:
maximum_n(array: ARRAY, n: INT64) -> ARRAY
Beschreibung:
Gibt ein Array der n größten Werte in array in absteigender Reihenfolge zurück.
NULL-Werte werden ignoriert.- Wenn
nnegativ ist, wird ein Fehler zurückgegeben.
Beispiele:
| array | n | maximum_n(array, n) |
|---|---|---|
| [1, 5, 2, 4, 3] | 3 | [5, 4, 3] |
| [1, null, 5] | 3 | [5, 1] |
MINIMUM
Syntax:
minimum(array: ARRAY) -> ANY
Beschreibung:
Gibt den Mindestwert in array zurück.
NULL-Werte werden beim Vergleich ignoriert.- Wenn
arrayleer ist oder nurNULL-Werte enthält, wirdNULLzurückgegeben.
Beispiele:
| array | minimum(array) |
|---|---|
| [1, 5, 2] | 1 |
| [5, null, 1] | 1 |
| ["a", "c", "b"] | „a“ |
| [null, null] | null |
| [] | null |
MINIMUM_N
Syntax:
minimum_n(array: ARRAY, n: INT64) -> ARRAY
Beschreibung:
Gibt ein Array der n kleinsten Werte in array in aufsteigender Reihenfolge zurück.
NULL-Werte werden ignoriert.- Wenn
nnegativ ist, wird ein Fehler zurückgegeben.
Beispiele:
| array | n | minimum_n(array, n) |
|---|---|---|
| [1, 5, 2, 4, 3] | 3 | [1, 2, 3] |
| [5, null, 1] | 3 | [1, 5] |
SUM
Syntax:
sum(array: ARRAY) -> INT64 | FLOAT64
Beschreibung:
Gibt die Summe aller NUMERIC-Werte in einem ARRAY zurück.
- Nicht numerische Werte im Array werden ignoriert.
- Wenn ein numerischer Wert im Array
NaNist, gibt die FunktionNaNzurück. - Der Rückgabetyp wird durch den breitesten numerischen Typ im Array bestimmt:
INT64<FLOAT64. - Wenn ein 64-Bit-Ganzzahlüberlauf auftritt, bevor ein Gleitkommawert summiert wird, wird ein Fehler zurückgegeben. Wenn Gleitkommawerte summiert werden, führt ein Überlauf zu +/- unendlich.
- Wenn das Array überhaupt keine numerischen Werte enthält, gibt die Funktion
NULLzurück.
Beispiele:
| array | 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] | Fehler |
| [INT64.MAX_VALUE, 1, -1.0] | Fehler |
| [INT64.MAX_VALUE, 1.0] | 9.223372036854776e+18 |
Beitreten
Syntax:
join[T <: STRING | BYTES](array: ARRAY<T>, delimiter: T) -> STRING
join[T <: STRING | BYTES](array: ARRAY<T>, delimiter: T, null_text: T) -> STRING
Beschreibung:
Gibt eine Verkettung der Elemente in array als STRING zurück. array kann den Datentyp STRING oder BYTES haben.
- Alle Elemente in
array,delimiterundnull_textmüssen vom selben Typ sein, also entweder alleSTRINGoder alleBYTES. - Wenn
null_textangegeben ist, werden alleNULL-Werte inarraydurchnull_textersetzt. - Wenn
null_textnicht angegeben ist, werdenNULL-Werte inarrayim Ergebnis weggelassen.
Beispiele:
Wenn null_text nicht angegeben ist:
| array | delimiter | 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'] | "," | Fehler |
| ["a", "c"] | b',' | Fehler |
| [b'a', b'c'] | "," | Fehler |
Wenn null_text angegeben wurde, geschieht Folgendes:
| array | delimiter | 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' | Fehler |
| [b'a', null] | b',' | "N" | Fehler |
Vergleichsfunktionen
| Name | Beschreibung |
EQUAL
|
Gleichheitsvergleich |
GREATER_THAN
|
Größer als (Vergleich) |
GREATER_THAN_OR_EQUAL
|
Vergleich „Größer als oder gleich“ |
LESS_THAN
|
Vergleich „Kleiner als“ |
LESS_THAN_OR_EQUAL
|
Vergleich „kleiner oder gleich“ |
NOT_EQUAL
|
Vergleich „Ist nicht gleich“ |
CMP
|
Allgemeiner Vergleich |
EQUAL
Syntax:
equal(x: ANY, y: ANY) -> BOOLEAN
Beispiele:
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 |
Beschreibung:
Gibt TRUE zurück, wenn x und y gleich sind, andernfalls 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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(equal(field("rating"), 5).as("hasPerfectRating")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.Equal(firestore.FieldOf("rating"), 5).As("hasPerfectRating"), )). Execute(ctx)
GREATER_THAN
Syntax:
greater_than(x: ANY, y: ANY) -> BOOLEAN
Beschreibung:
Gibt TRUE zurück, wenn x größer als y ist, andernfalls FALSE.
Wenn x und y nicht vergleichbar sind, wird FALSE zurückgegeben.
Beispiele:
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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(greaterThan(field("rating"), 4).as("hasHighRating")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.GreaterThan(firestore.FieldOf("rating"), 4).As("hasHighRating"), )). Execute(ctx)
GREATER_THAN_OR_EQUAL
Syntax:
greater_than_or_equal(x: ANY, y: ANY) -> BOOLEAN
Beschreibung:
Gibt TRUE zurück, wenn x größer oder gleich y ist, andernfalls FALSE.
Wenn x und y nicht vergleichbar sind, wird FALSE zurückgegeben.
Beispiele:
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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(greaterThanOrEqual(field("published"), 1900).as("publishedIn20thCentury")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.GreaterThanOrEqual(firestore.FieldOf("published"), 1900).As("publishedIn20thCentury"), )). Execute(ctx)
LESS_THAN
Syntax:
less_than(x: ANY, y: ANY) -> BOOLEAN
Beschreibung:
Gibt TRUE zurück, wenn x kleiner als y ist, andernfalls FALSE.
Wenn x und y nicht vergleichbar sind, wird FALSE zurückgegeben.
Beispiele:
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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(lessThan(field("published"), 1923).as("isPublicDomainProbably")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.LessThan(firestore.FieldOf("published"), 1923).As("isPublicDomainProbably"), )). Execute(ctx)
LESS_THAN_OR_EQUAL
Syntax:
less_than_or_equal(x: ANY, y: ANY) -> BOOLEAN
Beschreibung:
Gibt TRUE zurück, wenn x kleiner oder gleich y ist, andernfalls FALSE.
Wenn x und y nicht vergleichbar sind, wird FALSE zurückgegeben.
Beispiele:
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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(lessThanOrEqual(field("rating"), 2).as("hasBadRating")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.LessThanOrEqual(firestore.FieldOf("rating"), 2).As("hasBadRating"), )). Execute(ctx)
NOT_EQUAL
Syntax:
not_equal(x: ANY, y: ANY) -> BOOLEAN
Beschreibung:
Gibt TRUE zurück, wenn x nicht gleich y ist, andernfalls FALSE.
Beispiele:
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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(notEqual(field("title"), "1984").as("not1984")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.NotEqual(firestore.FieldOf("title"), "1984").As("not1984"), )). Execute(ctx)
CMP
Syntax:
cmp(x: ANY, y: ANY) -> Int64
Beschreibung:
Vergleicht x und y und gibt Folgendes zurück:
1L, wennxgrößer alsyist.-1L, wennxkleiner alsyist.- Andernfalls
0L.
Im Gegensatz zu anderen Vergleichsfunktionen funktioniert die Funktion cmp(...) typübergreifend und folgt derselben Reihenfolge wie in der Phase sort(...). Informationen zur Sortierung von Werten über Typen hinweg finden Sie unter Reihenfolge der Werttypen.
Beispiele:
x |
y |
cmp(x, y) |
|---|---|---|
| 1L | 1L | 0L |
| 1.0 | 1L | 0L |
| -1,0 | 1L | -1L |
| 42,5 Tage | "foo" | -1L |
NULL |
NULL |
0L |
NULL |
ABSENT |
0L |
Debugging-Funktionen
| Name | Beschreibung |
EXISTS
|
Gibt TRUE zurück, wenn der Wert kein fehlender Wert ist
|
IS_ABSENT
|
Gibt TRUE zurück, wenn der Wert ein fehlender Wert ist.
|
IF_ABSENT
|
Ersetzt den Wert durch einen Ausdruck, wenn er nicht vorhanden ist |
IS_ERROR
|
Fängt einen Fehler ab und prüft, ob er vom zugrunde liegenden Ausdruck ausgelöst wurde |
IF_ERROR
|
Ersetzt den Wert durch einen Ausdruck, wenn ein Fehler aufgetreten ist |
ERROR
|
Beendet die Auswertung und gibt einen Fehler mit der angegebenen Meldung zurück |
EXISTS
Syntax:
exists(value: ANY) -> BOOLEAN
Beschreibung:
Gibt TRUE zurück, wenn value nicht der fehlende Wert ist.
Beispiele:
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
Beispiel:
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
Beispiel:
val result = db.pipeline() .collection("books") .select(field("rating").exists().alias("hasRating")) .execute()
Java
Beispiel:
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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(exists(field("rating")).as("hasRating")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.FieldExists(firestore.FieldOf("rating")).As("hasRating"), )). Execute(ctx)
IS_ABSENT
Syntax:
is_absent(value: ANY) -> BOOLEAN
Beschreibung:
Gibt TRUE zurück, wenn value der fehlende Wert ist, andernfalls FALSE. Fehlende Werte sind Werte, die in der Eingabe fehlen, z. B. ein fehlendes Dokumentfeld.
Beispiele:
value |
is_absent(value) |
|---|---|
| 0L | FALSE |
| "foo" | FALSE |
NULL |
FALSE |
ABSENT |
TRUE |
IF_ABSENT
Syntax:
if_absent(value: ANY, replacement: ANY) -> ANY
Beschreibung:
Wenn value ein fehlender Wert ist, wird replacement ausgewertet und zurückgegeben. Andernfalls wird value zurückgegeben.
Beispiele:
value |
replacement |
if_absent(value, replacement) |
|---|---|---|
| 5L | 0L | 5L |
NULL |
0L | NULL |
ABSENT |
0L | 0L |
IS_ERROR
Syntax:
is_error(try: ANY) -> BOOLEAN
Beschreibung:
Gibt TRUE zurück, wenn bei der Auswertung von try ein Fehler auftritt. Andernfalls wird FALSE zurückgegeben.
IF_ERROR
Syntax:
if_error(try: ANY, catch: ANY) -> ANY
Beschreibung:
Wenn bei der Auswertung von try ein Fehler auftritt, wird replacement ausgewertet und zurückgegeben. Andernfalls wird der aufgelöste Wert von try zurückgegeben.
FEHLER
Syntax:
error(message: STRING) -> ANY
Beschreibung:
Die Auswertung der Funktion error führt dazu, dass die Auswertung der Pipeline mit einem Fehler beendet wird. Der angegebene message ist im Fehler enthalten.
Beispiele:
cond |
res |
switch_on(cond, res, error("no condition matched")) |
|---|---|---|
TRUE |
1L | 1L |
FALSE |
1L | ERROR ("no condition matched") |
Referenzfunktionen
Der Typ REFERENCE fungiert als „Zeiger“ auf andere Dokumente in der Datenbank (oder sogar in anderen Datenbanken). Mit den folgenden Funktionen kann dieser Typ während der Abfrageausführung bearbeitet werden.
| Name | Beschreibung |
COLLECTION_ID
|
Gibt die ID der Blatt-Sammlung im angegebenen Verweis zurück |
DOCUMENT_ID
|
Gibt die ID des Dokuments in der angegebenen Referenz zurück. |
PARENT
|
Gibt die übergeordnete Referenz zurück |
REFERENCE_SLICE
|
Gibt eine Teilmenge von Segmenten aus der angegebenen Referenz zurück |
COLLECTION_ID
Syntax:
collection_id(ref: REFERENCE) -> STRING
Beschreibung:
Gibt die Blatt-Sammlungs-ID des angegebenen REFERENCE zurück.
Beispiele:
ref |
collection_id(ref) |
|---|---|
users/user1 |
"users" |
users/user1/posts/post1 |
"posts" |
DOCUMENT_ID
Syntax:
document_id(ref: REFERENCE) -> ANY
Beschreibung:
Gibt die Dokument-ID des angegebenen REFERENCE zurück.
Beispiele:
ref |
document_id(ref) |
|---|---|
users/user1 |
"user1" |
users/user1/posts/post1 |
"post1" |
PARENT
Syntax:
parent(ref: REFERENCE) -> REFERENCE
Beschreibung:
Gibt das übergeordnete REFERENCE der angegebenen Referenz oder NULL zurück, wenn die Referenz bereits eine Stammreferenz ist.
Beispiele:
ref |
parent(ref) |
|---|---|
/ |
NULL |
users/user1 |
/ |
users/user1/posts/post1 |
users/user1 |
REFERENCE_SLICE
Syntax:
reference_slice(ref: REFERENCE, offset: INT, length: INT) -> REFERENCE
Beschreibung:
Ein REFERENCE ist eine Liste von (collection_id, document_id)-Tupeln. Damit können Sie eine Ansicht dieser Liste abrufen, genau wie bei array_slice(...).
Gibt ein neues REFERENCE zurück, das eine Teilmenge der Segmente des angegebenen ref ist.
offset: Der Startindex (0-basiert) des Segments. Wenn der Wert negativ ist, ist er ein Offset vom Ende der Referenz.length: Die Anzahl der Segmente, die in das Slice aufgenommen werden sollen.
Beispiele:
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 |
Logische Funktionen
| Name | Beschreibung |
AND
|
Führt ein logisches UND aus |
OR
|
Führt ein logisches ODER aus. |
XOR
|
Führt einen logischen XOR-Vorgang aus |
NOT
|
Führt ein logisches NICHT aus |
NOR
|
Führt einen logischen NOR-Vorgang aus |
CONDITIONAL
|
Verzweigt die Auswertung basierend auf einem bedingten Ausdruck. |
IF_NULL
|
Gibt den ersten Wert zurück, der nicht null ist |
SWITCH_ON
|
Verzweigt die Auswertung basierend auf einer Reihe von Bedingungen |
EQUAL_ANY
|
Prüft, ob ein Wert mit einem Element in einem Array übereinstimmt |
NOT_EQUAL_ANY
|
Prüft, ob ein Wert mit keinem Element in einem Array übereinstimmt |
MAXIMUM
|
Gibt den Maximalwert in einer Gruppe von Werten zurück. |
MINIMUM
|
Gibt den Minimalwert in einer Gruppe von Werten zurück |
UND
Syntax:
and(x: BOOLEAN...) -> BOOLEAN
Beschreibung:
Gibt das logische UND von zwei oder mehr booleschen Werten zurück.
Gibt NULL zurück, wenn das Ergebnis nicht abgeleitet werden kann, weil einer der angegebenen Werte ABSENT oder NULL ist.
Beispiele:
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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select( and(greaterThan(field("rating"), 4), lessThan(field("price"), 10)) .as("under10Recommendation")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.And( firestore.GreaterThan(firestore.FieldOf("rating"), 4), firestore.LessThan(firestore.FieldOf("price"), 10), ).As("under10Recommendation"), )). Execute(ctx)
ODER
Syntax:
or(x: BOOLEAN...) -> BOOLEAN
Beschreibung:
Gibt das logische ODER von zwei oder mehr booleschen Werten zurück.
Gibt NULL zurück, wenn das Ergebnis nicht abgeleitet werden kann, weil einer der angegebenen Werte ABSENT oder NULL ist.
Beispiele:
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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select( or(equal(field("genre"), "Fantasy"), arrayContains(field("tags"), "adventure")) .as("matchesSearchFilters")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.Or( firestore.Equal(firestore.FieldOf("genre"), "Fantasy"), firestore.ArrayContains(firestore.FieldOf("tags"), "adventure"), ).As("matchesSearchFilters"), )). Execute(ctx)
XOR
Syntax:
xor(x: BOOLEAN...) -> BOOLEAN
Beschreibung:
Gibt das logische XOR von zwei oder mehr booleschen Werten zurück.
Gibt NULL zurück, wenn einer der angegebenen Werte ABSENT oder NULL ist.
Beispiele:
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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select( xor( arrayContains(field("tags"), "magic"), arrayContains(field("tags"), "nonfiction")) .as("matchesSearchFilters")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.Xor( firestore.ArrayContains(firestore.FieldOf("tags"), "magic"), firestore.ArrayContains(firestore.FieldOf("tags"), "nonfiction"), ).As("matchesSearchFilters"), )). Execute(ctx)
NOR
Syntax:
nor(x: BOOLEAN...) -> BOOLEAN
Beschreibung:
Gibt das logische NOR von zwei oder mehr booleschen Werten zurück.
Gibt NULL zurück, wenn das Ergebnis nicht abgeleitet werden kann, weil einer der angegebenen Werte ABSENT oder NULL ist.
Beispiele:
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
Syntax:
not(x: BOOLEAN) -> BOOLEAN
Beschreibung:
Gibt das logische NICHT eines booleschen Werts zurück.
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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(not(arrayContains(field("tags"), "nonfiction")).as("isFiction")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.Not(firestore.ArrayContains(firestore.FieldOf("tags"), "nonfiction")).As("isFiction"), )). Execute(ctx)
BEDINGT
Syntax:
conditional(condition: BOOLEAN, true_case: ANY, false_case: ANY) -> ANY
Beschreibung:
Wertet true_case aus und gibt es zurück, wenn condition als TRUE ausgewertet wird.
Wertet false_case aus und gibt den Wert zurück, wenn die Bedingung zu FALSE, NULL oder einem ABSENT-Wert aufgelöst wird.
Beispiele:
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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select( arrayConcat( field("tags"), conditional( greaterThan(field("pages"), 100), constant("longRead"), constant("shortRead"))) .as("extendedTags")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.ArrayConcat( firestore.FieldOf("tags"), firestore.Conditional( firestore.GreaterThan(firestore.FieldOf("pages"), 100), firestore.ConstantOf("longRead"), firestore.ConstantOf("shortRead"), ), ).As("extendedTags"), )). Execute(ctx)
IF_NULL
Syntax:
if_null(expr: ANY, replacement: ANY) -> ANY
Beschreibung:
Gibt expr zurück, wenn es nicht NULL ist. Andernfalls wird replacement ausgewertet und zurückgegeben. Der Ausdruck replacement wird nicht ausgewertet, wenn expr verwendet wird.
Beispiele:
expr |
replacement |
if_null(expr, replacement) |
|---|---|---|
| 1L | 2L | 1L |
NULL |
2L | 2L |
ABSENT |
2L | ABSENT |
SWITCH_ON
Syntax:
switch_on(cond1: BOOLEAN, res1: ANY, cond2: BOOLEAN, res2: ANY, ..., [default: ANY]) -> ANY
Beschreibung:
Wertet eine Reihe von Bedingungen aus und gibt das Ergebnis zurück, das mit der ersten TRUE-Bedingung verknüpft ist. Wenn keine Bedingungen als TRUE ausgewertet werden, wird der Wert default zurückgegeben, sofern angegeben. Wenn kein default-Wert angegeben ist, wird ein Fehler ausgegeben, wenn keine anderen Bedingungen als TRUE ausgewertet wurden.
Wenn Sie einen default-Wert angeben möchten, übergeben Sie ihn als letztes Argument, sodass eine ungerade Anzahl von Argumenten vorhanden ist.
Beispiele:
x |
switch_on(eq(x, 1L), "one", eq(x, 2L), "two", "other") |
|---|---|
| 1L | "eins" |
| 2L | "zwei" |
| 3L | "other" |
EQUAL_ANY
Syntax:
equal_any(value: ANY, search_space: ARRAY) -> BOOLEAN
Beschreibung:
Gibt TRUE zurück, wenn value im Array search_space enthalten ist.
Beispiele:
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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select( equalAny(field("genre"), Arrays.asList("Science Fiction", "Psychological Thriller")) .as("matchesGenreFilters")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.EqualAny(firestore.FieldOf("genre"), []string{"Science Fiction", "Psychological Thriller"}).As("matchesGenreFilters"), )). Execute(ctx)
NOT_EQUAL_ANY
Syntax:
not_equal_any(value: ANY, search_space: ARRAY) -> BOOLEAN
Beschreibung:
Gibt TRUE zurück, wenn value nicht im Array search_space enthalten ist.
Beispiele:
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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select( notEqualAny(field("author"), Arrays.asList("George Orwell", "F. Scott Fitzgerald")) .as("byExcludedAuthors")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.NotEqualAny(firestore.FieldOf("author"), []string{"George Orwell", "F. Scott Fitzgerald"}).As("byExcludedAuthors"), )). Execute(ctx)
MAXIMAL
Syntax:
maximum(x: ANY...) -> ANY
maximum(x: ARRAY) -> ANY
Beschreibung:
Gibt den maximalen Wert ungleich NULL und ungleich ABSENT in einer Reihe von Werten x zurück.
Wenn keine Werte vorhanden sind, die weder NULL noch ABSENT sind, wird NULL zurückgegeben.
Wenn es mehrere maximale äquivalente Werte gibt, kann jeder dieser Werte zurückgegeben werden. Die Reihenfolge der Werttypen entspricht der dokumentierten Reihenfolge.
Beispiele:
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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(logicalMaximum(field("rating"), 1).as("flooredRating")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.LogicalMaximum(firestore.FieldOf("rating"), 1).As("flooredRating"), )). Execute(ctx)
MINIMUM
Syntax:
minimum(x: ANY...) -> ANY
minimum(x: ARRAY) -> ANY
Beschreibung:
Gibt den Mindestwert ungleich NULL und ungleich ABSENT in einer Reihe von Werten x zurück.
Wenn keine Werte vorhanden sind, die weder NULL noch ABSENT sind, wird NULL zurückgegeben.
Wenn es mehrere minimale äquivalente Werte gibt, kann jeder dieser Werte zurückgegeben werden. Die Reihenfolge der Werttypen entspricht der dokumentierten Reihenfolge.
Beispiele:
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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(logicalMinimum(field("rating"), 5).as("cappedRating")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.LogicalMinimum(firestore.FieldOf("rating"), 5).As("cappedRating"), )). Execute(ctx)
Kartenfunktionen
| Name | Beschreibung |
MAP
|
Erstellt einen Zuordnungswert aus einer Reihe von Schlüssel/Wert-Paaren |
MAP_GET
|
Gibt den Wert in einer Map für einen angegebenen Schlüssel zurück |
MAP_SET
|
Gibt eine Kopie einer Map mit einer Reihe aktualisierter Schlüssel zurück |
MAP_REMOVE
|
Gibt eine Kopie einer Map zurück, aus der eine Reihe von Schlüsseln entfernt wurde |
MAP_MERGE
|
Führt eine Reihe von Maps zusammen. |
CURRENT_CONTEXT
|
Gibt den aktuellen Kontext als Map zurück. |
MAP_KEYS
|
Gibt ein Array aller Schlüssel in einer Map zurück. |
MAP_VALUES
|
Gibt ein Array aller Werte in einer Map zurück. |
MAP_ENTRIES
|
Gibt ein Array von Schlüssel/Wert-Paaren einer Map zurück. |
MAP
Syntax:
map(key: STRING, value: ANY, ...) -> MAP
Beschreibung:
Erstellt eine Map aus einer Reihe von Schlüssel/Wert-Paaren.
MAP_GET
Syntax:
map_get(map: ANY, key: STRING) -> ANY
Beschreibung:
Gibt den Wert in einer Map für einen angegebenen Schlüssel zurück. Gibt einen ABSENT-Wert zurück, wenn der key nicht in der Zuordnung vorhanden ist oder wenn das Argument map kein MAP ist.
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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(mapGet(field("awards"), "pulitzer").as("hasPulitzerAward")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.MapGet(firestore.FieldOf("awards"), "pulitzer").As("hasPulitzerAward"), )). Execute(ctx)
MAP_SET
Syntax:
map_set(map: MAP, key: STRING, value: ANY, ...) -> MAP
Beschreibung:
Gibt eine Kopie des map-Werts zurück, dessen Inhalt durch eine Reihe von Schlüssel/Wert-Paaren aktualisiert wurde.
Wenn der angegebene Wert zu einem nicht vorhandenen Wert aufgelöst wird, wird der zugehörige Schlüssel aus der Zuordnung entfernt.
Wenn das Argument map kein MAP ist, wird ein fehlender Wert zurückgegeben.
MAP_REMOVE
Syntax:
map_remove(map: MAP, key: STRING...) -> MAP
Beschreibung:
Gibt eine Kopie des map-Werts zurück, wobei eine Reihe von Schlüsseln entfernt wurde.
MAP_MERGE
Syntax:
map_merge(maps: MAP...) -> MAP
Führt die Inhalte von zwei oder mehr Maps zusammen. Wenn mehrere Zuordnungen widersprüchliche Werte haben, wird der letzte Wert verwendet.
CURRENT_CONTEXT
Syntax:
current_context() -> MAP
Gibt eine Zuordnung zurück, die alle verfügbaren Felder am aktuellen Ausführungspunkt enthält.
MAP_KEYS
Syntax:
map_keys(map: MAP) -> ARRAY<STRING>
Beschreibung:
Gibt ein Array zurück, das alle Schlüssel des map-Werts enthält.
MAP_VALUES
Syntax:
map_values(map: MAP) -> ARRAY<ANY>
Beschreibung:
Gibt ein Array zurück, das alle Werte des map-Werts enthält.
MAP_ENTRIES
Syntax:
map_entries(map: MAP) -> ARRAY<MAP>
Beschreibung:
Gibt ein Array mit allen Schlüssel/Wert-Paaren im map-Wert zurück.
Jedes Schlüssel/Wert-Paar hat die Form einer Zuordnung mit zwei Einträgen, k und v.
Beispiele:
map |
map_entries(map) |
|---|---|
| {} | [] |
| {"foo" : 2L} | [{"k": "foo", "v" : 2L}] |
| {"foo" : "bar", "bar" : "foo"} | [{"k": "foo", "v" : "bar" }, {"k" : "bar", "v": "foo"}] |
Stringfunktionen
| Name | Beschreibung |
BYTE_LENGTH
|
Gibt die Anzahl der BYTES in einem STRING- oder BYTES-Wert zurück
|
CHAR_LENGTH
|
Gibt die Anzahl der Unicode-Zeichen in einem STRING-Wert zurück
|
STARTS_WITH
|
Gibt TRUE zurück, wenn ein STRING mit einem bestimmten Präfix beginnt
|
ENDS_WITH
|
Gibt TRUE zurück, wenn ein STRING mit einem bestimmten Postfix endet
|
LIKE
|
Gibt TRUE zurück, wenn ein STRING mit einem Muster übereinstimmt.
|
REGEX_CONTAINS
|
Gibt TRUE zurück, wenn ein Wert teilweise oder vollständig mit einem regulären Ausdruck übereinstimmt
|
REGEX_FIND
|
Gibt den ersten Teilstring zurück, der mit einem regulären Ausdruck übereinstimmt, oder NULL, wenn keine Übereinstimmung gefunden wird.
|
REGEX_FIND_ALL
|
Gibt ein Array aller Teilstrings zurück, die mit einem regulären Ausdruck übereinstimmen, oder ein leeres Array, wenn es keine Übereinstimmungen gibt. |
REGEX_MATCH
|
Gibt TRUE zurück, wenn ein Teil eines Werts mit einem regulären Ausdruck übereinstimmt.
|
STRING_CONCAT
|
Verkettet mehrere STRING zu einem STRING
|
STRING_CONTAINS
|
Gibt TRUE zurück, wenn ein Wert einen STRING-Wert enthält.
|
STRING_INDEX_OF
|
Gibt den nullbasierten Index des ersten Vorkommens eines STRING- oder BYTES-Werts zurück.
|
TO_UPPER
|
Wandelt einen STRING- oder BYTES-Wert in Großbuchstaben um.
|
TO_LOWER
|
Wandelt einen STRING- oder BYTES-Wert in Kleinbuchstaben um.
|
SUBSTRING
|
Ruft einen Teilstring eines STRING- oder BYTES-Werts ab.
|
STRING_REVERSE
|
Kehrt einen STRING- oder BYTES-Wert um.
|
STRING_REPEAT
|
Wiederholt einen STRING- oder BYTES-Wert so oft wie angegeben.
|
STRING_REPLACE_ALL
|
Ersetzt alle Vorkommen eines STRING- oder BYTES-Werts.
|
STRING_REPLACE_ONE
|
Ersetzt das erste Vorkommen eines STRING- oder BYTES-Werts.
|
TRIM
|
Entfernt vor- und nachgestellte Zeichen aus einem STRING- oder BYTES-Wert.
|
LTRIM
|
Entfernt vorangestellte Zeichen aus einem STRING- oder BYTES-Wert.
|
RTRIM
|
Entfernt nachgestellte Zeichen aus einem STRING- oder BYTES-Wert.
|
SPLIT
|
Teilt einen STRING- oder BYTES-Wert in ein Array auf.
|
BYTE_LENGTH
Syntax:
byte_length[T <: STRING | BYTES](value: T) -> INT64
Beschreibung:
Gibt die Anzahl der BYTES in einem STRING- oder BYTES-Wert zurück.
Beispiele:
| Wert | 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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(byteLength(field("title")).as("titleByteLength")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.ByteLength(firestore.FieldOf("title")).As("titleByteLength"), )). Execute(ctx)
CHAR_LENGTH
Syntax:
char_length(value: STRING) -> INT64
Beschreibung:
Gibt die Anzahl der Unicode-Codepunkte im STRING-Wert zurück.
Beispiele:
| Wert | 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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(charLength(field("title")).as("titleCharLength")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.CharLength(firestore.FieldOf("title")).As("titleCharLength"), )). Execute(ctx)
STARTS_WITH
Syntax:
starts_with(value: STRING, prefix: STRING) -> BOOLEAN
Beschreibung:
Gibt TRUE zurück, wenn value mit prefix beginnt.
Beispiele:
| Wert | Präfix | starts_with(value, prefix) |
|---|---|---|
| "abc" | „a“ | wahr |
| "abc" | "b" | falsch |
| "abc" | "" | wahr |
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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(startsWith(field("title"), "The").as("needsSpecialAlphabeticalSort")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.StartsWith(firestore.FieldOf("title"), "The").As("needsSpecialAlphabeticalSort"), )). Execute(ctx)
ENDS_WITH
Syntax:
ends_with(value: STRING, postfix: STRING) -> BOOLEAN
Beschreibung:
Gibt TRUE zurück, wenn value mit postfix endet.
Beispiele:
| Wert | postfix | ends_with(value, postfix) |
|---|---|---|
| "abc" | "c" | wahr |
| "abc" | "b" | falsch |
| "abc" | "" | wahr |
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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("inventory/devices/laptops") .select(endsWith(field("name"), "16 inch").as("16InLaptops")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("inventory/devices/laptops"). Select(firestore.Fields( firestore.EndsWith(firestore.FieldOf("name"), "16 inch").As("`Laptops16in`"), )). Execute(ctx)
LIKE
Syntax:
like(value: STRING, pattern: STRING) -> BOOLEAN
Beschreibung:
Gibt TRUE zurück, wenn value mit pattern übereinstimmt.
Beispiele:
| Wert | Muster | like(value, pattern) |
|---|---|---|
| "Firestore" | "Fire%" | wahr |
| "Firestore" | „%store“ | wahr |
| „Datastore“ | "Data_tore" | wahr |
| "100%" | "100\%" | wahr |
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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(like(field("genre"), "%Fiction").as("anyFiction")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.Like(firestore.FieldOf("genre"), "%Fiction").As("anyFiction"), )). Execute(ctx)
REGEX_CONTAINS
Syntax:
regex_contains(value: STRING, regexp: STRING | REGEX) -> BOOLEAN
Beschreibung:
Gibt TRUE zurück, wenn ein Teil von value mit regexp übereinstimmt. Wenn regexp kein gültiger regulärer Ausdruck ist, gibt diese Funktion einen error zurück.
Das Argument regexp kann auch ein REGEX-Wert sein, der mit regex("pattern", "options") erstellt wurde. In diesem Format können Sie Optionen für reguläre Ausdrücke zusammen mit dem Muster angeben. Die folgenden Optionen werden unterstützt:
i: Übereinstimmung ohne Berücksichtigung der Groß-/Kleinschreibung.m: Mehrzeiliger Modus (^und$entsprechen dem Anfang oder Ende von Zeilen).s: Dotall-Modus (.entspricht Zeilenumbrüchen).
Wenn regexp ein STRING ist, werden außer den im Muster selbst eingebetteten Optionen (z.B. (?i)) keine Optionen angewendet.
Reguläre Ausdrücke folgen der Syntax der re2-Bibliothek.
Beispiele:
| Wert | RegExp | regex_contains(value, regexp) |
|---|---|---|
| "Firestore" | "Feuer" | wahr |
| "Firestore" | "store$" | wahr |
| "Firestore" | "data" | falsch |
| "Firestore" | regex("fire", "i") |
wahr |
| "Firestore" | regex("FIRE", "") |
falsch |
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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("documents") .select( regexContains(field("title"), "Firestore (Enterprise|Standard)") .as("isFirestoreRelated")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("documents"). Select(firestore.Fields( firestore.RegexContains(firestore.FieldOf("title"), "Firestore (Enterprise|Standard)").As("isFirestoreRelated"), )). Execute(ctx)
REGEX_FIND
Syntax:
regex_find(value: STRING, regexp: STRING | REGEX) -> STRING
Beschreibung:
Gibt den ersten Teilstring in value zurück, der mit regexp übereinstimmt, oder NULL, wenn es keine Übereinstimmung gibt. Wenn regexp kein gültiger regulärer Ausdruck ist, gibt diese Funktion einen error zurück.
Das Argument regexp kann auch ein REGEX-Wert sein, der mit regex("pattern", "options") erstellt wurde. In diesem Format können Sie Optionen für reguläre Ausdrücke zusammen mit dem Muster angeben. Die folgenden Optionen werden unterstützt:
i: Übereinstimmung ohne Berücksichtigung der Groß-/Kleinschreibung.m: Mehrzeiliger Modus (^und$entsprechen dem Anfang oder Ende von Zeilen).s: Dotall-Modus (.entspricht Zeilenumbrüchen).
Wenn regexp ein STRING ist, werden außer den im Muster selbst eingebetteten Optionen (z.B. (?i)) keine Optionen angewendet.
Reguläre Ausdrücke folgen der Syntax der re2-Bibliothek.
Beispiele:
| Wert | RegExp | regex_find(value, regexp) |
|---|---|---|
| "Sometext MATCH" | "SomeText" | "Sometext" |
| "Sometext MATCH" | regex("match", "i") |
„MATCH“ |
| "Sometext MATCH" | regex("(match)", "i") |
„MATCH“ |
| „Sometext match“ | regex("MATCH", "") |
null |
REGEX_FIND_ALL
Syntax:
regex_find_all(value: STRING, regexp: STRING | REGEX) -> ARRAY<STRING>
Beschreibung:
Gibt ein Array aller Teilstrings in value zurück, die mit regexp übereinstimmen, oder ein leeres Array, wenn es keine Übereinstimmungen gibt. Wenn regexp kein gültiger regulärer Ausdruck ist, gibt diese Funktion einen error zurück.
Das Argument regexp kann auch ein REGEX-Wert sein, der mit regex("pattern", "options") erstellt wurde. In diesem Format können Sie Optionen für reguläre Ausdrücke zusammen mit dem Muster angeben. Die folgenden Optionen werden unterstützt:
i: Übereinstimmung ohne Berücksichtigung der Groß-/Kleinschreibung.m: Mehrzeiliger Modus (^und$entsprechen dem Anfang oder Ende von Zeilen).s: Dotall-Modus (.entspricht Zeilenumbrüchen).
Wenn regexp ein STRING ist, werden außer den im Muster selbst eingebetteten Optionen (z.B. (?i)) keine Optionen angewendet.
Reguläre Ausdrücke folgen der Syntax der re2-Bibliothek.
Beispiele:
| Wert | RegExp | regex_find_all(value, regexp) |
|---|---|---|
| "one two three two" | "eins" | ["one"] |
| "one TWO three Two" | regex("two", "i") |
["TWO", "Two"] |
| "one two three two" | regex("TWO", "") |
[] |
REGEX_MATCH
Syntax:
regex_match(value: STRING, regexp: STRING | REGEX) -> BOOLEAN
Beschreibung:
Gibt TRUE zurück, wenn value vollständig mit regexp übereinstimmt. Wenn regexp kein gültiger regulärer Ausdruck ist, gibt diese Funktion einen error zurück.
Das Argument regexp kann auch ein REGEX-Wert sein, der mit regex("pattern", "options") erstellt wurde. In diesem Format können Sie Optionen für reguläre Ausdrücke zusammen mit dem Muster angeben. Die folgenden Optionen werden unterstützt:
i: Übereinstimmung ohne Berücksichtigung der Groß-/Kleinschreibung.m: Mehrzeiliger Modus (^und$entsprechen dem Anfang oder Ende von Zeilen).s: Dotall-Modus (.entspricht Zeilenumbrüchen).
Wenn regexp ein STRING ist, werden außer den im Muster selbst eingebetteten Optionen (z.B. (?i)) keine Optionen angewendet.
Reguläre Ausdrücke folgen der Syntax der re2-Bibliothek.
Beispiele:
| Wert | RegExp | regex_match(value, regexp) |
|---|---|---|
| "Firestore" | "F.*store" | wahr |
| "Firestore" | "Feuer" | falsch |
| "Firestore" | "^F.*e$" | wahr |
| „FiReStOrE“ | regex("firestore", "i") |
wahr |
| "Firestore" | regex("firestore", "") |
falsch |
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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("documents") .select( regexMatch(field("title"), "Firestore (Enterprise|Standard)") .as("isFirestoreExactly")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("documents"). Select(firestore.Fields( firestore.RegexMatch(firestore.FieldOf("title"), "Firestore (Enterprise|Standard)").As("isFirestoreExactly"), )). Execute(ctx)
STRING_CONCAT
Syntax:
string_concat(values: STRING...) -> STRING
Beschreibung:
Verkettet zwei oder mehr STRING-Werte zu einem einzigen Ergebnis.
Beispiele:
| Argumente | string_concat(values...) |
|---|---|
() |
Fehler |
("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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(stringConcat(field("title"), " by ", field("author")).as("fullyQualifiedTitle")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.StringConcat(firestore.FieldOf("title"), " by ", firestore.FieldOf("author")).As("fullyQualifiedTitle"), )). Execute(ctx)
STRING_CONTAINS
Syntax:
string_contains(value: STRING, substring: STRING) -> BOOLEAN
Beschreibung:
Prüft, ob value den Stringliteral substring enthält.
Beispiele:
| Wert | Teilstring | string_contains(value, substring) |
|---|---|---|
| "abc" | "b" | wahr |
| "abc" | "d" | falsch |
| "abc" | "" | wahr |
| "a.c" | "." | wahr |
| "☃☃☃" | "☃" | wahr |
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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("articles") .select(stringContains(field("body"), "Firestore").as("isFirestoreRelated")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("articles"). Select(firestore.Fields( firestore.StringContains(firestore.FieldOf("body"), "Firestore").As("isFirestoreRelated"), )). Execute(ctx)
STRING_INDEX_OF
Syntax:
string_index_of[T <: STRING | BYTES](value: T, search: T) -> INT64
Beschreibung:
Gibt den 0-basierten Index des ersten Vorkommens von search in value zurück.
- Gibt
-1zurück, wennsearchnicht gefunden wird. - Wenn
valueeinSTRING-Wert ist, wird das Ergebnis in Unicode-Codepunkten gemessen. Wenn es sich um einenBYTES-Wert handelt, wird er in Byte gemessen. - Wenn
searchein leererSTRING- oderBYTES-Wert ist, ist das Ergebnis0.
Beispiele:
| Wert | search | string_index_of(value, search) |
|---|---|---|
| "hello world" | "o" | 4 |
| "hello world" | "l" | 2 |
| "hello world" | "z" | -1 |
| "banana" | "ana" | 1 |
| "abc" | "" | 0 |
| b"abc" | b"b" | 1 |
| "é" | "é" | 0 |
| b"é" | b"é" | 0 |
TO_UPPER
Syntax:
to_upper[T <: STRING | BYTES](value: T) -> T
Beschreibung:
Wandelt einen STRING- oder BYTES-Wert in Großbuchstaben um.
Wenn ein Byte oder Zeichen keinem UTF-8-Kleinbuchstaben entspricht, wird es unverändert weitergegeben.
Beispiele:
| Wert | 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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("authors") .select(toUpper(field("name")).as("uppercaseName")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("authors"). Select(firestore.Fields( firestore.ToUpper(firestore.FieldOf("name")).As("uppercaseName"), )). Execute(ctx)
TO_LOWER
Syntax:
to_lower[T <: STRING | BYTES](value: T) -> T
Beschreibung:
Wandelt einen STRING- oder BYTES-Wert in Kleinbuchstaben um.
Wenn ein Byte oder Zeichen keinem UTF-8-Großbuchstaben entspricht, wird es unverändert weitergegeben.
Beispiele:
| Wert | 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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("authors") .select(equal(toLower(field("genre")), "fantasy").as("isFantasy")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("authors"). Select(firestore.Fields( firestore.Equal(firestore.ToLower(firestore.FieldOf("genre")), "fantasy").As("isFantasy"), )). Execute(ctx)
SUBSTRING
Syntax:
substring[T <: STRING | BYTES](input: T, position: INT64) -> T
substring[T <: STRING | BYTES](input: T, position: INT64, length: INT64) -> T
Beschreibung:
Gibt einen Teilstring von input zurück, beginnend bei position (nullbasierter Index) und mit bis zu length Einträgen. Wenn kein length angegeben ist, wird der Teilstring von position bis zum Ende von input zurückgegeben.
Wenn
inputeinSTRING-Wert ist, werdenpositionundlengthin Unicode-Codepunkten gemessen. Wenn es sich um einenBYTES-Wert handelt, wird er in Byte gemessen.Wenn
positiongrößer als die Länge voninputist, wird ein leerer Teilstring zurückgegeben. Wennpositionpluslengthgrößer als die Länge voninputist, wird der Teilstring bis zum Ende voninputabgeschnitten.Wenn
positionnegativ ist, wird die Position vom Ende der Eingabe genommen. Wenn der negativepositiongrößer als die Größe der Eingabe ist, wird die Position auf null gesetzt.lengthdarf nicht negativ sein.
Beispiele:
Wenn length nicht angegeben ist:
| Eingabe | position | substring(input, position) |
|---|---|---|
| "abc" | 0 | "abc" |
| "abc" | 1 | "bc" |
| "abc" | 3 | "" |
| "abc" | -1 | "c" |
| b"abc" | 1 | b"bc" |
Wenn length angegeben wurde, geschieht Folgendes:
| Eingabe | position | Länge | 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() )
Java
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();
Go
snapshot := client.Pipeline(). Collection("books"). Where(firestore.StartsWith(firestore.FieldOf("title"), "The ")). Select(firestore.Fields( firestore.Substring(firestore.FieldOf("title"), firestore.ConstantOf(4), firestore.FieldOf("title").CharLength()).As("titleWithoutLeadingThe"), )). Execute(ctx)
STRING_REVERSE
Syntax:
string_reverse[T <: STRING | BYTES](input: T) -> T
Beschreibung:
Gibt die angegebene Eingabe in umgekehrter Reihenfolge zurück.
Zeichen werden durch Unicode-Codepunkte abgegrenzt, wenn die Eingabe ein STRING-Wert ist, und durch Byte, wenn die Eingabe ein BYTES-Wert ist.
Beispiele:
| Eingabe | 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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(reverse(field("name")).as("reversedName")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.Reverse(firestore.FieldOf("name")).As("reversedName"), )). Execute(ctx)
STRING_REPEAT
Syntax:
string_repeat[T <: STRING | BYTES](input: T, repetitions: INT64) -> T
Beschreibung:
Gibt input repetitions-mal wiederholt zurück.
repetitionsmuss eine nicht negative Ganzzahl sein.- Wenn
repetitionsden Wert0hat, wird ein leerer Wert desselben Typs wieinputzurückgegeben. - Wenn das Ergebnis die maximal zulässige Größe (1 MB) überschreitet, wird ein Fehler zurückgegeben.
Beispiele:
| Eingabe | Wiederholungen | string_repeat(input, repetitions) |
|---|---|---|
| "foo" | 3 | "foofoofoo" |
| "foo" | 0 | "" |
| "a " | 3 | "a a a " |
| b"ab" | 2 | b"abab" |
| „é🦆“ | 2 | „é🦆é🦆“ |
STRING_REPLACE_ALL
Syntax:
string_replace_all[T <: STRING | BYTES](input: T, find: T, replacement: T) -> T
Beschreibung:
Ersetzt alle nicht überlappenden Vorkommen von find in input durch replacement.
- Bei Übereinstimmungen wird zwischen Groß- und Kleinschreibung unterschieden.
- Wenn
findleer ist, werden keine Ersetzungen vorgenommen.
Beispiele:
| Eingabe | finden | Ersetzen | 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
Syntax:
string_replace_one[T <: STRING | BYTES](input: T, find: T, replacement: T) -> T
Beschreibung:
Ersetzt das erste Vorkommen von find in input durch replacement.
- Bei Übereinstimmungen wird zwischen Groß- und Kleinschreibung unterschieden.
- Wenn
findleer ist, werden keine Ersetzungen vorgenommen.
Beispiele:
| Eingabe | finden | Ersetzen | string_replace_one(input, find, replacement) |
|---|---|---|---|
| "foobarfoo" | "foo" | "baz" | "bazbarfoo" |
| "é" | "é" | „a“ | „a“ |
| b"foobar" | b"o" | b"z" | b"fzoobar" |
TRIM
Syntax:
trim[T <: STRING | BYTES](input: T, values_to_trim: T) -> T
trim[T <: STRING | BYTES](input: T) -> T
Beschreibung:
Entfernt einen angegebenen Satz von BYTES oder CHARS am Anfang und Ende des angegebenen input.
- Wenn keine
values_to_trimangegeben sind, werden Leerzeichen entfernt.
Beispiele:
Wenn values_to_trim nicht angegeben ist:
| Eingabe | 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" |
Wenn values_to_trim angegeben wurde, geschieht Folgendes:
| Eingabe | values_to_trim | trim(input, values_to_trim) |
|---|---|---|
| "abcbfooaacb" | "abc" | "foo" |
| "abcdaabadbac" | "abc" | "daabad" |
| b"C1C2C3" | b"C1" | b"C2C3" |
| b"C1C2" | "foo" | Fehler |
| "foo" | b"C1" | Fehler |
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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(trim(field("name")).as("whitespaceTrimmedName")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.Trim(firestore.FieldOf("name")).As("whitespaceTrimmedName"), )). Execute(ctx)
LTRIM
Syntax:
ltrim[T <: STRING | BYTES](value: T, to_trim: T) -> T
ltrim[T <: STRING | BYTES](value: T) -> T
Beschreibung:
Entfernt einen angegebenen Satz von BYTES oder CHARS vom Anfang des angegebenen value.
- Wenn
to_trimnicht angegeben ist, werden führende Leerzeichen entfernt.
Beispiele:
Wenn to_trim nicht angegeben ist:
| Wert | ltrim(value) |
|---|---|
| " foo " | "foo " |
| "foo" | "foo" |
Wenn to_trim angegeben wurde, geschieht Folgendes:
| Wert | to_trim | ltrim(value, to_trim) |
|---|---|---|
| "aaabc" | „a“ | "bc" |
| "abacaba" | "ba" | "caba" |
| "é" | "é" | "" |
RTRIM
Syntax:
rtrim[T <: STRING | BYTES](value: T, to_trim: T) -> T
rtrim[T <: STRING | BYTES](value: T) -> T
Beschreibung:
Entfernt einen angegebenen Satz von BYTES oder CHARS vom Ende des angegebenen value.
- Wenn
to_trimnicht angegeben ist, werden nachfolgende Leerzeichen entfernt.
Beispiele:
Wenn to_trim nicht angegeben ist:
| Wert | rtrim(value) |
|---|---|
| " foo " | " foo" |
| "foo" | "foo" |
Wenn to_trim angegeben wurde, geschieht Folgendes:
| Wert | to_trim | rtrim(value, to_trim) |
|---|---|---|
| "abccc" | "c" | "ab" |
| "abacaba" | "ba" | "abac" |
| "é" | "é" | "" |
SPLIT
Syntax:
split(input: STRING) -> ARRAY<STRING>
split[T <: STRING | BYTES](input: T, delimiter: T) -> ARRAY<T>
Beschreibung:
Teilt einen STRING- oder BYTES-Wert mithilfe eines Trennzeichens auf.
Für
STRINGist das Standardtrennzeichen das Komma,. Das Trennzeichen wird als einzelner String behandelt.Für
BYTESmüssen Sie ein Trennzeichen angeben.Wenn Sie einen leeren Trenner verwenden, wird ein Array von Unicode-Codepunkten für
STRING-Werte und ein Array vonBYTESfürBYTES-Werte erzeugt.Das Aufteilen eines leeren
STRINGgibt einARRAYaus einem einzelnen leerenSTRINGzurück.
Beispiele:
Wenn delimiter nicht angegeben ist:
| Eingabe | split(input) |
|---|---|
| "foo,bar,foo" | ["foo", "bar", "foo"] |
| "foo" | ["foo"] |
| ",foo," | ["", "foo", ""] |
| "" | [""] |
| b"C120C2C4" | Fehler |
Wenn delimiter angegeben wurde, geschieht Folgendes:
| Eingabe | 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" | Fehler |
Zeitstempelfunktionen
| Name | Beschreibung |
CURRENT_TIMESTAMP
|
Generiert einen TIMESTAMP, der der Anfragezeit entspricht.
|
TIMESTAMP_TRUNC
|
Kürzt einen TIMESTAMP-Wert auf eine bestimmte Granularität.
|
UNIX_MICROS_TO_TIMESTAMP
|
Wandelt die Anzahl der Mikrosekunden seit 1970-01-01 00:00:00 UTC in einen TIMESTAMP um.
|
UNIX_MILLIS_TO_TIMESTAMP
|
Wandelt die Anzahl der Millisekunden seit 1970-01-01 00:00:00 UTC in einen TIMESTAMP um
|
UNIX_SECONDS_TO_TIMESTAMP
|
Konvertiert die Anzahl der Sekunden seit 1970-01-01 00:00:00 UTC in einen TIMESTAMP.
|
TIMESTAMP_ADD
|
Fügt einem TIMESTAMP ein Zeitintervall hinzu
|
TIMESTAMP_SUB
|
Subtrahiert ein Zeitintervall von einem TIMESTAMP
|
TIMESTAMP_TO_UNIX_MICROS
|
Wandelt einen TIMESTAMP-Wert in die Anzahl der Mikrosekunden seit 1970-01-01 00:00:00 UTC um.
|
TIMESTAMP_TO_UNIX_MILLIS
|
Wandelt einen TIMESTAMP in die Anzahl der Millisekunden seit 1970-01-01 00:00:00 UTC um
|
TIMESTAMP_TO_UNIX_SECONDS
|
Wandelt einen TIMESTAMP in die Anzahl der Sekunden seit 1970-01-01 00:00:00 UTC um
|
TIMESTAMP_DIFF
|
Gibt die ganze Zahl der angegebenen unit-Intervalle zwischen zwei TIMESTAMP-Werten zurück.
|
TIMESTAMP_EXTRACT
|
Extrahiert einen bestimmten part (z.B. Jahr, Monat, Tag) aus einem TIMESTAMP.
|
CURRENT_TIMESTAMP
Syntax:
current_timestamp() -> TIMESTAMP
Beschreibung:
Ruft den Zeitstempel am Anfang der Anfragezeit input ab (interpretiert als Anzahl der Mikrosekunden seit 1970-01-01 00:00:00 UTC).
Dieser Wert ist innerhalb einer Abfrage stabil und wird immer in denselben Wert aufgelöst, wenn er mehrmals aufgerufen wird.
TIMESTAMP_TRUNC
Syntax:
timestamp_trunc(timestamp: TIMESTAMP | BSON_TIMESTAMP, granularity: STRING[, timezone: STRING]) -> TIMESTAMP
Beschreibung:
Kürzt einen Zeitstempel auf eine bestimmte Granularität.
Das Argument granularity muss ein String und einer der folgenden Werte sein:
microsecondmillisecondsecondminutehourdayweekweek([weekday])monthquarteryearisoyear
Wenn das Argument timezone angegeben ist, basiert die Kürzung auf den Kalendergrenzen der angegebenen Zeitzone (z.B. wird die Kürzung auf den Tag in der angegebenen Zeitzone auf Mitternacht gekürzt). Bei der Kürzung wird die Sommerzeit berücksichtigt.
Wenn timezone nicht angegeben ist, basiert die Kürzung auf den Kalendergrenzen von UTC.
Das Argument timezone sollte eine Stringdarstellung einer Zeitzone aus der tz-Datenbank sein, z. B. America/New_York. Sie können auch einen benutzerdefinierten Zeitversatz verwenden, indem Sie einen Versatz von GMT angeben.
Beispiele:
timestamp |
granularity |
timezone |
timestamp_trunc(timestamp, granularity, timezone) |
|---|---|---|---|
| 2000-01-01 10:20:30:123456 UTC | „second“ | Nicht bereitgestellt | 2001-01-01 10:20:30 UTC |
| 1997-05-31 04:30:30 UTC | "day" | Nicht bereitgestellt | 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) | Nicht bereitgestellt | 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
Syntax:
unix_micros_to_timestamp(input: INT64) -> TIMESTAMP
Beschreibung:
Konvertiert input (interpretiert als die Anzahl der Mikrosekunden seit 1970-01-01 00:00:00 UTC) in einen TIMESTAMP. Löst einen error aus, wenn input nicht in einen gültigen TIMESTAMP konvertiert werden kann.
Beispiele:
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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("documents") .select(unixMicrosToTimestamp(field("createdAtMicros")).as("createdAtString")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("documents"). Select(firestore.Fields( firestore.UnixMicrosToTimestamp(firestore.FieldOf("createdAtMicros")).As("createdAtString"), )). Execute(ctx)
UNIX_MILLIS_TO_TIMESTAMP
Syntax:
unix_millis_to_timestamp(input: INT64) -> TIMESTAMP
Beschreibung:
Konvertiert input (interpretiert als Anzahl der Millisekunden seit 1970-01-01 00:00:00 UTC) in einen TIMESTAMP. Löst einen error aus, wenn input nicht in einen gültigen TIMESTAMP konvertiert werden kann.
Beispiele:
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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("documents") .select(unixMillisToTimestamp(field("createdAtMillis")).as("createdAtString")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("documents"). Select(firestore.Fields( firestore.UnixMillisToTimestamp(firestore.FieldOf("createdAtMillis")).As("createdAtString"), )). Execute(ctx)
UNIX_SECONDS_TO_TIMESTAMP
Syntax:
unix_seconds_to_timestamp(input: INT64) -> TIMESTAMP
Beschreibung:
Konvertiert input (interpretiert als Anzahl der Sekunden seit 1970-01-01 00:00:00 UTC) in einen TIMESTAMP. Löst einen error aus, wenn input nicht in einen gültigen TIMESTAMP konvertiert werden kann.
Beispiele:
input |
unix_seconds_to_timestamp(input) |
|---|---|
| 0L | 1970-01-01 00:00:00 UTC |
| 60 l | 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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("documents") .select(unixSecondsToTimestamp(field("createdAtSeconds")).as("createdAtString")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("documents"). Select(firestore.Fields( firestore.UnixSecondsToTimestamp(firestore.FieldOf("createdAtSeconds")).As("createdAtString"), )). Execute(ctx)
TIMESTAMP_ADD
Syntax:
timestamp_add(timestamp: TIMESTAMP | BSON_TIMESTAMP, unit: STRING, amount: INT64) -> TIMESTAMP
Beschreibung:
Fügt ein amount von unit aus timestamp hinzu. Das Argument amount kann negativ sein. In diesem Fall entspricht es TIMESTAMP_SUB.
Das Argument unit muss ein String und einer der folgenden Werte sein:
microsecondmillisecondsecondminutehourday
Löst einen Fehler aus, wenn der resultierende Zeitstempel nicht in den TIMESTAMP-Bereich passt.
Beispiele:
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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("documents") .select(timestampAdd(field("createdAt"), "day", 3653).as("expiresAt")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("documents"). Select(firestore.Fields( firestore.TimestampAdd(firestore.FieldOf("createdAt"), "day", 3653).As("expiresAt"), )). Execute(ctx)
TIMESTAMP_SUB
Syntax:
timestamp_sub(timestamp: TIMESTAMP | BSON_TIMESTAMP, unit: STRING, amount: INT64) -> TIMESTAMP
Beschreibung:
Subtrahiert einen amount von unit von timestamp. Das Argument amount kann negativ sein. In diesem Fall entspricht es TIMESTAMP_ADD.
Das Argument unit muss ein String und einer der folgenden Werte sein:
microsecondmillisecondsecondminutehourday
Löst einen Fehler aus, wenn der resultierende Zeitstempel nicht in den TIMESTAMP-Bereich passt.
Beispiele:
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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("documents") .select(timestampSubtract(field("expiresAt"), "day", 14).as("sendWarningTimestamp")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("documents"). Select(firestore.Fields( firestore.TimestampSubtract(firestore.FieldOf("expiresAt"), "day", 14).As("sendWarningTimestamp"), )). Execute(ctx)
TIMESTAMP_TO_UNIX_MICROS
Syntax:
timestamp_to_unix_micros(input: TIMESTAMP | BSON_TIMESTAMP) -> INT64
Beschreibung:
Wandelt input in die Anzahl der Mikrosekunden seit 1970-01-01 00:00:00 UTC um.
Nachkommastellen werden durch das Abrunden auf den Anfang der Mikrosekunde abgeschnitten.
Beispiele:
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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("documents") .select(timestampToUnixMicros(field("dateString")).as("unixMicros")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("documents"). Select(firestore.Fields( firestore.TimestampToUnixMicros(firestore.FieldOf("dateString")).As("unixMicros"), )). Execute(ctx)
TIMESTAMP_TO_UNIX_MILLIS
Syntax:
timestamp_to_unix_millis(input: TIMESTAMP | BSON_TIMESTAMP) -> INT64
Beschreibung:
Wandelt input in die Anzahl der Millisekunden seit 1970-01-01 00:00:00 UTC um.
Nachkommastellen werden durch das Abrunden auf den Anfang der Millisekunde abgeschnitten.
Beispiele:
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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("documents") .select(timestampToUnixMillis(field("dateString")).as("unixMillis")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("documents"). Select(firestore.Fields( firestore.TimestampToUnixMillis(firestore.FieldOf("dateString")).As("unixMillis"), )). Execute(ctx)
TIMESTAMP_TO_UNIX_SECONDS
Syntax:
timestamp_to_unix_seconds(input: TIMESTAMP | BSON_TIMESTAMP) -> INT64
Beschreibung:
Konvertiert input in die Anzahl der Sekunden seit 1970-01-01 00:00:00 UTC.
Nachkommastellen werden durch das Abrunden auf den Anfang der Sekunde abgeschnitten.
Beispiele:
input |
timestamp_to_unix_seconds(input) |
|---|---|
| 1970-01-01 00:00:00 UTC | 0L |
| 1970-01-01 00:01:00 UTC | 60 l |
| 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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("documents") .select(timestampToUnixSeconds(field("dateString")).as("unixSeconds")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("documents"). Select(firestore.Fields( firestore.TimestampToUnixSeconds(firestore.FieldOf("dateString")).As("unixSeconds"), )). Execute(ctx)
TIMESTAMP_DIFF
Syntax:
timestamp_diff(end: TIMESTAMP | BSON_TIMESTAMP, start: TIMESTAMP | BSON_TIMESTAMP, unit: STRING) -> INT64
Beschreibung:
Gibt die ganze Zahl der angegebenen unit-Intervalle zwischen zwei TIMESTAMP-Werten zurück.
- Gibt einen negativen Wert zurück, wenn
endvorstartliegt. - Schneidet alle Bruchteile ab. Beispiel:
timestamp_diff("2021-01-01 00:00:01", "2021-01-01 00:00:00", "minute")gibt0zurück.
Das Argument unit muss ein String und einer der folgenden Werte sein:
microsecondmillisecondsecondminutehourday
Beispiele:
end |
start |
unit |
timestamp_diff(end, start, unit) |
|---|---|---|---|
| 2026-07-04 00:01:00 UTC | 2026-07-04 00:00:00 UTC | „second“ | 60 l |
| 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
Syntax:
timestamp_extract(timestamp: TIMESTAMP | BSON_TIMESTAMP, part: STRING[, timezone: STRING]) -> INT64
Beschreibung:
Extrahiert einen bestimmten part (z.B. Jahr, Monat, Tag) aus timestamp.
Das Argument part muss ein String und einer der folgenden Werte sein:
microsecondmillisecondsecondminutehourdaydayofweek: Gibt einen Wert zwischen 1 (Sonntag) und 7 (Samstag) zurück.dayofyearweek: Gibt die Wochennummer des Jahres zurück, beginnend mit 1 für den ersten Sonntag des Jahres.week([weekday]): Gibt die Kalenderwoche des Jahres zurück, beginnend mit dem angegebenenweekday.monthquarteryearisoweek: Gibt die ISO 8601-Wochennummer zurück.isoyear: Gibt das Jahr mit ISO 8601-Wochennummerierung zurück.
Wenn das Argument timezone angegeben ist, basiert die Extraktion auf dem Kalender der angegebenen Zeitzone. Bei der Extraktion wird die Sommerzeit berücksichtigt.
Wenn timezone nicht angegeben ist, basiert die Extraktion auf UTC.
Das Argument timezone sollte eine Stringdarstellung einer Zeitzone aus der Zeitzonendatenbank sein, z. B. America/New_York. Sie können auch einen benutzerdefinierten zeitlichen Versatz verwenden, indem Sie einen Versatz von GMT angeben.
Beispiele:
timestamp |
part |
timezone |
timestamp_extract(timestamp, part, timezone) |
|---|---|---|---|
| 2025-02-20 10:20:30 UTC | "year" | Nicht bereitgestellt | 2025 |
| 2025-02-20 10:20:30 UTC | "day" | Nicht bereitgestellt | 20 |
| 2025-12-31 23:59:59 UTC | "year" | "Asia/Tokyo" | 2026 |
Typfunktionen
| Name | Beschreibung |
TYPE
|
Gibt den Typ des Werts als STRING zurück.
|
IS_TYPE
|
Gibt true zurück, wenn der Wert mit dem angegebenen Typ übereinstimmt.
|
TYP
Syntax:
type(input: ANY) -> STRING
Beschreibung:
Gibt eine Stringdarstellung des Typs input zurück.
Wenn ein fehlender Wert angegeben wird, wird NULL zurückgegeben.
Beispiele:
input |
type(input) |
|---|---|
| NULL | "null" |
| wahr | "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" |
object_id "a7f2c9d18b3e4509f67c12d8" |
"object_id" |
1.2e9m |
"decimal128" |
regex "/pattern/i" |
"regex" |
bson_timestamp(1732754912, 500) |
"bson_timestamp" |
| ABSENT | NULL |
Kundenbeispiele
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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(notEqual(field("title"), "1984").as("not1984")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.NotEqual(firestore.FieldOf("title"), "1984").As("not1984"), )). Execute(ctx)
IS_TYPE
Syntax:
is_type(input: ANY, type: STRING) -> BOOLEAN
Beschreibung:
Gibt true zurück, wenn input mit dem angegebenen type übereinstimmt, andernfalls false.
Wenn ein fehlender input angegeben wird, wird NULL zurückgegeben.
Unterstützte type-Strings:
"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"
Beispiele:
input |
type |
is_type(input, type) |
|---|---|---|
| NULL | "null" | wahr |
| wahr | "boolean" | wahr |
| 3.14 | "float64" | wahr |
| "foo" | "string" | wahr |
| b"foo" | "string" | falsch |
| [1, 2] | "array" | wahr |
| {"a": 1} | "map" | wahr |
vector([1.0, 2.0]) |
"vector" | wahr |
| ABSENT | "string" | NULL |
| "bar" | "other" | FEHLER |
Vektorfunktionen
| Name | Beschreibung |
COSINE_DISTANCE
|
Gibt die Kosinus-Distanz zwischen zwei Vektoren zurück |
DOT_PRODUCT
|
Gibt das Skalarprodukt zweier Vektoren zurück |
EUCLIDEAN_DISTANCE
|
Gibt den euklidischen Abstand zwischen zwei Vektoren zurück |
MANHATTAN_DISTANCE
|
Gibt die Manhattan-Distanz zwischen zwei Vektoren zurück |
VECTOR_LENGTH
|
Gibt die Anzahl der Elemente in einem Vektor zurück |
COSINE_DISTANCE
Syntax:
cosine_distance(x: VECTOR, y: VECTOR) -> FLOAT64
Beschreibung:
Gibt den Kosinusabstand zwischen x und y zurück.
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() )
Java
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();
Go
sampleVector := []float64{0.0, 1.0, 2.0, 3.0, 4.0, 5.0} snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.CosineDistance(firestore.FieldOf("embedding"), sampleVector).As("cosineDistance"), )). Execute(ctx)
DOT_PRODUCT
Syntax:
dot_product(x: VECTOR, y: VECTOR) -> FLOAT64
Beschreibung:
Gibt das Skalarprodukt von x und y zurück.
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() )
Java
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();
Go
sampleVector := []float64{0.0, 1.0, 2.0, 3.0, 4.0, 5.0} snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.DotProduct(firestore.FieldOf("embedding"), sampleVector).As("dotProduct"), )). Execute(ctx)
EUCLIDEAN_DISTANCE
Syntax:
euclidean_distance(x: VECTOR, y: VECTOR) -> FLOAT64
Beschreibung:
Berechnet den euklidischen Abstand zwischen x und 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() )
Java
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();
Go
sampleVector := []float64{0.0, 1.0, 2.0, 3.0, 4.0, 5.0} snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.EuclideanDistance(firestore.FieldOf("embedding"), sampleVector).As("euclideanDistance"), )). Execute(ctx)
MANHATTAN_DISTANCE
Syntax:
manhattan_distance(x: VECTOR, y: VECTOR) -> FLOAT64
Beschreibung:
Berechnet die Manhattan-Distanz zwischen x und y.
VECTOR_LENGTH
Syntax:
vector_length(vector: VECTOR) -> INT64
Beschreibung:
Gibt die Anzahl der Elemente in einem VECTOR zurück.
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() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(vectorLength(field("embedding")).as("vectorLength")) .execute() .get();
Go
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.VectorLength(firestore.FieldOf("embedding")).As("vectorLength"), )). Execute(ctx)