Funkcje ciągu znaków

Funkcje ciągów znaków

Nazwa Opis
BYTE_LENGTH Zwraca liczbę BYTES w wartości STRING lub BYTES.
CHAR_LENGTH Zwraca liczbę znaków Unicode w STRINGwartości.
STARTS_WITH Zwraca wartość TRUE, jeśli STRING zaczyna się od danego prefiksu.
ENDS_WITH Zwraca TRUE, jeśli STRING kończy się danym przyrostkiem.
LIKE Zwraca TRUE, jeśli STRING pasuje do wzorca
REGEX_CONTAINS Zwraca TRUE, jeśli wartość jest częściowo lub w pełni zgodna z wyrażeniem regularnym.
REGEX_MATCH Zwraca TRUE, jeśli jakakolwiek część wartości pasuje do wyrażenia regularnego.
STRING_CONCAT Łączy wiele STRING w STRING
STRING_CONTAINS Zwraca wartość TRUE, jeśli wartość zawiera znak STRING
STRING_INDEX_OF Zwraca indeks pierwszego wystąpienia wartości STRING lub BYTES (liczony od zera).
TO_UPPER Przekształca wartość STRING lub BYTES na wielkie litery.
TO_LOWER Konwertuje wartość STRING lub BYTES na małe litery.
SUBSTRING Pobiera podciąg wartości STRING lub BYTES.
STRING_REVERSE Odwraca wartość STRING lub BYTES.
STRING_REPEAT Powtarza wartość STRING lub BYTES określoną liczbę razy.
STRING_REPLACE_ALL Zastępuje wszystkie wystąpienia wartości STRING lub BYTES.
STRING_REPLACE_ONE Zastępuje pierwsze wystąpienie wartości STRING lub BYTES.
TRIM Usuwa znaki z początku i końca wartości STRING lub BYTES.
LTRIM Usuwa znaki z początku wartości STRING lub BYTES.
RTRIM Usuwa końcowe znaki z wartości STRING lub BYTES.
SPLIT Dzieli wartość STRING lub BYTES na tablicę.

BYTE_LENGTH

Składnia:

byte_length[T <: STRING | BYTES](value: T) -> INT64

Opis:

Zwraca liczbę znaków BYTES w wartości STRING lub BYTES.

Przykłady:

wartość 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

Składnia:

char_length(value: STRING) -> INT64

Opis:

Zwraca liczbę punktów kodowych Unicode w STRING.

Przykłady:

wartość char_length(value)
„abc” 3
„Witaj” 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();

STARTS_WITH

Składnia:

starts_with(value: STRING, prefix: STRING) -> BOOLEAN

Opis:

Zwraca wartość TRUE, jeśli value zaczyna się od prefix.

Przykłady:

wartość prefiks starts_with(value, prefix)
„abc” „a” prawda
„abc” „b” fałsz
„abc” "" prawda
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

Składnia:

ends_with(value: STRING, postfix: STRING) -> BOOLEAN

Opis:

Zwraca wartość TRUE, jeśli ciąg value kończy się ciągiem postfix.

Przykłady:

wartość przyrostek, ends_with(value, postfix)
„abc” „c” prawda
„abc” „b” fałsz
„abc” "" prawda
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();

PODOBA MI SIĘ

Składnia:

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

Opis:

Zwraca TRUE, jeśli value pasuje do pattern.

Przykłady:

wartość wzór like(value, pattern)
„Firestore” „Fire%” prawda
„Firestore” „%store” prawda
„Datastore” „Data_tore” prawda
„100%” „100%” prawda
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

Składnia:

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

Opis:

Zwraca wartość TRUE, jeśli część ciągu value pasuje do wzorca pattern. Jeśli pattern nie jest prawidłowym wyrażeniem regularnym, funkcja zwraca wartość error.

Wyrażenia regularne są zgodne ze składnią biblioteki re2.

Przykłady:

wartość wzór regex_contains(value, pattern)
„Firestore” „Ogień” prawda
„Firestore” „store$” prawda
„Firestore” „dane” fałsz
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

Składnia:

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

Opis:

Zwraca wartość TRUE, jeśli value w pełni pasuje do pattern. Jeśli pattern nie jest prawidłowym wyrażeniem regularnym, funkcja zwraca wartość error.

Wyrażenia regularne są zgodne ze składnią biblioteki re2.

