Skip to content

Commit d6cd6d9

Browse files
committed
More expression work
1 parent 1ae8be7 commit d6cd6d9

File tree

2 files changed

+135
-54
lines changed

2 files changed

+135
-54
lines changed

firebase-firestore/src/androidTest/java/com/google/firebase/firestore/PipelineTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import static com.google.firebase.firestore.pipeline.Expr.euclideanDistance;
2626
import static com.google.firebase.firestore.pipeline.Expr.field;
2727
import static com.google.firebase.firestore.pipeline.Expr.gt;
28-
import static com.google.firebase.firestore.pipeline.Expr.logicalMax;
28+
import static com.google.firebase.firestore.pipeline.Expr.logicalMaximum;
2929
import static com.google.firebase.firestore.pipeline.Expr.lt;
3030
import static com.google.firebase.firestore.pipeline.Expr.lte;
3131
import static com.google.firebase.firestore.pipeline.Expr.mapGet;
@@ -724,8 +724,8 @@ public void testLogicalMax() {
724724
.collection(randomCol)
725725
.where(field("author").eq("Douglas Adams"))
726726
.select(
727-
field("rating").logicalMax(4.5).alias("max_rating"),
728-
logicalMax(field("published"), 1900).alias("max_published"))
727+
field("rating").logicalMaximum(4.5).alias("max_rating"),
728+
logicalMaximum(field("published"), 1900).alias("max_published"))
729729
.execute();
730730
assertThat(waitFor(execute).getResults())
731731
.comparingElementsUsing(DATA_CORRESPONDENCE)

firebase-firestore/src/main/java/com/google/firebase/firestore/pipeline/expressions.kt

