diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expression.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expression.java index 363046c39..6297e14e5 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expression.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expression.java @@ -1692,6 +1692,352 @@ public static Expression trimValue(String fieldName, Expression characters) { return trimValue(field(fieldName), characters); } + /** + * Creates an expression that removes whitespace from the beginning of a string or blob. + * + * @param value The expression representing the string or blob to trim. + * @return A new {@link Expression} representing the trimmed string or blob. + */ + @BetaApi + public static Expression ltrim(Expression value) { + return new FunctionExpression("ltrim", ImmutableList.of(value)); + } + + /** + * Creates an expression that removes whitespace from the beginning of a string or blob. + * + * @param fieldName The name of the field containing the string or blob to trim. + * @return A new {@link Expression} representing the trimmed string. + */ + @BetaApi + public static Expression ltrim(String fieldName) { + return ltrim(field(fieldName)); + } + + /** + * Creates an expression that removes specified characters from the beginning of a string or blob. + * + * @param value The expression representing the string or blob to trim. + * @param characters The characters to remove. + * @return A new {@link Expression} representing the trimmed string or blob. + */ + @BetaApi + public static Expression ltrimValue(Expression value, String characters) { + return new FunctionExpression("ltrim", ImmutableList.of(value, constant(characters))); + } + + /** + * Creates an expression that removes specified characters from the beginning of a string or blob. + * + * @param fieldName The name of the field containing the string or blob to trim. + * @param characters The characters to remove. + * @return A new {@link Expression} representing the trimmed string or blob. + */ + @BetaApi + public static Expression ltrimValue(String fieldName, String characters) { + return ltrimValue(field(fieldName), characters); + } + + /** + * Creates an expression that removes specified characters from the beginning of a string or blob. + * + * @param value The expression representing the string or blob to trim. + * @param characters The expression representing the characters to remove. + * @return A new {@link Expression} representing the trimmed string or blob. + */ + @BetaApi + public static Expression ltrimValue(Expression value, Expression characters) { + return new FunctionExpression("ltrim", ImmutableList.of(value, characters)); + } + + /** + * Creates an expression that removes specified characters from the beginning of a string or blob. + * + * @param fieldName The name of the field containing the string or blob to trim. + * @param characters The expression representing the characters to remove. + * @return A new {@link Expression} representing the trimmed string or blob. + */ + @BetaApi + public static Expression ltrimValue(String fieldName, Expression characters) { + return ltrimValue(field(fieldName), characters); + } + + /** + * Creates an expression that removes whitespace from the end of a string or byte array. + * + * @param value The expression representing the string or blob to trim. + * @return A new {@link Expression} representing the trimmed string or blob. + */ + @BetaApi + public static Expression rtrim(Expression value) { + return new FunctionExpression("rtrim", ImmutableList.of(value)); + } + + /** + * Creates an expression that removes trailing whitespace from a string or byte field. + * + * @param fieldName The name of the field containing the string to trim. + * @return A new {@link Expression} representing the trimmed string. + */ + @BetaApi + public static Expression rtrim(String fieldName) { + return rtrim(field(fieldName)); + } + + /** + * Creates an expression that removes specified characters from the end of a string or blob. + * + * @param value The expression representing the string or blob to trim. + * @param characters The characters to remove. + * @return A new {@link Expression} representing the trimmed string or blob. + */ + @BetaApi + public static Expression rtrimValue(Expression value, String characters) { + return new FunctionExpression("rtrim", ImmutableList.of(value, constant(characters))); + } + + /** + * Creates an expression that removes specified characters from the end of a string or blob. + * + * @param fieldName The name of the field containing the string or blob to trim. + * @param characters The characters to remove. + * @return A new {@link Expression} representing the trimmed string or blob. + */ + @BetaApi + public static Expression rtrimValue(String fieldName, String characters) { + return rtrimValue(field(fieldName), characters); + } + + /** + * Creates an expression that removes specified characters from the end of a string or blob. + * + * @param value The expression representing the string or blob to trim. + * @param characters The expression representing the characters to remove. + * @return A new {@link Expression} representing the trimmed string or blob. + */ + @BetaApi + public static Expression rtrimValue(Expression value, Expression characters) { + return new FunctionExpression("rtrim", ImmutableList.of(value, characters)); + } + + /** + * Creates an expression that removes specified characters from the end of a string or blob. + * + * @param fieldName The name of the field containing the string or blob to trim. + * @param characters The expression representing the characters to remove. + * @return A new {@link Expression} representing the trimmed string or blob. + */ + @BetaApi + public static Expression rtrimValue(String fieldName, Expression characters) { + return rtrimValue(field(fieldName), characters); + } + + /** + * Creates an expression that repeats a string or byte array a specified number of times. + * + * @param value The expression representing the string or byte array to repeat. + * @param repetitions The number of times to repeat the string or byte array. + * @return A new {@link Expression} representing the repeated string or byte array. + */ + @BetaApi + public static Expression stringRepeat(Expression value, Number repetitions) { + return new FunctionExpression("string_repeat", ImmutableList.of(value, constant(repetitions))); + } + + /** + * Creates an expression that repeats a string or byte array a specified number of times. + * + * @param fieldName The name of the field containing the string or byte array to repeat. + * @param repetitions The number of times to repeat the string or byte array. + * @return A new {@link Expression} representing the repeated string or byte array. + */ + @BetaApi + public static Expression stringRepeat(String fieldName, Number repetitions) { + return stringRepeat(field(fieldName), repetitions); + } + + /** + * Creates an expression that repeats a string or byte array a specified number of times. + * + * @param value The expression representing the string or byte array to repeat. + * @param repetitions The expression representing the number of times to repeat. + * @return A new {@link Expression} representing the repeated string or byte array. + */ + @BetaApi + public static Expression stringRepeat(Expression value, Expression repetitions) { + return new FunctionExpression("string_repeat", ImmutableList.of(value, repetitions)); + } + + /** + * Creates an expression that repeats a string or byte array a specified number of times. + * + * @param fieldName The name of the field containing the string or byte array to repeat. + * @param repetitions The expression representing the number of times to repeat. + * @return A new {@link Expression} representing the repeated string or byte array. + */ + @BetaApi + public static Expression stringRepeat(String fieldName, Expression repetitions) { + return stringRepeat(field(fieldName), repetitions); + } + + /** + * Creates an expression that replaces all occurrences of a substring or byte sequence. + * + * @param value The expression representing the input string or byte array. + * @param find The match pattern. + * @param replacement The replacement string/bytes. + * @return A new {@link Expression} representing the replaced value. + */ + @BetaApi + public static Expression stringReplaceAll(Expression value, String find, String replacement) { + return new FunctionExpression( + "string_replace_all", ImmutableList.of(value, constant(find), constant(replacement))); + } + + /** + * Creates an expression that replaces all occurrences of a substring or byte sequence. + * + * @param fieldName The name of the field containing the input string or byte array. + * @param find The match pattern. + * @param replacement The replacement string/bytes. + * @return A new {@link Expression} representing the replaced value. + */ + @BetaApi + public static Expression stringReplaceAll(String fieldName, String find, String replacement) { + return stringReplaceAll(field(fieldName), find, replacement); + } + + /** + * Creates an expression that replaces all occurrences of a substring or byte sequence. + * + * @param value The expression representing the input string or byte array. + * @param find The expression representing the match pattern. + * @param replacement The expression representing the replacement value. + * @return A new {@link Expression} representing the replaced value. + */ + @BetaApi + public static Expression stringReplaceAll( + Expression value, Expression find, Expression replacement) { + return new FunctionExpression("string_replace_all", ImmutableList.of(value, find, replacement)); + } + + /** + * Creates an expression that replaces all occurrences of a substring or byte sequence. + * + * @param fieldName The name of the field containing the input string or byte array. + * @param find The expression representing the match pattern. + * @param replacement The expression representing the replacement value. + * @return A new {@link Expression} representing the replaced value. + */ + @BetaApi + public static Expression stringReplaceAll( + String fieldName, Expression find, Expression replacement) { + return stringReplaceAll(field(fieldName), find, replacement); + } + + /** + * Creates an expression that replaces the first occurrence of a substring or byte sequence. + * + * @param value The expression representing the input string or byte array. + * @param find The match pattern. + * @param replacement The replacement string/bytes. + * @return A new {@link Expression} representing the replaced value. + */ + @BetaApi + public static Expression stringReplaceOne(Expression value, String find, String replacement) { + return new FunctionExpression( + "string_replace_one", ImmutableList.of(value, constant(find), constant(replacement))); + } + + /** + * Creates an expression that replaces the first occurrence of a substring or byte sequence. + * + * @param fieldName The name of the field containing the input string or byte array. + * @param find The match pattern. + * @param replacement The replacement string/bytes. + * @return A new {@link Expression} representing the replaced value. + */ + @BetaApi + public static Expression stringReplaceOne(String fieldName, String find, String replacement) { + return stringReplaceOne(field(fieldName), find, replacement); + } + + /** + * Creates an expression that replaces the first occurrence of a substring or byte sequence. + * + * @param value The expression representing the input string or byte array. + * @param find The expression representing the match pattern. + * @param replacement The expression representing the replacement value. + * @return A new {@link Expression} representing the replaced value. + */ + @BetaApi + public static Expression stringReplaceOne( + Expression value, Expression find, Expression replacement) { + return new FunctionExpression("string_replace_one", ImmutableList.of(value, find, replacement)); + } + + /** + * Creates an expression that replaces the first occurrence of a substring or byte sequence. + * + * @param fieldName The name of the field containing the input string or byte array. + * @param find The expression representing the match pattern. + * @param replacement The expression representing the replacement value. + * @return A new {@link Expression} representing the replaced value. + */ + @BetaApi + public static Expression stringReplaceOne( + String fieldName, Expression find, Expression replacement) { + return stringReplaceOne(field(fieldName), find, replacement); + } + + /** + * Creates an expression that returns the index of the first occurrence of a substring or bytes. + * + * @param value The expression representing the input string or byte array. + * @param search The search pattern. + * @return A new {@link Expression} representing the index. + */ + @BetaApi + public static Expression stringIndexOf(Expression value, String search) { + return new FunctionExpression("string_index_of", ImmutableList.of(value, constant(search))); + } + + /** + * Creates an expression that returns the index of the first occurrence of a substring or bytes. + * + * @param fieldName The name of the field containing the input string or byte array. + * @param search The search pattern. + * @return A new {@link Expression} representing the index. + */ + @BetaApi + public static Expression stringIndexOf(String fieldName, String search) { + return stringIndexOf(field(fieldName), search); + } + + /** + * Creates an expression that returns the index of the first occurrence of a substring or bytes. + * + * @param value The expression representing the input string or byte array. + * @param search The expression representing the search pattern. + * @return A new {@link Expression} representing the index. + */ + @BetaApi + public static Expression stringIndexOf(Expression value, Expression search) { + return new FunctionExpression("string_index_of", ImmutableList.of(value, search)); + } + + /** + * Creates an expression that returns the index of the first occurrence of a substring or bytes. + * + * @param fieldName The name of the field containing the input string or byte array. + * @param search The expression representing the search pattern. + * @return A new {@link Expression} representing the index. + */ + @BetaApi + public static Expression stringIndexOf(String fieldName, Expression search) { + return stringIndexOf(field(fieldName), search); + } + /** * Creates an expression that splits a string or blob by a delimiter. * @@ -4141,6 +4487,167 @@ public Expression trimValue(Expression characters) { return trimValue(this, characters); } + /** + * Creates an expression that removes whitespace from the beginning of this string or blob + * expression. + * + * @return A new {@link Expression} representing the trimmed string or blob. + */ + @BetaApi + public Expression ltrim() { + return ltrim(this); + } + + /** + * Creates an expression that removes the specified set of characters from the beginning of this + * string or blob expression. + * + * @param characters The characters to remove. + * @return A new {@link Expression} representing the trimmed string or blob. + */ + @BetaApi + public Expression ltrimValue(String characters) { + return ltrimValue(this, characters); + } + + /** + * Creates an expression that removes the specified characters or bytes from the beginning of this + * string or blob expression. + * + * @param characters The expression representing the characters or bytes to remove. + * @return A new {@link Expression} representing the trimmed string or blob. + */ + @BetaApi + public Expression ltrimValue(Expression characters) { + return ltrimValue(this, characters); + } + + /** + * Creates an expression that removes whitespace from the end of this string or blob expression. + * + * @return A new {@link Expression} representing the trimmed string or blob. + */ + @BetaApi + public Expression rtrim() { + return rtrim(this); + } + + /** + * Creates an expression that removes the specified set of characters from the end of this string + * or blob expression. + * + * @param characters The characters to remove. + * @return A new {@link Expression} representing the trimmed string or blob. + */ + @BetaApi + public Expression rtrimValue(String characters) { + return rtrimValue(this, characters); + } + + /** + * Creates an expression that removes the specified characters or bytes from the end of this + * string or blob expression. + * + * @param characters The expression representing the characters or bytes to remove. + * @return A new {@link Expression} representing the trimmed string or blob. + */ + @BetaApi + public Expression rtrimValue(Expression characters) { + return rtrimValue(this, characters); + } + + /** + * Creates an expression that repeats a string or byte array a specified number of times. + * + * @param repetitions The number of times to repeat the string or byte array. + * @return A new {@link Expression} representing the repeated string or byte array. + */ + @BetaApi + public Expression stringRepeat(Number repetitions) { + return stringRepeat(this, repetitions); + } + + /** + * Creates an expression that repeats a string or byte array a specified number of times. + * + * @param repetitions The expression representing the number of times to repeat. + * @return A new {@link Expression} representing the repeated string or byte array. + */ + @BetaApi + public Expression stringRepeat(Expression repetitions) { + return stringRepeat(this, repetitions); + } + + /** + * Creates an expression that replaces all occurrences of a substring or byte sequence. + * + * @param find The match pattern. + * @param replacement The replacement string/bytes. + * @return A new {@link Expression} representing the replaced value. + */ + @BetaApi + public Expression stringReplaceAll(String find, String replacement) { + return stringReplaceAll(this, find, replacement); + } + + /** + * Creates an expression that replaces all occurrences of a substring or byte sequence. + * + * @param find The expression representing the match pattern. + * @param replacement The expression representing the replacement value. + * @return A new {@link Expression} representing the replaced value. + */ + @BetaApi + public Expression stringReplaceAll(Expression find, Expression replacement) { + return stringReplaceAll(this, find, replacement); + } + + /** + * Creates an expression that replaces the first occurrence of a substring or byte sequence. + * + * @param find The match pattern. + * @param replacement The replacement string/bytes. + * @return A new {@link Expression} representing the replaced value. + */ + @BetaApi + public Expression stringReplaceOne(String find, String replacement) { + return stringReplaceOne(this, find, replacement); + } + + /** + * Creates an expression that replaces the first occurrence of a substring or byte sequence. + * + * @param find The expression representing the match pattern. + * @param replacement The expression representing the replacement value. + * @return A new {@link Expression} representing the replaced value. + */ + @BetaApi + public Expression stringReplaceOne(Expression find, Expression replacement) { + return stringReplaceOne(this, find, replacement); + } + + /** + * Creates an expression that returns the index of the first occurrence of a substring or bytes. + * + * @param search The search pattern. + * @return A new {@link Expression} representing the index. + */ + @BetaApi + public Expression stringIndexOf(String search) { + return stringIndexOf(this, search); + } + + /** + * Creates an expression that returns the index of the first occurrence of a substring or bytes. + * + * @param search The expression representing the search pattern. + * @return A new {@link Expression} representing the index. + */ + @BetaApi + public Expression stringIndexOf(Expression search) { + return stringIndexOf(this, search); + } + /** * Creates an expression that splits this string or blob expression by a delimiter. * diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java index 5f810332f..5de0a74c4 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java @@ -50,6 +50,7 @@ import static com.google.cloud.firestore.pipeline.expressions.Expression.log; import static com.google.cloud.firestore.pipeline.expressions.Expression.logicalMaximum; import static com.google.cloud.firestore.pipeline.expressions.Expression.logicalMinimum; +import static com.google.cloud.firestore.pipeline.expressions.Expression.ltrim; import static com.google.cloud.firestore.pipeline.expressions.Expression.mapMerge; import static com.google.cloud.firestore.pipeline.expressions.Expression.mapRemove; import static com.google.cloud.firestore.pipeline.expressions.Expression.notEqual; @@ -58,6 +59,7 @@ import static com.google.cloud.firestore.pipeline.expressions.Expression.pow; import static com.google.cloud.firestore.pipeline.expressions.Expression.regexMatch; import static com.google.cloud.firestore.pipeline.expressions.Expression.round; +import static com.google.cloud.firestore.pipeline.expressions.Expression.rtrim; import static com.google.cloud.firestore.pipeline.expressions.Expression.sqrt; import static com.google.cloud.firestore.pipeline.expressions.Expression.startsWith; import static com.google.cloud.firestore.pipeline.expressions.Expression.stringConcat; @@ -1008,6 +1010,184 @@ public void testTrimWithCharacters() throws Exception { "The Hitchhiker's Guide to the Galaxy"))); } + @Test + public void testLTrim() throws Exception { + List results = + firestore + .pipeline() + .createFrom(collection) + .where(equal("title", "The Hitchhiker's Guide to the Galaxy")) + .addFields(constant(" The Hitchhiker's Guide to the Galaxy ").as("spacedTitle")) + .addFields(constant("\"alice\"").as("userNameWithQuotes")) + .addFields( + constant(Blob.fromBytes(new byte[] {0x00, 0x01, 0x02, 0x00, 0x00})).as("bytes")) + .select( + ltrim("spacedTitle").as("ltrimmedTitle"), + field("userNameWithQuotes").ltrimValue("\"").as("userName"), + field("bytes").ltrimValue(constant(Blob.fromBytes(new byte[] {0x00}))).as("bytes")) + .limit(1) + .execute() + .get() + .getResults(); + + assertThat(data(results)) + .isEqualTo( + Lists.newArrayList( + map( + "ltrimmedTitle", "The Hitchhiker's Guide to the Galaxy ", + "userName", "alice\"", + "bytes", Blob.fromBytes(new byte[] {0x01, 0x02, 0x00, 0x00})))); + } + + @Test + public void testRTrim() throws Exception { + List results = + firestore + .pipeline() + .createFrom(collection) + .where(equal("title", "The Hitchhiker's Guide to the Galaxy")) + .addFields(constant(" The Hitchhiker's Guide to the Galaxy ").as("spacedTitle")) + .addFields(constant("\"alice\"").as("userNameWithQuotes")) + .addFields( + constant(Blob.fromBytes(new byte[] {0x00, 0x01, 0x02, 0x00, 0x00})).as("bytes")) + .select( + rtrim("spacedTitle").as("rtrimmedTitle"), + field("userNameWithQuotes").rtrimValue("\"").as("userName"), + field("bytes").rtrimValue(constant(Blob.fromBytes(new byte[] {0x00}))).as("bytes")) + .limit(1) + .execute() + .get() + .getResults(); + + assertThat(data(results)) + .isEqualTo( + Lists.newArrayList( + map( + "rtrimmedTitle", " The Hitchhiker's Guide to the Galaxy", + "userName", "\"alice", + "bytes", Blob.fromBytes(new byte[] {0x00, 0x01, 0x02})))); + } + + @Test + public void testStringRepeat() throws Exception { + List results = + firestore + .pipeline() + .createFrom(collection) + .where(equal("title", "The Hitchhiker's Guide to the Galaxy")) + .addFields(constant(Blob.fromBytes(new byte[] {0x01, 0x02, 0x03})).as("bytes")) + .select( + field("title").stringRepeat(2).as("repeatedTitle"), + Expression.stringRepeat(field("title"), 2).as("repeatedTitleStatic"), + field("bytes").stringRepeat(2).as("repeatedBytes")) + .limit(1) + .execute() + .get() + .getResults(); + + assertThat(data(results)) + .isEqualTo( + Lists.newArrayList( + map( + "repeatedTitle", + "The Hitchhiker's Guide to the GalaxyThe Hitchhiker's Guide to the Galaxy", + "repeatedTitleStatic", + "The Hitchhiker's Guide to the GalaxyThe Hitchhiker's Guide to the Galaxy", + "repeatedBytes", + Blob.fromBytes(new byte[] {0x01, 0x02, 0x03, 0x01, 0x02, 0x03})))); + } + + @Test + public void testStringReplaceAll() throws Exception { + List results = + firestore + .pipeline() + .createFrom(collection) + .where(equal("title", "The Hitchhiker's Guide to the Galaxy")) + .addFields(constant(Blob.fromBytes(new byte[] {0x01, 0x02, 0x02})).as("bytes")) + .select( + field("title").stringReplaceAll("e", "X").as("replacedAll"), + Expression.stringReplaceAll(field("title"), "e", "X").as("replacedAllStatic"), + field("bytes") + .stringReplaceAll( + constant(Blob.fromBytes(new byte[] {0x02})), + constant(Blob.fromBytes(new byte[] {0x03}))) + .as("replacedMultipleBytes")) + .limit(1) + .execute() + .get() + .getResults(); + + assertThat(data(results)) + .isEqualTo( + Lists.newArrayList( + map( + "replacedAll", + "ThX HitchhikXr's GuidX to thX Galaxy", + "replacedAllStatic", + "ThX HitchhikXr's GuidX to thX Galaxy", + "replacedMultipleBytes", + Blob.fromBytes(new byte[] {0x01, 0x03, 0x03})))); + } + + @Test + public void testStringReplaceOne() throws Exception { + List results = + firestore + .pipeline() + .createFrom(collection) + .where(equal("title", "The Hitchhiker's Guide to the Galaxy")) + .addFields(constant(Blob.fromBytes(new byte[] {0x01, 0x02, 0x02})).as("bytes")) + .select( + field("title").stringReplaceOne("e", "X").as("replacedOne"), + Expression.stringReplaceOne("title", "e", "X").as("replacedOneStatic"), + field("bytes") + .stringReplaceOne( + constant(Blob.fromBytes(new byte[] {0x02})), + constant(Blob.fromBytes(new byte[] {0x03}))) + .as("replacedOneByte")) + .limit(1) + .execute() + .get() + .getResults(); + + assertThat(data(results)) + .isEqualTo( + Lists.newArrayList( + map( + "replacedOne", + "ThX Hitchhiker's Guide to the Galaxy", + "replacedOneStatic", + "ThX Hitchhiker's Guide to the Galaxy", + "replacedOneByte", + Blob.fromBytes(new byte[] {0x01, 0x03, 0x02})))); + } + + @Test + public void testStringIndexOf() throws Exception { + List results = + firestore + .pipeline() + .createFrom(collection) + .where(equal("title", "The Hitchhiker's Guide to the Galaxy")) + .addFields(constant(Blob.fromBytes(new byte[] {0x01, 0x02, 0x03})).as("bytes")) + .select( + field("title").stringIndexOf("Guide").as("indexOfGuide"), + Expression.stringIndexOf(field("title"), "Guide").as("indexOfGuideStatic"), + field("bytes") + .stringIndexOf(constant(Blob.fromBytes(new byte[] {0x02}))) + .as("indexOfByte")) + .limit(1) + .execute() + .get() + .getResults(); + + assertThat(data(results)) + .isEqualTo( + Lists.newArrayList( + map("indexOfGuide", 17L, "indexOfGuideStatic", 17L, "indexOfByte", 1L))); + } + @Test public void testLike() throws Exception { assumeFalse( diff --git a/samples/preview-snippets/src/main/java/com/example/firestore/PipelineSnippets.java b/samples/preview-snippets/src/main/java/com/example/firestore/PipelineSnippets.java index cf6efe72d..328a65cfb 100644 --- a/samples/preview-snippets/src/main/java/com/example/firestore/PipelineSnippets.java +++ b/samples/preview-snippets/src/main/java/com/example/firestore/PipelineSnippets.java @@ -1392,6 +1392,84 @@ void strTrimFunction() throws ExecutionException, InterruptedException { System.out.println(result.getResults()); } + void strLTrimFunction() throws ExecutionException, InterruptedException { + // [START ltrim_function] + Pipeline.Snapshot result = + firestore + .pipeline() + .collection("books") + .select(ltrim(field("name")).as("ltrimmedName")) + .execute() + .get(); + // [END ltrim_function] + System.out.println(result.getResults()); + } + + void strRTrimFunction() throws ExecutionException, InterruptedException { + // [START rtrim_function] + Pipeline.Snapshot result = + firestore + .pipeline() + .collection("books") + .select(rtrim(field("name")).as("rtrimmedName")) + .execute() + .get(); + // [END rtrim_function] + System.out.println(result.getResults()); + } + + void strRepeatFunction() throws ExecutionException, InterruptedException { + // [START string_repeat_function] + Pipeline.Snapshot result = + firestore + .pipeline() + .collection("books") + .select(stringRepeat(field("title"), 2).as("repeatedTitle")) + .execute() + .get(); + // [END string_repeat_function] + System.out.println(result.getResults()); + } + + void strReplaceAllFunction() throws ExecutionException, InterruptedException { + // [START string_replace_all_function] + Pipeline.Snapshot result = + firestore + .pipeline() + .collection("books") + .select(stringReplaceAll(field("title"), "The", "A").as("replacedTitle")) + .execute() + .get(); + // [END string_replace_all_function] + System.out.println(result.getResults()); + } + + void strReplaceOneFunction() throws ExecutionException, InterruptedException { + // [START string_replace_one_function] + Pipeline.Snapshot result = + firestore + .pipeline() + .collection("books") + .select(stringReplaceOne(field("title"), "The", "A").as("replacedTitle")) + .execute() + .get(); + // [END string_replace_one_function] + System.out.println(result.getResults()); + } + + void strIndexOfFunction() throws ExecutionException, InterruptedException { + // [START string_index_of_function] + Pipeline.Snapshot result = + firestore + .pipeline() + .collection("books") + .select(stringIndexOf(field("title"), "The").as("indexOfThe")) + .execute() + .get(); + // [END string_index_of_function] + System.out.println(result.getResults()); + } + void unixMicrosToTimestampFunction() throws ExecutionException, InterruptedException { // [START unix_micros_timestamp] Pipeline.Snapshot result =