Stringfunktionen

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_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 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 eine bestimmte Anzahl von Malen.
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 überflüssige 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();

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
„hallo“ 5
„Welt“ 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();

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();

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();

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
„Datenspeicher“ „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();

REGEX_CONTAINS

Syntax:

regex_contains(value: STRING, pattern: STRING) -> BOOLEAN

Beschreibung:

Gibt TRUE zurück, wenn ein Teil von value mit pattern übereinstimmt. Wenn pattern kein gültiger regulärer Ausdruck ist, gibt diese Funktion einen error zurück.

Reguläre Ausdrücke folgen der Syntax der re2-Bibliothek.

Beispiele:

Wert Muster regex_contains(value, pattern)
„Firestore“ „Fire“ wahr
„Firestore“ „store$“ wahr
„Firestore“ „data“ 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();

REGEX_MATCH

Syntax:

regex_match(value: STRING, pattern: STRING) -> BOOLEAN

Beschreibung:

Gibt TRUE zurück, wenn value vollständig mit pattern übereinstimmt. Wenn pattern kein gültiger regulärer Ausdruck ist, gibt diese Funktion einen error zurück.

Reguläre Ausdrücke folgen der Syntax der re2-Bibliothek.

Beispiele:

Wert Muster regex_match(value, pattern)
„Firestore“ „F.*store“ wahr
„Firestore“ „Fire“ falsch
„Firestore“ "^F.*e$" wahr
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();

STRING_CONCAT

Syntax:

string_concat(values: STRING...) -> STRING

Beschreibung:

Verkettet zwei oder mehr STRING-Werte zu einem einzelnen 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();

STRING_CONTAINS

Syntax:

string_contains(value: STRING, substring: STRING) -> BOOLEAN

Beschreibung:

Prüft, ob value den Literalstring substring enthält.

Beispiele:

Wert Teilzeichenfolge 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();

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 -1 zurück, wenn search nicht gefunden wird.
  • Wenn value ein STRING-Wert ist, wird das Ergebnis in Unicode-Codepunkten gemessen. Wenn es sich um einen BYTES-Wert handelt, wird er in Byte gemessen.
  • Wenn search ein leerer STRING- oder BYTES-Wert ist, ist das Ergebnis 0.

Beispiele:

Wert search string_index_of(value, search)
„Hallo Welt“ „o“ 4
„Hallo Welt“ „l“ 2
„Hallo Welt“ "z" -1
„Banane“ "na" 2
"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 kein UTF-8-Kleinbuchstabe ist, 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();

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();

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 mit position (nullbasierter Index) und mit bis zu length Einträgen. Wenn kein length angegeben wird, wird der Teilstring von position bis zum Ende von input zurückgegeben.

  • Wenn input ein STRING-Wert ist, werden position und length in Unicode-Codepunkten gemessen. Wenn es sich um einen BYTES-Wert handelt, werden sie in Byte gemessen.

  • Wenn position größer als die Länge von input ist, wird ein leerer Teilstring zurückgegeben. Wenn position plus length größer als die Länge von input ist, wird der Teilstring bis zum Ende von input abgeschnitten.

  • Wenn position negativ ist, wird die Position vom Ende der Eingabe aus gezählt. Wenn der negative position größer als die Größe der Eingabe ist, wird die Position auf null gesetzt. length darf 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 wird:

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();

STRING_REVERSE

Syntax:

string_reverse[T <: STRING | BYTES](input: T) -> T

Beschreibung:

Gibt die bereitgestellte Eingabe in umgekehrter Reihenfolge zurück.

Zeichen werden durch Unicode-Codepunkte abgegrenzt, wenn die Eingabe ein STRING ist, und durch Byte, wenn die Eingabe ein BYTES-Wert ist.

Beispiele:

Eingabe string_reverse(input)
"abc" „cba“
„a🌹b“ „b🌹a“
„hallo“ „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();

STRING_REPEAT

Syntax:

string_repeat[T <: STRING | BYTES](input: T, repetitions: INT64) -> T

Beschreibung:

Gibt die input zurück, die repetitions-mal wiederholt wurde.

  • repetitions muss eine nicht negative Ganzzahl sein.
  • Wenn repetitions 0 ist, wird ein leerer Wert desselben Typs wie input zurü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 find leer 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 find leer 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 eine angegebene Gruppe von BYTES- oder CHARS-Zeichen vom Anfang und Ende der angegebenen input.

  • Wenn keine values_to_trim angegeben werden, 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 wird:

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();

LTRIM

Syntax:

ltrim[T <: STRING | BYTES](value: T, to_trim: T) -> T
ltrim[T <: STRING | BYTES](value: T) -> T

Beschreibung:

Entfernt eine angegebene Gruppe von BYTES oder CHARS vom Anfang des angegebenen value.

  • Wenn to_trim nicht angegeben ist, werden vorangestellte Leerzeichen entfernt.

Beispiele:

Wenn to_trim nicht angegeben ist:

Wert ltrim(value)
" foo " "foo "
"foo" "foo"

Wenn to_trim angegeben wird:

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 eine angegebene Gruppe von BYTES oder CHARS vom Ende des angegebenen value.

  • Wenn to_trim nicht angegeben ist, werden nachgestellte Leerzeichen entfernt.

Beispiele:

Wenn to_trim nicht angegeben ist:

Wert rtrim(value)
" foo " " foo"
"foo" "foo"

Wenn to_trim angegeben wird:

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.

  • Für STRING ist das Standardtrennzeichen das Komma (,). Das Trennzeichen wird als einzelner String behandelt.

  • Für BYTES müssen Sie ein Trennzeichen angeben.

  • Das Aufteilen mit einem leeren Trennzeichen generiert ein Array von Unicode-Codepunkten für STRING-Werte und ein Array von BYTES für BYTES-Werte.

  • Das Aufteilen eines leeren STRING gibt ein ARRAY aus einem einzelnen leeren STRING zurü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 wird:

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