Przykłady:

wartość wzór regex_match(value, pattern)
„Firestore” „F.*store” prawda
„Firestore” „Ogień” fałsz
„Firestore” "^F.*e$" prawda
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

Składnia:

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

Opis:

Łączy co najmniej 2 wartości STRING w jeden wynik.

Przykłady:

argumenty string_concat(values...)
() błąd
("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

Składnia:

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

Opis:

Sprawdza, czy argument value zawiera ciąg tekstowy substring.

Przykłady:

wartość podłańcuch string_contains(value, substring)
„abc” „b” prawda
„abc” „d” fałsz
„abc” "" prawda
„a.c” „.” prawda
„☃☃☃” „☃” prawda
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

Składnia:

string_index_of[T <: STRING | BYTES](value: T, search: T) -> INT64

Opis:

Zwraca indeks (liczony od zera) pierwszego wystąpienia znaku search w ciągu value.

  • Zwraca wartość -1, jeśli nie znaleziono wartości search.
  • Jeśli value jest wartością STRING, wynik jest mierzony w punktach kodowych Unicode. Jeśli jest to wartość BYTES, jest mierzona w bajtach.
  • Jeśli argument search jest pustą wartością STRING lub BYTES, wynikiem jest 0.

Przykłady:

wartość szukaj string_index_of(value, search)
„hello world” „o” 4
„hello world” „l” 2
„hello world” "z" -1
„banana” „na” 2
„abc” "" 0
b"abc" b"b" 1
"é" "é" 0
b"é" b"é" 0

TO_UPPER

Składnia:

to_upper[T <: STRING | BYTES](value: T) -> T

Opis:

Przekształca wartość STRING lub BYTES na wielkie litery.

Jeśli bajt lub znak nie odpowiada małej literze alfabetu UTF-8, jest przekazywany bez zmian.

Przykłady:

wartość 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

Składnia:

to_lower[T <: STRING | BYTES](value: T) -> T

Opis:

Konwertuje wartość STRING lub BYTES na małe litery.

Jeśli bajt lub znak nie odpowiada wielkiej literze alfabetu UTF-8, jest przekazywany bez zmian.

Przykłady:

wartość 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

Składnia:

substring[T <: STRING | BYTES](input: T, position: INT64) -> T
substring[T <: STRING | BYTES](input: T, position: INT64, length: INT64) -> T

Opis:

Zwraca podłańcuch ciągu input zaczynający się od pozycji position (indeks liczony od zera) i zawierający maksymalnie length elementów. Jeśli nie podano argumentu length, zwraca podciąg od position do końca argumentu input.

  • Jeśli input jest wartością STRING, positionlength są mierzone w punktach kodowych Unicode. Jeśli jest to wartość BYTES, jest mierzona w bajtach.

  • Jeśli argument position jest większy niż długość argumentu input, zwracany jest pusty podciąg. Jeśli position + length jest większe niż długość input, podciąg jest obcinany do końca input.

  • Jeśli position jest ujemne, pozycja jest pobierana od końca danych wejściowych. Jeśli ujemna wartość position jest większa niż rozmiar danych wejściowych, pozycja jest ustawiana na zero. Wartość parametru length musi być nieujemna.

Przykłady:

Gdy nie podano wartości length:

wprowadzanie danych position substring(input, position)
„abc” 0 „abc”
„abc” 1 „bc”
„abc” 3 ""
„abc” -1 „c”
b"abc" 1 b"bc"

Gdy podano wartość length:

wprowadzanie danych position długość 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

Składnia:

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

Opis:

Zwraca podane dane wejściowe w odwrotnej kolejności.

Znaki są rozdzielane przez punkty kodowe Unicode, gdy dane wejściowe są wartością STRING, a przez bajty, gdy dane wejściowe są wartością BYTES.

Przykłady:

wprowadzanie danych string_reverse(input)
„abc” „cba”
"a🌹b" „b🌹a”
„Witaj” „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

Składnia:

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

Opis:

Zwraca ciąg input powtórzony repetitions razy.

  • repetitions musi być nieujemną liczbą całkowitą.
  • Jeśli repetitions to 0, zwraca pustą wartość tego samego typu co input.
  • Jeśli wynik przekracza maksymalny dozwolony rozmiar (1 MB), zwracany jest błąd.

Przykłady:

wprowadzanie danych powtórzenia, string_repeat(input, repetitions)
„foo” 3 „foofoofoo”
„foo” 0 ""
"a " 3 "a a a "
b"ab" 2 b"abab"
„é🦆” 2 „é🦆é🦆”

STRING_REPLACE_ALL

Składnia:

string_replace_all[T <: STRING | BYTES](input: T, find: T, replacement: T) -> T

Opis:

Zamienia wszystkie niepokrywające się wystąpienia ciągu find w ciągu input na ciąg replacement.

  • W dopasowaniach jest rozróżniana wielkość liter.
  • Jeśli pole find jest puste, nie zostaną wprowadzone żadne zamiany.

Przykłady:

wprowadzanie danych znajdź wymiany 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

Składnia:

string_replace_one[T <: STRING | BYTES](input: T, find: T, replacement: T) -> T

Opis:

Zastępuje pierwsze wystąpienie ciągu find w ciągu input ciągiem replacement.

  • W dopasowaniach jest rozróżniana wielkość liter.
  • Jeśli pole find jest puste, nie zostaną wprowadzone żadne zamiany.

Przykłady:

wprowadzanie danych znajdź wymiany string_replace_one(input, find, replacement)
„foobarfoo” „foo” „baz” „bazbarfoo”
"é" "é" „a” „a”
b"foobar" b"o" b"z" b"fzoobar"

TRIM

Składnia:

trim[T <: STRING | BYTES](input: T, values_to_trim: T) -> T
trim[T <: STRING | BYTES](input: T) -> T

Opis:

Usuwa określony zestaw znaków BYTES lub CHARS z początku i końca podanego ciągu input.

  • Jeśli nie podano żadnych znaków values_to_trim, usuwa znaki odstępu.

Przykłady:

Gdy nie podano wartości values_to_trim:

wprowadzanie danych 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"

Gdy podano wartość values_to_trim:

wprowadzanie danych wartości_do_przycięcia trim(input, values_to_trim)
„abcbfooaacb” „abc” „foo”
„abcdaabadbac” „abc” "daabad"
b"C1C2C3" b"C1" b"C2C3"
b"C1C2" „foo” błąd
„foo” b"C1" błąd

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

Składnia:

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

Opis:

Usuwa określony zestaw znaków BYTES lub CHARS z początku podanego ciągu value.

  • Jeśli wartość to_trim nie zostanie podana, usuwa początkowe znaki odstępu.

Przykłady:

Gdy nie podano wartości to_trim:

wartość ltrim(value)
" foo " "foo "
„foo” „foo”

Gdy podano wartość to_trim:

wartość to_trim ltrim(value, to_trim)
„aaabc” „a” „bc”
„abacaba” „ba” „caba”
"é" "é" ""

RTRIM

Składnia:

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

Opis:

Usuwa określony zestaw znaków BYTES lub CHARS z końca podanego tekstu value.

  • Jeśli nie podasz wartości to_trim, zostaną usunięte znaki odstępu na końcu.

Przykłady:

Gdy nie podano wartości to_trim:

wartość rtrim(value)
" foo " " foo"
„foo” „foo”

Gdy podano wartość to_trim:

wartość to_trim rtrim(value, to_trim)
„abccc” „c” "ab"
„abacaba” „ba” „abac”
"é" "é" ""

SPLIT

Składnia:

split(input: STRING) -> ARRAY<STRING>
split[T <: STRING | BYTES](input: T, delimiter: T) -> ARRAY<T>

Opis:

Dzieli wartość STRING lub BYTES za pomocą separatora.

  • W przypadku typu STRING domyślnym separatorem jest przecinek ,. Separator jest traktowany jako pojedynczy ciąg znaków.

  • W przypadku BYTES musisz określić ogranicznik.

  • Podział za pomocą pustego separatora tworzy tablicę punktów kodowych Unicode dla wartości STRING i tablicę BYTES dla wartości BYTES.

  • Podział pustego STRING zwraca ARRAY z pojedynczym pustym STRING.

Przykłady:

Gdy nie podano wartości delimiter:

wprowadzanie danych split(input)
„foo,bar,foo” ["foo", "bar", "foo"]
„foo” ["foo"]
",foo," ["", "foo", ""]
"" [""]
b"C120C2C4" błąd

Gdy podano wartość delimiter:

wprowadzanie danych separator 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" błąd