Lines changed: 132 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -829,8 +829,7 @@ abstract class Expr internal constructor() {
829829
@JvmStatic fun isNan(fieldName: String): BooleanExpr = BooleanExpr("is_nan", fieldName)
830830

831831
/**
832-
* Creates an expression that checks if the results of [expr] is NOT 'NaN' (Not a
833-
* Number).
832+
* Creates an expression that checks if the results of [expr] is NOT 'NaN' (Not a Number).
834833
*
835834
* @param expr The expression to check.
836835
* @return A new [BooleanExpr] representing the isNotNan operation.
@@ -942,19 +941,48 @@ abstract class Expr internal constructor() {
942941
*/
943942
@JvmStatic fun byteLength(fieldName: String): Expr = FunctionExpr("byte_length", fieldName)
944943

945-
/** @return A new [Expr] representing the like operation. */
946-
@JvmStatic fun like(expr: Expr, pattern: Expr): BooleanExpr = BooleanExpr("like", expr, pattern)
944+
/**
945+
* Creates an expression that performs a case-sensitive wildcard string comparison.
946+
*
947+
* @param stringExpression The expression representing the string to perform the comparison on.
948+
* @param pattern The pattern to search for. You can use "%" as a wildcard character.
949+
* @return A new [BooleanExpr] representing the like operation.
950+
*/
951+
@JvmStatic
952+
fun like(stringExpression: Expr, pattern: Expr): BooleanExpr =
953+
BooleanExpr("like", stringExpression, pattern)
947954

948-
/** @return A new [Expr] representing the like operation. */
955+
/**
956+
* Creates an expression that performs a case-sensitive wildcard string comparison.
957+
*
958+
* @param stringExpression The expression representing the string to perform the comparison on.
959+
* @param pattern The pattern to search for. You can use "%" as a wildcard character.
960+
* @return A new [BooleanExpr] representing the like operation.
961+
*/
949962
@JvmStatic
950-
fun like(expr: Expr, pattern: String): BooleanExpr = BooleanExpr("like", expr, pattern)
963+
fun like(stringExpression: Expr, pattern: String): BooleanExpr =
964+
BooleanExpr("like", stringExpression, pattern)
951965

952-
/** @return A new [Expr] representing the like operation. */
966+
/**
967+
* Creates an expression that performs a case-sensitive wildcard string comparison against a
968+
* field.
969+
*
970+
* @param fieldName The name of the field containing the string.
971+
* @param pattern The pattern to search for. You can use "%" as a wildcard character.
972+
* @return A new [BooleanExpr] representing the like comparison.
973+
*/
953974
@JvmStatic
954975
fun like(fieldName: String, pattern: Expr): BooleanExpr =
955976
BooleanExpr("like", fieldName, pattern)
956977

957-
/** @return A new [Expr] representing the like operation. */
978+
/**
979+
* Creates an expression that performs a case-sensitive wildcard string comparison against a
980+
* field.
981+
*
982+
* @param fieldName The name of the field containing the string.
983+
* @param pattern The pattern to search for. You can use "%" as a wildcard character.
984+
* @return A new [BooleanExpr] representing the like comparison.
985+
*/
958986
@JvmStatic
959987
fun like(fieldName: String, pattern: String): BooleanExpr =
960988
BooleanExpr("like", fieldName, pattern)
@@ -999,41 +1027,53 @@ abstract class Expr internal constructor() {
9991027
fun regexMatch(fieldName: String, pattern: String) =
10001028
BooleanExpr("regex_match", fieldName, pattern)
10011029

1002-
/** @return A new [Expr] representing the logicalMax operation. */
1003-
@JvmStatic
1004-
fun logicalMax(left: Expr, right: Expr): Expr = FunctionExpr("logical_max", left, right)
1005-
1006-
/** @return A new [Expr] representing the logicalMax operation. */
1007-
@JvmStatic
1008-
fun logicalMax(left: Expr, right: Any): Expr = FunctionExpr("logical_max", left, right)
1009-
1010-
/** @return A new [Expr] representing the logicalMax operation. */
1011-
@JvmStatic
1012-
fun logicalMax(fieldName: String, other: Expr): Expr =
1013-
FunctionExpr("logical_max", fieldName, other)
1014-
1015-
/** @return A new [Expr] representing the logicalMax operation. */
1016-
@JvmStatic
1017-
fun logicalMax(fieldName: String, other: Any): Expr =
1018-
FunctionExpr("logical_max", fieldName, other)
1019-
1020-
/** @return A new [Expr] representing the logicalMin operation. */
1030+
/**
1031+
* Creates an expression that returns the largest value between multiple input expressions or
1032+
* literal values. Based on Firestore's value type ordering.
1033+
*
1034+
* @param expr The first operand expression.
1035+
* @param others Optional additional expressions or literals.
1036+
* @return A new [Expr] representing the logical maximum operation.
1037+
*/
10211038
@JvmStatic
1022-
fun logicalMin(left: Expr, right: Expr): Expr = FunctionExpr("logical_min", left, right)
1039+
fun logicalMaximum(expr: Expr, vararg others: Any): Expr =
1040+
FunctionExpr("logical_max", expr, *others)
10231041

1024-
/** @return A new [Expr] representing the logicalMin operation. */
1042+
/**
1043+
* Creates an expression that returns the largest value between multiple input expressions or
1044+
* literal values. Based on Firestore's value type ordering.
1045+
*
1046+
* @param fieldName The first operand field name.
1047+
* @param others Optional additional expressions or literals.
1048+
* @return A new [Expr] representing the logical maximum operation.
1049+
*/
10251050
@JvmStatic
1026-
fun logicalMin(left: Expr, right: Any): Expr = FunctionExpr("logical_min", left, right)
1051+
fun logicalMaximum(fieldName: String, vararg others: Any): Expr =
1052+
FunctionExpr("logical_max", fieldName, *others)
10271053

1028-
/** @return A new [Expr] representing the logicalMin operation. */
1054+
/**
1055+
* Creates an expression that returns the smallest value between multiple input expressions or
1056+
* literal values. Based on Firestore's value type ordering.
1057+
*
1058+
* @param expr The first operand expression.
1059+
* @param others Optional additional expressions or literals.
1060+
* @return A new [Expr] representing the logical minimum operation.
1061+
*/
10291062
@JvmStatic
1030-
fun logicalMin(fieldName: String, other: Expr): Expr =
1031-
FunctionExpr("logical_min", fieldName, other)
1063+
fun logicalMinimum(expr: Expr, vararg others: Any): Expr =
1064+
FunctionExpr("logical_min", expr, *others)
10321065

1033-
/** @return A new [Expr] representing the logicalMin operation. */
1066+
/**
1067+
* Creates an expression that returns the smallest value between multiple input expressions or
1068+
* literal values. Based on Firestore's value type ordering.
1069+
*
1070+
* @param fieldName The first operand field name.
1071+
* @param others Optional additional expressions or literals.
1072+
* @return A new [Expr] representing the logical minimum operation.
1073+
*/
10341074
@JvmStatic
1035-
fun logicalMin(fieldName: String, other: Any): Expr =
1036-
FunctionExpr("logical_min", fieldName, other)
1075+
fun logicalMinimum(fieldName: String, vararg others: Any): Expr =
1076+
FunctionExpr("logical_min", fieldName, *others)
10371077

10381078
/** @return A new [Expr] representing the reverse operation. */
10391079
@JvmStatic fun reverse(expr: Expr): Expr = FunctionExpr("reverse", expr)
@@ -1193,9 +1233,14 @@ abstract class Expr internal constructor() {
11931233

11941234
internal fun map(elements: Array<out Expr>): Expr = FunctionExpr("map", elements)
11951235

1196-
/** @return A new [Expr] representing the map operation. */
1236+
/**
1237+
* Creates an expression that creates a Firestore map value from an input object.
1238+
*
1239+
* @param elements The input map to evaluate in the expression.
1240+
* @return A new [Expr] representing the map function.
1241+
*/
11971242
@JvmStatic
1198-
fun map(elements: Map<String, Any>) =
1243+
fun map(elements: Map<String, Any>): Expr =
11991244
map(elements.flatMap { listOf(constant(it.key), toExprOrConstant(it.value)) }.toTypedArray())
12001245

12011246
/** @return A new [Expr] representing the mapGet operation. */
@@ -1215,12 +1260,12 @@ abstract class Expr internal constructor() {
12151260
/** @return A new [Expr] representing the mapMerge operation. */
12161261
@JvmStatic
12171262
fun mapMerge(firstMap: Expr, secondMap: Expr, vararg otherMaps: Expr): Expr =
1218-
FunctionExpr("map_merge", firstMap, secondMap, otherMaps)
1263+
FunctionExpr("map_merge", firstMap, secondMap, *otherMaps)
12191264

12201265
/** @return A new [Expr] representing the mapMerge operation. */
12211266
@JvmStatic
12221267
fun mapMerge(mapField: String, secondMap: Expr, vararg otherMaps: Expr): Expr =
1223-
FunctionExpr("map_merge", mapField, secondMap, otherMaps)
1268+
FunctionExpr("map_merge", mapField, secondMap, *otherMaps)
12241269

12251270
/** @return A new [Expr] representing the mapRemove operation. */
12261271
@JvmStatic
@@ -2341,6 +2386,14 @@ abstract class Expr internal constructor() {
23412386
*/
23422387
fun notEqAny(arrayExpression: Expr): BooleanExpr = Companion.notEqAny(this, arrayExpression)
23432388

2389+
/**
2390+
* Creates an expression that returns true if yhe result of this expression is absent. Otherwise,
2391+
* returns false even if the value is null.
2392+
*
2393+
* @return A new [BooleanExpr] representing the isAbsent operation.
2394+
*/
2395+
fun isAbsent(): BooleanExpr = Companion.isAbsent(this)
2396+
23442397
/**
23452398
* Creates an expression that checks if this expression evaluates to 'NaN' (Not a Number).
23462399
*
@@ -2402,48 +2455,76 @@ abstract class Expr internal constructor() {
24022455
fun byteLength(): Expr = Companion.byteLength(this)
24032456

24042457
/**
2458+
* Creates an expression that performs a case-sensitive wildcard string comparison.
2459+
*
2460+
* @param pattern The pattern to search for. You can use "%" as a wildcard character.
2461+
* @return A new [BooleanExpr] representing the like operation.
24052462
*/
2406-
fun like(pattern: Expr) = Companion.like(this, pattern)
2463+
fun like(pattern: Expr): BooleanExpr = Companion.like(this, pattern)
24072464

24082465
/**
2466+
* Creates an expression that performs a case-sensitive wildcard string comparison.
2467+
*
2468+
* @param pattern The pattern to search for. You can use "%" as a wildcard character.
2469+
* @return A new [BooleanExpr] representing the like operation.
24092470
*/
2410-
fun like(pattern: String) = Companion.like(this, pattern)
2471+
fun like(pattern: String): BooleanExpr = Companion.like(this, pattern)
24112472

24122473
/**
24132474
*/
2414-
fun regexContains(pattern: Expr) = Companion.regexContains(this, pattern)
2475+
fun regexContains(pattern: Expr): BooleanExpr = Companion.regexContains(this, pattern)
24152476

24162477
/**
24172478
*/
2418-
fun regexContains(pattern: String) = Companion.regexContains(this, pattern)
2479+
fun regexContains(pattern: String): BooleanExpr = Companion.regexContains(this, pattern)
24192480

24202481
/**
24212482
*/
2422-
fun regexMatch(pattern: Expr) = Companion.regexMatch(this, pattern)
2483+
fun regexMatch(pattern: Expr): BooleanExpr = Companion.regexMatch(this, pattern)
24232484

24242485
/**
24252486
*/
2426-
fun regexMatch(pattern: String) = Companion.regexMatch(this, pattern)
2487+
fun regexMatch(pattern: String): BooleanExpr = Companion.regexMatch(this, pattern)
24272488

24282489
/**
2490+
* Creates an expression that returns the largest value between multiple input expressions or
2491+
* literal values. Based on Firestore's value type ordering.
2492+
*
2493+
* @param others Expressions or literals.
2494+
* @return A new [Expr] representing the logical maximum operation.
24292495
*/
2430-
fun logicalMax(other: Expr) = Companion.logicalMax(this, other)
2496+
fun logicalMaximum(vararg others: Expr): Expr = Companion.logicalMaximum(this, *others)
24312497

24322498
/**
2499+
* Creates an expression that returns the largest value between multiple input expressions or
2500+
* literal values. Based on Firestore's value type ordering.
2501+
*
2502+
* @param others Expressions or literals.
2503+
* @return A new [Expr] representing the logical maximum operation.
24332504
*/
2434-
fun logicalMax(other: Any) = Companion.logicalMax(this, other)
2505+
fun logicalMaximum(vararg others: Any): Expr = Companion.logicalMaximum(this, *others)
24352506

24362507
/**
2508+
* Creates an expression that returns the smallest value between multiple input expressions or
2509+
* literal values. Based on Firestore's value type ordering.
2510+
*
2511+
* @param others Expressions or literals.
2512+
* @return A new [Expr] representing the logical minimum operation.
24372513
*/
2438-
fun logicalMin(other: Expr) = Companion.logicalMin(this, other)
2514+
fun logicalMinimum(vararg others: Expr): Expr = Companion.logicalMinimum(this, *others)
24392515

24402516
/**
2517+
* Creates an expression that returns the smallest value between multiple input expressions or
2518+
* literal values. Based on Firestore's value type ordering.
2519+
*
2520+
* @param others Expressions or literals.
2521+
* @return A new [Expr] representing the logical minimum operation.
24412522
*/
2442-
fun logicalMin(other: Any) = Companion.logicalMin(this, other)
2523+
fun logicalMinimum(vararg others: Any): Expr = Companion.logicalMinimum(this, *others)
24432524

24442525
/**
24452526
*/
2446-
fun reverse() = Companion.reverse(this)
2527+
fun reverse(): Expr = Companion.reverse(this)
24472528

24482529
/**
24492530
*/

0 commit comments

Comments
 (0)