Referência de funções de string
Funções de string
| Nome | Descrição |
BYTE_LENGTH
|
Retorna o número de BYTES em um valor STRING ou BYTES.
|
CHAR_LENGTH
|
Retorna o número de caracteres Unicode em um valor STRING.
|
STARTS_WITH
|
Retorna TRUE se um STRING começar com um prefixo especificado
|
ENDS_WITH
|
Retorna TRUE se um STRING terminar com um sufixo específico
|
LIKE
|
Retorna TRUE se um STRING corresponder a um padrão
|
REGEX_CONTAINS
|
Retorna TRUE se um valor for uma correspondência parcial ou completa de uma expressão regular
|
REGEX_FIND
|
Retorna a primeira substring que corresponde a uma expressão regular ou NULL se não houver correspondência.
|
REGEX_FIND_ALL
|
Retorna uma matriz de todas as substrings que correspondem a uma expressão regular ou uma matriz vazia se não houver correspondências. |
REGEX_MATCH
|
Retorna TRUE se alguma parte de um valor corresponder a uma expressão regular
|
STRING_CONCAT
|
Concatena vários STRING em um STRING
|
STRING_CONTAINS
|
Retorna TRUE se um valor contiver um STRING
|
STRING_INDEX_OF
|
Retorna o índice baseado em zero da primeira ocorrência de um valor STRING ou BYTES.
|
TO_UPPER
|
Converte um valor STRING ou BYTES em letras maiúsculas.
|
TO_LOWER
|
Converte um valor STRING ou BYTES em minúsculas.
|
SUBSTRING
|
Recebe uma substring de um valor STRING ou BYTES.
|
STRING_REVERSE
|
Inverte um valor STRING ou BYTES.
|
STRING_REPEAT
|
Repete um valor STRING ou BYTES um número especificado de vezes.
|
STRING_REPLACE_ALL
|
Substitui todas as ocorrências de um valor STRING ou BYTES.
|
STRING_REPLACE_ONE
|
Substitui a primeira ocorrência de um valor STRING ou BYTES.
|
TRIM
|
Corta caracteres à direita e à esquerda de um valor STRING ou BYTES.
|
LTRIM
|
Corta caracteres à esquerda de um valor STRING ou BYTES.
|
RTRIM
|
Corta caracteres à direita de um valor STRING ou BYTES.
|
SPLIT
|
Divide um valor STRING ou BYTES em uma matriz.
|
BYTE_LENGTH
Sintaxe:
byte_length[T <: STRING | BYTES](value: T) -> INT64
Descrição:
Retorna o número de BYTES em um valor STRING ou BYTES.
Exemplos:
| valor | 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
Android
val result = db.pipeline() .collection("books") .select( field("title").byteLength().alias("titleByteLength") ) .execute()
Java
Android
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
Sintaxe:
char_length(value: STRING) -> INT64
Descrição:
Retorna o número de pontos de código Unicode no valor STRING.
Exemplos:
| valor | 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
Android
val result = db.pipeline() .collection("books") .select( field("title").charLength().alias("titleCharLength") ) .execute()
Java
Android
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
Sintaxe:
starts_with(value: STRING, prefix: STRING) -> BOOLEAN
Descrição:
Retorna TRUE se value começar com prefix.
Exemplos:
| valor | prefixo | starts_with(value, prefix) |
|---|---|---|
| "abc" | "a" | verdadeiro |
| "abc" | "b" | falso |
| "abc" | "" | verdadeiro |
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
Android
val result = db.pipeline() .collection("books") .select( field("title").startsWith("The") .alias("needsSpecialAlphabeticalSort") ) .execute()
Java
Android
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
Sintaxe:
ends_with(value: STRING, postfix: STRING) -> BOOLEAN
Descrição:
Retorna TRUE se value terminar com postfix.
Exemplos:
| valor | postfix | ends_with(value, postfix) |
|---|---|---|
| "abc" | "c" | verdadeiro |
| "abc" | "b" | falso |
| "abc" | "" | verdadeiro |
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
Android
val result = db.pipeline() .collection("inventory/devices/laptops") .select( field("name").endsWith("16 inch") .alias("16InLaptops") ) .execute()
Java
Android
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
Sintaxe:
like(value: STRING, pattern: STRING) -> BOOLEAN
Descrição:
Retorna TRUE se value corresponder a pattern.
Exemplos:
| valor | padrão | like(value, pattern) |
|---|---|---|
| "Firestore" | "Fire%" | verdadeiro |
| "Firestore" | "%store" | verdadeiro |
| "Datastore" | "Data_tore" | verdadeiro |
| "100%" | "100\%" | verdadeiro |
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
Android
val result = db.pipeline() .collection("books") .select( field("genre").like("%Fiction") .alias("anyFiction") ) .execute()
Java
Android
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
Sintaxe:
regex_contains(value: STRING, regexp: STRING | REGEX) -> BOOLEAN
Descrição:
Retorna TRUE se alguma parte de value corresponder a regexp. Se regexp não for uma expressão regular válida, essa função vai retornar um error.
O argumento regexp também pode ser um valor REGEX criado usando
regex("pattern", "options"). Esse formato permite fornecer opções de expressão regular
com o padrão. Veja a seguir as opções aceitas:
i: correspondência que não diferencia maiúsculas de minúsculas.m: modo de várias linhas (^e$correspondem ao início ou ao fim das linhas).s: modo Dotall (.corresponde a novas linhas).
Se regexp for um STRING, nenhuma opção será aplicada além daquelas incorporadas ao
próprio padrão (por exemplo, (?i)).
As expressões regulares seguem a sintaxe da biblioteca re2.
Exemplos:
| valor | regexp | regex_contains(value, regexp) |
|---|---|---|
| "Firestore" | "Fire" | verdadeiro |
| "Firestore" | "store$" | verdadeiro |
| "Firestore" | "data" | falso |
| "Firestore" | regex("fire", "i") |
verdadeiro |
| "Firestore" | regex("FIRE", "") |
falso |
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
Android
val result = db.pipeline() .collection("documents") .select( field("title").regexContains("Firestore (Enterprise|Standard)") .alias("isFirestoreRelated") ) .execute()
Java
Android
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
Sintaxe:
regex_find(value: STRING, regexp: STRING | REGEX) -> STRING
Descrição:
Retorna a primeira substring em value que corresponde a regexp ou NULL se
não houver correspondência. Se regexp não for uma expressão regular válida, essa função vai retornar um error.
O argumento regexp também pode ser um valor REGEX criado usando
regex("pattern", "options"). Esse formato permite fornecer opções de expressão regular
com o padrão. Veja a seguir as opções aceitas:
i: correspondência que não diferencia maiúsculas de minúsculas.m: modo de várias linhas (^e$correspondem ao início ou ao fim das linhas).s: modo Dotall (.corresponde a novas linhas).
Se regexp for um STRING, nenhuma opção será aplicada além daquelas incorporadas ao
próprio padrão (por exemplo, (?i)).
As expressões regulares seguem a sintaxe da biblioteca re2.
Exemplos:
| valor | 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
Sintaxe:
regex_find_all(value: STRING, regexp: STRING | REGEX) -> ARRAY<STRING>
Descrição:
Retorna uma matriz de todas as substrings em value que correspondem a regexp ou uma matriz vazia se não houver correspondências. Se regexp não for uma expressão regular válida,
essa função vai retornar um error.
O argumento regexp também pode ser um valor REGEX criado usando
regex("pattern", "options"). Esse formato permite fornecer opções de expressão regular
com o padrão. Veja a seguir as opções aceitas:
i: correspondência que não diferencia maiúsculas de minúsculas.m: modo de várias linhas (^e$correspondem ao início ou ao fim das linhas).s: modo Dotall (.corresponde a novas linhas).
Se regexp for um STRING, nenhuma opção será aplicada além daquelas incorporadas ao
próprio padrão (por exemplo, (?i)).
As expressões regulares seguem a sintaxe da biblioteca re2.
Exemplos:
| valor | regexp | regex_find_all(value, regexp) |
|---|---|---|
| "one two three two" | "one" | ["one"] |
| "one TWO three Two" | regex("two", "i") |
["TWO", "Two"] |
| "one two three two" | regex("TWO", "") |
[] |
REGEX_MATCH
Sintaxe:
regex_match(value: STRING, regexp: STRING | REGEX) -> BOOLEAN
Descrição:
Retorna TRUE se value corresponder totalmente a regexp. Se regexp não for uma expressão regular válida, essa função vai retornar um error.
O argumento regexp também pode ser um valor REGEX criado usando
regex("pattern", "options"). Esse formato permite fornecer opções de expressão regular
com o padrão. Veja a seguir as opções aceitas:
i: correspondência que não diferencia maiúsculas de minúsculas.m: modo de várias linhas (^e$correspondem ao início ou ao fim das linhas).s: modo Dotall (.corresponde a novas linhas).
Se regexp for um STRING, nenhuma opção será aplicada além daquelas incorporadas ao
próprio padrão (por exemplo, (?i)).
As expressões regulares seguem a sintaxe da biblioteca re2.
Exemplos:
| valor | regexp | regex_match(value, regexp) |
|---|---|---|
| "Firestore" | "F.*store" | verdadeiro |
| "Firestore" | "Fire" | falso |
| "Firestore" | "^F.*e$" | verdadeiro |
| "FiReStOrE" | regex("firestore", "i") |
verdadeiro |
| "Firestore" | regex("firestore", "") |
falso |
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
Android
val result = db.pipeline() .collection("documents") .select( field("title").regexMatch("Firestore (Enterprise|Standard)") .alias("isFirestoreExactly") ) .execute()
Java
Android
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
Sintaxe:
string_concat(values: STRING...) -> STRING
Descrição:
Concatena dois ou mais valores STRING em um único resultado.
Exemplos:
| argumentos | string_concat(values...) |
|---|---|
() |
erro |
("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
Android
val result = db.pipeline() .collection("books") .select( field("title").concat(" by ", field("author")) .alias("fullyQualifiedTitle") ) .execute()
Java
Android
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
Sintaxe:
string_contains(value: STRING, substring: STRING) -> BOOLEAN
Descrição:
Verifica se value contém a string literal substring.
Exemplos:
| valor | substring | string_contains(value, substring) |
|---|---|---|
| "abc" | "b" | verdadeiro |
| "abc" | "d" | falso |
| "abc" | "" | verdadeiro |
| "a.c" | "." | verdadeiro |
| "☃☃☃" | "☃" | verdadeiro |
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
Android
val result = db.pipeline() .collection("articles") .select( field("body").stringContains("Firestore") .alias("isFirestoreRelated") ) .execute()
Java
Android
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
Sintaxe:
string_index_of[T <: STRING | BYTES](value: T, search: T) -> INT64
Descrição:
Retorna o índice baseado em zero da primeira ocorrência de search em value.
- Retorna
-1sesearchnão for encontrado. - Se
valuefor um valorSTRING, o resultado será medido em pontos de código Unicode. Se for um valorBYTES, ele será medido em bytes. - Se
searchfor um valorSTRINGouBYTESvazio, o resultado será0.
Exemplos:
| valor | 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
Sintaxe:
to_upper[T <: STRING | BYTES](value: T) -> T
Descrição:
Converte um valor STRING ou BYTES em letras maiúsculas.
Se um byte ou gráfico não corresponder a um caractere alfabético minúsculo UTF-8, ele será transmitido sem alterações.
Exemplos:
| valor | 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
Android
val result = db.pipeline() .collection("authors") .select( field("name").toUpper() .alias("uppercaseName") ) .execute()
Java
Android
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
Sintaxe:
to_lower[T <: STRING | BYTES](value: T) -> T
Descrição:
Converte um valor STRING ou BYTES em minúsculas.
Se um byte ou caractere não corresponder a um caractere alfabético maiúsculo UTF-8, ele será transmitido sem alterações.
Exemplos:
| valor | 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
Android
val result = db.pipeline() .collection("authors") .select( field("genre").toLower().equal("fantasy") .alias("isFantasy") ) .execute()
Java
Android
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
Sintaxe:
substring[T <: STRING | BYTES](input: T, position: INT64) -> T
substring[T <: STRING | BYTES](input: T, position: INT64, length: INT64) -> T
Descrição:
Retorna uma substring de input começando em position (índice baseado em zero) e incluindo até length entradas. Se nenhum length for fornecido, vai retornar a substring
de position até o final do input.
Se
inputfor um valorSTRING,positionelengthserão medidos em caracteres pontos de código Unicode. Se for um valorBYTES, eles serão medidos em bytes.Se
positionfor maior que o comprimento deinput, uma substring vazia será retornada. Sepositionmaislengthfor maior que o comprimento deinput, a substring será truncada até o final deinput.Se
positionfor negativo, a posição será extraída do final da entrada. Se opositionnegativo for maior que o tamanho da entrada, a posição será definida como zero.lengthnão pode ser negativo.
Exemplos:
Quando length não é fornecido:
| entrada | posição | substring(input, position) |
|---|---|---|
| "abc" | 0 | "abc" |
| "abc" | 1 | "bc" |
| "abc" | 3 | "" |
| "abc" | -1 | "c" |
| b"abc" | 1 | b"bc" |
Quando length é fornecido:
| entrada | posição | comprimento | 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
Android
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
Android
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
Sintaxe:
string_reverse[T <: STRING | BYTES](input: T) -> T
Descrição:
Retorna a entrada fornecida na ordem inversa.
Os caracteres são delimitados por pontos de código Unicode quando a entrada é um STRING e por bytes quando a entrada é um valor BYTES.
Exemplos:
| entrada | 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
Android
val result = db.pipeline() .collection("books") .select( field("name").reverse().alias("reversedName") ) .execute()
Java
Android
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
Sintaxe:
string_repeat[T <: STRING | BYTES](input: T, repetitions: INT64) -> T
Descrição:
Retorna a input repetida repetitions vezes.
repetitionsprecisa ser um número inteiro não negativo- Se
repetitionsfor0, vai retornar um valor vazio do mesmo tipo deinput. - Se o resultado exceder o tamanho máximo permitido (1 MB), um erro será retornado.
Exemplos:
| entrada | repetições | string_repeat(input, repetitions) |
|---|---|---|
| "foo" | 3 | "foofoofoo" |
| "foo" | 0 | "" |
| "a " | 3 | "a a a " |
| b"ab" | 2 | b"abab" |
| "é🦆" | 2 | "é🦆é🦆" |
STRING_REPLACE_ALL
Sintaxe:
string_replace_all[T <: STRING | BYTES](input: T, find: T, replacement: T) -> T
Descrição:
Substitui todas as ocorrências não sobrepostas de find em input por
replacement.
- As correspondências diferenciam maiúsculas de minúsculas.
- Se
findestiver vazio, nenhuma substituição será feita.
Exemplos:
| entrada | encontrar | substituição | 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
Sintaxe:
string_replace_one[T <: STRING | BYTES](input: T, find: T, replacement: T) -> T
Descrição:
Substitui as primeiras ocorrências de find em input com replacement.
- As correspondências diferenciam maiúsculas de minúsculas.
- Se
findestiver vazio, nenhuma substituição será feita.
Exemplos:
| entrada | encontrar | substituição | string_replace_one(input, find, replacement) |
|---|---|---|---|
| "foobarfoo" | "foo" | "baz" | "bazbarfoo" |
| "é" | "é" | "a" | "a" |
| b"foobar" | b"o" | b"z" | b"fzoobar" |
TRIM
Sintaxe:
trim[T <: STRING | BYTES](input: T, values_to_trim: T) -> T
trim[T <: STRING | BYTES](input: T) -> T
Descrição:
Remove um conjunto especificado de BYTES ou CHARS do início e do fim da input fornecida.
- Se nenhum
values_to_trimfor fornecido, os caracteres de espaço em branco serão removidos.
Exemplos:
Quando values_to_trim não é fornecido:
| entrada | 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" |
Quando values_to_trim é fornecido:
| entrada | values_to_trim | trim(input, values_to_trim) |
|---|---|---|
| "abcbfooaacb" | "abc" | "foo" |
| "abcdaabadbac" | "abc" | "daabad" |
| b"C1C2C3" | b"C1" | b"C2C3" |
| b"C1C2" | "foo" | erro |
| "foo" | b"C1" | erro |
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
Android
val result = db.pipeline() .collection("books") .select( field("name").trim().alias("whitespaceTrimmedName") ) .execute()
Java
Android
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
Sintaxe:
ltrim[T <: STRING | BYTES](value: T, to_trim: T) -> T
ltrim[T <: STRING | BYTES](value: T) -> T
Descrição:
Remove um conjunto especificado de BYTES ou CHARS do início da value fornecida.
- Se
to_trimnão for fornecido, os caracteres de espaço em branco iniciais serão removidos.
Exemplos:
Quando to_trim não é fornecido:
| valor | ltrim(value) |
|---|---|
| " foo " | "foo " |
| "foo" | "foo" |
Quando to_trim é fornecido:
| valor | to_trim | ltrim(value, to_trim) |
|---|---|---|
| "aaabc" | "a" | "bc" |
| "abacaba" | "ba" | "caba" |
| "é" | "é" | "" |
RTRIM
Sintaxe:
rtrim[T <: STRING | BYTES](value: T, to_trim: T) -> T
rtrim[T <: STRING | BYTES](value: T) -> T
Descrição:
Remove um conjunto especificado de BYTES ou CHARS do final da value fornecida.
- Se
to_trimnão for fornecido, os caracteres de espaço em branco finais serão removidos.
Exemplos:
Quando to_trim não é fornecido:
| valor | rtrim(value) |
|---|---|
| " foo " | " foo" |
| "foo" | "foo" |
Quando to_trim é fornecido:
| valor | to_trim | rtrim(value, to_trim) |
|---|---|---|
| "abccc" | "c" | "ab" |
| "abacaba" | "ba" | "abac" |
| "é" | "é" | "" |
SPLIT
Sintaxe:
split(input: STRING) -> ARRAY<STRING>
split[T <: STRING | BYTES](input: T, delimiter: T) -> ARRAY<T>
Descrição:
Divide um valor STRING ou BYTES usando um delimitador.
Para
STRING, o delimitador padrão é a vírgula,. O delimitador é tratado como uma única string.Para
BYTES, especifique um delimitador.A divisão em um delimitador vazio produz uma matriz de pontos de código Unicode para valores
STRINGe uma matriz deBYTESpara valoresBYTES.A divisão de uma
STRINGvazia retorna umaARRAYcom uma únicaSTRINGvazia.
Exemplos:
Quando delimiter não é fornecido:
| entrada | split(input) |
|---|---|
| "foo,bar,foo" | ["foo", "bar", "foo"] |
| "foo" | ["foo"] |
| ",foo," | ["", "foo", ""] |
| "" | [""] |
| b"C120C2C4" | erro |
Quando delimiter é fornecido:
| entrada | delimitador | 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" | erro |
A seguir
- Consulte a Visão geral das consultas de pipeline.