Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions firebase-firestore/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
[#7893](https://github.com/firebase/firebase-android-sdk/pull/7893)
- [feature] Added support for `rand` and `trunc` Pipeline expressions.
[#7886](https://github.com/firebase/firebase-android-sdk/pull/7886)
- [feature] Added support for `ltrim`, `rtrim`, `stringIndexOf`, `stringRepeat`, `stringReplaceOne`, and `stringReplaceAll` Pipeline expressions.
[#7978](https://github.com/firebase/firebase-android-sdk/pull/7978)

# 26.1.2

Expand Down
70 changes: 70 additions & 0 deletions firebase-firestore/api.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion firebase-firestore/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version=26.1.3
version=26.2.0
latestReleasedVersion=26.1.2
Original file line number Diff line number Diff line change
Expand Up @@ -1478,6 +1478,203 @@ public void testTrimWithCharacters() {
"The Hitchhiker's Guide to the Galaxy"));
}

@Test
public void testLTrim() {
assumeFalse("Not implemented.", isRunningAgainstEmulator());

Task<Pipeline.Snapshot> execute =
firestore
.pipeline()
.collection(randomCol)
.limit(1)
.replaceWith(
map(
ImmutableMap.of(
"strWhitespace", " trimMe ", "strChars", "xxxtrimMe", "chars", "x")))
.select(
Expression.ltrim(constant(" trimMe ")).alias("staticLtrimExpr"),
Expression.ltrim("strWhitespace").alias("staticLtrimStr"),
field("strWhitespace").ltrim().alias("instLtrim"),
Expression.ltrimValue(constant("xxxtrimMe"), "x").alias("staticLtrimValueExprPrim"),
Expression.ltrimValue(constant("xxxtrimMe"), constant("x"))
.alias("staticLtrimValueExprExpr"),
Expression.ltrimValue("strChars", "x").alias("staticLtrimValueStrPrim"),
Expression.ltrimValue("strChars", field("chars")).alias("staticLtrimValueStrExpr"),
field("strChars").ltrimValue("x").alias("instLtrimValuePrim"),
field("strChars").ltrimValue(field("chars")).alias("instLtrimValueExpr"))
.execute();

Map<String, Object> result = waitFor(execute).getResults().get(0).getData();
assertThat(result.get("staticLtrimExpr")).isEqualTo("trimMe ");
assertThat(result.get("staticLtrimStr")).isEqualTo("trimMe ");
assertThat(result.get("instLtrim")).isEqualTo("trimMe ");

assertThat(result.get("staticLtrimValueExprPrim")).isEqualTo("trimMe");
assertThat(result.get("staticLtrimValueExprExpr")).isEqualTo("trimMe");
assertThat(result.get("staticLtrimValueStrPrim")).isEqualTo("trimMe");
assertThat(result.get("staticLtrimValueStrExpr")).isEqualTo("trimMe");
assertThat(result.get("instLtrimValuePrim")).isEqualTo("trimMe");
assertThat(result.get("instLtrimValueExpr")).isEqualTo("trimMe");
}

@Test
public void testRTrim() {
assumeFalse("Not implemented.", isRunningAgainstEmulator());

Task<Pipeline.Snapshot> execute =
firestore
.pipeline()
.collection(randomCol)
.limit(1)
.replaceWith(
map(
ImmutableMap.of(
"strWhitespace", " trimMe ", "strChars", "trimMexxx", "chars", "x")))
.select(
Expression.rtrim(constant(" trimMe ")).alias("staticRtrimExpr"),
Expression.rtrim("strWhitespace").alias("staticRtrimStr"),
field("strWhitespace").rtrim().alias("instRtrim"),
Expression.rtrimValue(constant("trimMexxx"), "x").alias("staticRtrimValueExprPrim"),
Expression.rtrimValue(constant("trimMexxx"), constant("x"))
.alias("staticRtrimValueExprExpr"),
Expression.rtrimValue("strChars", "x").alias("staticRtrimValueStrPrim"),
Expression.rtrimValue("strChars", field("chars")).alias("staticRtrimValueStrExpr"),
field("strChars").rtrimValue("x").alias("instRtrimValuePrim"),
field("strChars").rtrimValue(field("chars")).alias("instRtrimValueExpr"))
.execute();

Map<String, Object> result = waitFor(execute).getResults().get(0).getData();
assertThat(result.get("staticRtrimExpr")).isEqualTo(" trimMe");
assertThat(result.get("staticRtrimStr")).isEqualTo(" trimMe");
assertThat(result.get("instRtrim")).isEqualTo(" trimMe");

assertThat(result.get("staticRtrimValueExprPrim")).isEqualTo("trimMe");
assertThat(result.get("staticRtrimValueExprExpr")).isEqualTo("trimMe");
assertThat(result.get("staticRtrimValueStrPrim")).isEqualTo("trimMe");
assertThat(result.get("staticRtrimValueStrExpr")).isEqualTo("trimMe");
assertThat(result.get("instRtrimValuePrim")).isEqualTo("trimMe");
assertThat(result.get("instRtrimValueExpr")).isEqualTo("trimMe");
}

@Test
public void testStringRepeat() {
assumeFalse("Not implemented.", isRunningAgainstEmulator());

Task<Pipeline.Snapshot> execute =
firestore
.pipeline()
.collection(randomCol)
.limit(1)
.replaceWith(map(ImmutableMap.of("str", "ha", "count", 3)))
.select(
Expression.stringRepeat(constant("ha"), 3).alias("staticExprPrim"),
Expression.stringRepeat(constant("ha"), constant(3)).alias("staticExprExpr"),
Expression.stringRepeat("str", 3).alias("staticStrPrim"),
Expression.stringRepeat("str", field("count")).alias("staticStrExpr"),
field("str").stringRepeat(3).alias("instPrim"),
field("str").stringRepeat(field("count")).alias("instExpr"))
.execute();

Map<String, Object> result = waitFor(execute).getResults().get(0).getData();
assertThat(result.get("staticExprPrim")).isEqualTo("hahaha");
assertThat(result.get("staticExprExpr")).isEqualTo("hahaha");
assertThat(result.get("staticStrPrim")).isEqualTo("hahaha");
assertThat(result.get("staticStrExpr")).isEqualTo("hahaha");
assertThat(result.get("instPrim")).isEqualTo("hahaha");
assertThat(result.get("instExpr")).isEqualTo("hahaha");
}

@Test
public void testStringReplaceAll() {
assumeFalse("Not implemented.", isRunningAgainstEmulator());

Task<Pipeline.Snapshot> execute =
firestore
.pipeline()
.collection(randomCol)
.limit(1)
.replaceWith(map(ImmutableMap.of("str", "hello world", "old", "o", "new", "a")))
.select(
Expression.stringReplaceAll(constant("hello world"), "o", "a")
.alias("staticExprPrim"),
Expression.stringReplaceAll(constant("hello world"), constant("o"), constant("a"))
.alias("staticExprExpr"),
Expression.stringReplaceAll("str", "o", "a").alias("staticStrPrim"),
Expression.stringReplaceAll("str", field("old"), field("new"))
.alias("staticStrExpr"),
field("str").stringReplaceAll("o", "a").alias("instPrim"),
field("str").stringReplaceAll(field("old"), field("new")).alias("instExpr"))
.execute();

Map<String, Object> result = waitFor(execute).getResults().get(0).getData();
assertThat(result.get("staticExprPrim")).isEqualTo("hella warld");
assertThat(result.get("staticExprExpr")).isEqualTo("hella warld");
assertThat(result.get("staticStrPrim")).isEqualTo("hella warld");
assertThat(result.get("staticStrExpr")).isEqualTo("hella warld");
assertThat(result.get("instPrim")).isEqualTo("hella warld");
assertThat(result.get("instExpr")).isEqualTo("hella warld");
}

@Test
public void testStringReplaceOne() {
assumeFalse("Not implemented.", isRunningAgainstEmulator());

Task<Pipeline.Snapshot> execute =
firestore
.pipeline()
.collection(randomCol)
.limit(1)
.replaceWith(map(ImmutableMap.of("str", "hello world", "old", "o", "new", "a")))
.select(
Expression.stringReplaceOne(constant("hello world"), "o", "a")
.alias("staticExprPrim"),
Expression.stringReplaceOne(constant("hello world"), constant("o"), constant("a"))
.alias("staticExprExpr"),
Expression.stringReplaceOne("str", "o", "a").alias("staticStrPrim"),
Expression.stringReplaceOne("str", field("old"), field("new"))
.alias("staticStrExpr"),
field("str").stringReplaceOne("o", "a").alias("instPrim"),
field("str").stringReplaceOne(field("old"), field("new")).alias("instExpr"))
.execute();

Map<String, Object> result = waitFor(execute).getResults().get(0).getData();
assertThat(result.get("staticExprPrim")).isEqualTo("hella world");
assertThat(result.get("staticExprExpr")).isEqualTo("hella world");
assertThat(result.get("staticStrPrim")).isEqualTo("hella world");
assertThat(result.get("staticStrExpr")).isEqualTo("hella world");
assertThat(result.get("instPrim")).isEqualTo("hella world");
assertThat(result.get("instExpr")).isEqualTo("hella world");
}

@Test
public void testStringIndexOf() {
assumeFalse("Not implemented.", isRunningAgainstEmulator());

Task<Pipeline.Snapshot> execute =
firestore
.pipeline()
.collection(randomCol)
.limit(1)
.replaceWith(map(ImmutableMap.of("str", "hello world", "sub", "world")))
.select(
Expression.stringIndexOf(constant("hello world"), "world").alias("staticExprPrim"),
Expression.stringIndexOf(constant("hello world"), constant("world"))
.alias("staticExprExpr"),
Expression.stringIndexOf("str", "world").alias("staticStrPrim"),
Expression.stringIndexOf("str", field("sub")).alias("staticStrExpr"),
field("str").stringIndexOf("world").alias("instPrim"),
field("str").stringIndexOf(field("sub")).alias("instExpr"))
.execute();

Map<String, Object> result = waitFor(execute).getResults().get(0).getData();
assertThat(result.get("staticExprPrim")).isEqualTo(6L);
assertThat(result.get("staticExprExpr")).isEqualTo(6L);
assertThat(result.get("staticStrPrim")).isEqualTo(6L);
assertThat(result.get("staticStrExpr")).isEqualTo(6L);
assertThat(result.get("instPrim")).isEqualTo(6L);
assertThat(result.get("instExpr")).isEqualTo(6L);
}

@Test
public void testLike() {
assumeFalse("Regexes are not supported against the emulator.", isRunningAgainstEmulator());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ internal object FunctionRegistry {
"is_not_nan" to evaluateIsNotNaN,
"is_null" to evaluateIsNull,
"is_not_null" to evaluateIsNotNull,
"replace_first" to evaluateReplaceFirst,
"replace_all" to evaluateReplaceAll,
"char_length" to evaluateCharLength,
"byte_length" to evaluateByteLength,
"like" to evaluateLike,
Expand Down Expand Up @@ -116,9 +114,13 @@ internal object FunctionRegistry {
"cosine_distance" to notImplemented,
"dot_product" to notImplemented,
"timestamp_trunc" to notImplemented,
"split" to evaluateSplit,
"substring" to evaluateSubstring,
"ltrim" to evaluateLTrim,
"rtrim" to evaluateRTrim
"substring" to notImplemented,
"string_repeat" to notImplemented,
"string_replace_all" to notImplemented,
"string_replace_one" to notImplemented,
"string_index_of" to notImplemented,
"ltrim" to notImplemented,
"rtrim" to notImplemented,
"split" to notImplemented,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,6 @@ internal val evaluateTrim = unaryFunction { value: Value ->
}
}

internal val evaluateLTrim = notImplemented // TODO: Does not exist in expressions.kt yet.

internal val evaluateRTrim = notImplemented // TODO: Does not exist in expressions.kt yet.

internal val evaluateReplaceAll = notImplemented // TODO: Does not exist in backend yet.

internal val evaluateReplaceFirst = notImplemented // TODO: Does not exist in backend yet.

internal val evaluateRegexContains =
binaryFunctionConstructorType(
ValueTypeCase.STRING_VALUE,
Expand Down
Loading
Loading