Skip to content

Commit 1ae8be7

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

File tree

1 file changed

+116
-45
lines changed
  • firebase-firestore/src/main/java/com/google/firebase/firestore/pipeline

1 file changed

+116
-45
lines changed

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

Lines changed: 116 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -794,28 +794,88 @@ abstract class Expr internal constructor() {
794794
fun notEqAny(fieldName: String, arrayExpression: Expr): BooleanExpr =
795795
BooleanExpr("not_eq_any", fieldName, arrayExpression)
796796

797-
/** @return A new [Expr] representing the isNan operation. */
797+
/**
798+
* Creates an expression that returns true if a value is absent. Otherwise, returns false even
799+
* if the value is null.
800+
*
801+
* @param value The expression to check.
802+
* @return A new [BooleanExpr] representing the isAbsent operation.
803+
*/
804+
@JvmStatic fun isAbsent(value: Expr): BooleanExpr = BooleanExpr("is_absent", value)
805+
806+
/**
807+
* Creates an expression that returns true if a field is absent. Otherwise, returns false even
808+
* if the field value is null.
809+
*
810+
* @param fieldName The field to check.
811+
* @return A new [BooleanExpr] representing the isAbsent operation.
812+
*/
813+
@JvmStatic fun isAbsent(fieldName: String): BooleanExpr = BooleanExpr("is_absent", fieldName)
814+
815+
/**
816+
* Creates an expression that checks if an expression evaluates to 'NaN' (Not a Number).
817+
*
818+
* @param expr The expression to check.
819+
* @return A new [BooleanExpr] representing the isNan operation.
820+
*/
798821
@JvmStatic fun isNan(expr: Expr): BooleanExpr = BooleanExpr("is_nan", expr)
799822

800-
/** @return A new [Expr] representing the isNan operation. */
823+
/**
824+
* Creates an expression that checks if [expr] evaluates to 'NaN' (Not a Number).
825+
*
826+
* @param fieldName The field to check.
827+
* @return A new [BooleanExpr] representing the isNan operation.
828+
*/
801829
@JvmStatic fun isNan(fieldName: String): BooleanExpr = BooleanExpr("is_nan", fieldName)
802830

803-
/** @return A new [Expr] representing the isNotNan operation. */
831+
/**
832+
* Creates an expression that checks if the results of [expr] is NOT 'NaN' (Not a
833+
* Number).
834+
*
835+
* @param expr The expression to check.
836+
* @return A new [BooleanExpr] representing the isNotNan operation.
837+
*/
804838
@JvmStatic fun isNotNan(expr: Expr): BooleanExpr = BooleanExpr("is_not_nan", expr)
805839

806-
/** @return A new [Expr] representing the isNotNan operation. */
840+
/**
841+
* Creates an expression that checks if the results of this expression is NOT 'NaN' (Not a
842+
* Number).
843+
*
844+
* @param fieldName The field to check.
845+
* @return A new [BooleanExpr] representing the isNotNan operation.
846+
*/
807847
@JvmStatic fun isNotNan(fieldName: String): BooleanExpr = BooleanExpr("is_not_nan", fieldName)
808848

809-
/** @return A new [Expr] representing the isNull operation. */
849+
/**
850+
* Creates an expression that checks if tbe result of [expr] is null.
851+
*
852+
* @param expr The expression to check.
853+
* @return A new [BooleanExpr] representing the isNull operation.
854+
*/
810855
@JvmStatic fun isNull(expr: Expr): BooleanExpr = BooleanExpr("is_null", expr)
811856

812-
/** @return A new [Expr] representing the isNull operation. */
857+
/**
858+
* Creates an expression that checks if tbe value of a field is null.
859+
*
860+
* @param fieldName The field to check.
861+
* @return A new [BooleanExpr] representing the isNull operation.
862+
*/
813863
@JvmStatic fun isNull(fieldName: String): BooleanExpr = BooleanExpr("is_null", fieldName)
814864

815-
/** @return A new [Expr] representing the isNotNull operation. */
865+
/**
866+
* Creates an expression that checks if tbe result of [expr] is not null.
867+
*
868+
* @param expr The expression to check.
869+
* @return A new [BooleanExpr] representing the isNotNull operation.
870+
*/
816871
@JvmStatic fun isNotNull(expr: Expr): BooleanExpr = BooleanExpr("is_not_null", expr)
817872

818-
/** @return A new [Expr] representing the isNotNull operation. */
873+
/**
874+
* Creates an expression that checks if tbe value of a field is not null.
875+
*
876+
* @param fieldName The field to check.
877+
* @return A new [BooleanExpr] representing the isNotNull operation.
878+
*/
819879
@JvmStatic fun isNotNull(fieldName: String): BooleanExpr = BooleanExpr("is_not_null", fieldName)
820880

821881
/** @return A new [Expr] representing the replaceFirst operation. */
@@ -2031,20 +2091,20 @@ abstract class Expr internal constructor() {
20312091
@JvmStatic fun exists(fieldName: String): BooleanExpr = BooleanExpr("exists", fieldName)
20322092

20332093
/**
2034-
* Creates an expression that returns the [catchExpr] argument if there is an
2035-
* error, else return the result of the [tryExpr] argument evaluation.
2094+
* Creates an expression that returns the [catchExpr] argument if there is an error, else return
2095+
* the result of the [tryExpr] argument evaluation.
20362096
*
20372097
* @param tryExpr The try expression.
2038-
* @param catchExpr The catch expression that will be evaluated and
2039-
* returned if the [tryExpr] produces an error.
2098+
* @param catchExpr The catch expression that will be evaluated and returned if the [tryExpr]
2099+
* produces an error.
20402100
* @return A new [Expr] representing the ifError operation.
20412101
*/
20422102
@JvmStatic
20432103
fun ifError(tryExpr: Expr, catchExpr: Expr): Expr = FunctionExpr("if_error", tryExpr, catchExpr)
20442104

20452105
/**
2046-
* Creates an expression that returns the [catchValue] argument if there is an
2047-
* error, else return the result of the [tryExpr] argument evaluation.
2106+
* Creates an expression that returns the [catchValue] argument if there is an error, else
2107+
* return the result of the [tryExpr] argument evaluation.
20482108
*
20492109
* @param tryExpr The try expression.
20502110
* @param catchValue The value that will be returned if the [tryExpr] produces an error.
@@ -2250,7 +2310,7 @@ abstract class Expr internal constructor() {
22502310
* @param values The values to check against.
22512311
* @return A new [BooleanExpr] representing the 'IN' comparison.
22522312
*/
2253-
fun eqAny(values: List<Any>) = Companion.eqAny(this, values)
2313+
fun eqAny(values: List<Any>): BooleanExpr = Companion.eqAny(this, values)
22542314

22552315
/**
22562316
* Creates an expression that checks if this expression, when evaluated, is equal to any of the
@@ -2260,7 +2320,7 @@ abstract class Expr internal constructor() {
22602320
* equality to the input.
22612321
* @return A new [BooleanExpr] representing the 'IN' comparison.
22622322
*/
2263-
fun eqAny(arrayExpression: Expr) = Companion.eqAny(this, arrayExpression)
2323+
fun eqAny(arrayExpression: Expr): BooleanExpr = Companion.eqAny(this, arrayExpression)
22642324

22652325
/**
22662326
* Creates an expression that checks if this expression, when evaluated, is not equal to all the
@@ -2269,7 +2329,7 @@ abstract class Expr internal constructor() {
22692329
* @param values The values to check against.
22702330
* @return A new [BooleanExpr] representing the 'NOT IN' comparison.
22712331
*/
2272-
fun notEqAny(values: List<Any>) = Companion.notEqAny(this, values)
2332+
fun notEqAny(values: List<Any>): BooleanExpr = Companion.notEqAny(this, values)
22732333

22742334
/**
22752335
* Creates an expression that checks if this expression, when evaluated, is not equal to all the
@@ -2279,23 +2339,36 @@ abstract class Expr internal constructor() {
22792339
* equality to the input.
22802340
* @return A new [BooleanExpr] representing the 'NOT IN' comparison.
22812341
*/
2282-
fun notEqAny(arrayExpression: Expr) = Companion.notEqAny(this, arrayExpression)
2342+
fun notEqAny(arrayExpression: Expr): BooleanExpr = Companion.notEqAny(this, arrayExpression)
22832343

22842344
/**
2345+
* Creates an expression that checks if this expression evaluates to 'NaN' (Not a Number).
2346+
*
2347+
* @return A new [BooleanExpr] representing the isNan operation.
22852348
*/
2286-
fun isNan() = Companion.isNan(this)
2349+
fun isNan(): BooleanExpr = Companion.isNan(this)
22872350

22882351
/**
2352+
* Creates an expression that checks if the results of this expression is NOT 'NaN' (Not a
2353+
* Number).
2354+
*
2355+
* @return A new [BooleanExpr] representing the isNotNan operation.
22892356
*/
2290-
fun isNotNan() = Companion.isNotNan(this)
2357+
fun isNotNan(): BooleanExpr = Companion.isNotNan(this)
22912358

22922359
/**
2360+
* Creates an expression that checks if tbe result of this expression is null.
2361+
*
2362+
* @return A new [BooleanExpr] representing the isNull operation.
22932363
*/
2294-
fun isNull() = Companion.isNull(this)
2364+
fun isNull(): BooleanExpr = Companion.isNull(this)
22952365

22962366
/**
2367+
* Creates an expression that checks if tbe result of this expression is not null.
2368+
*
2369+
* @return A new [BooleanExpr] representing the isNotNull operation.
22972370
*/
2298-
fun isNotNull() = Companion.isNotNull(this)
2371+
fun isNotNull(): BooleanExpr = Companion.isNotNull(this)
22992372

23002373
/**
23012374
*/
@@ -2463,67 +2536,71 @@ abstract class Expr internal constructor() {
24632536
* @param vector The other vector (represented as an Expr) to compare against.
24642537
* @return A new [Expr] representing the cosine distance between the two vectors.
24652538
*/
2466-
fun cosineDistance(vector: Expr) = Companion.cosineDistance(this, vector)
2539+
fun cosineDistance(vector: Expr): Expr = Companion.cosineDistance(this, vector)
24672540

24682541
/**
24692542
* Calculates the Cosine distance between this vector expression and a vector literal.
24702543
*
24712544
* @param vector The other vector (as an array of doubles) to compare against.
24722545
* @return A new [Expr] representing the cosine distance between the two vectors.
24732546
*/
2474-
fun cosineDistance(vector: DoubleArray) = Companion.cosineDistance(this, vector)
2547+
fun cosineDistance(vector: DoubleArray): Expr = Companion.cosineDistance(this, vector)
24752548

24762549
/**
24772550
* Calculates the Cosine distance between this vector expression and a vector literal.
24782551
*
24792552
* @param vector The other vector (represented as an [VectorValue]) to compare against.
24802553
* @return A new [Expr] representing the cosine distance between the two vectors.
24812554
*/
2482-
fun cosineDistance(vector: VectorValue) = Companion.cosineDistance(this, vector)
2555+
fun cosineDistance(vector: VectorValue): Expr = Companion.cosineDistance(this, vector)
24832556

24842557
/**
24852558
* Calculates the dot product distance between this and another vector expression.
24862559
*
24872560
* @param vector The other vector (represented as an Expr) to compare against.
24882561
* @return A new [Expr] representing the dot product distance between the two vectors.
24892562
*/
2490-
fun dotProduct(vector: Expr) = Companion.dotProduct(this, vector)
2563+
fun dotProduct(vector: Expr): Expr = Companion.dotProduct(this, vector)
24912564

24922565
/**
24932566
* Calculates the dot product distance between this vector expression and a vector literal.
24942567
*
24952568
* @param vector The other vector (as an array of doubles) to compare against.
24962569
* @return A new [Expr] representing the dot product distance between the two vectors.
24972570
*/
2498-
fun dotProduct(vector: DoubleArray) = Companion.dotProduct(this, vector)
2571+
fun dotProduct(vector: DoubleArray): Expr = Companion.dotProduct(this, vector)
24992572

25002573
/**
25012574
* Calculates the dot product distance between this vector expression and a vector literal.
25022575
*
25032576
* @param vector The other vector (represented as an [VectorValue]) to compare against.
25042577
* @return A new [Expr] representing the dot product distance between the two vectors.
25052578
*/
2506-
fun dotProduct(vector: VectorValue) = Companion.dotProduct(this, vector)
2579+
fun dotProduct(vector: VectorValue): Expr = Companion.dotProduct(this, vector)
25072580

25082581
/**
25092582
* Calculates the Euclidean distance between this and another vector expression.
25102583
*
25112584
* @param vector The other vector (represented as an Expr) to compare against.
25122585
* @return A new [Expr] representing the Euclidean distance between the two vectors.
25132586
*/
2514-
fun euclideanDistance(vector: Expr) = Companion.euclideanDistance(this, vector)
2587+
fun euclideanDistance(vector: Expr): Expr = Companion.euclideanDistance(this, vector)
25152588

25162589
/**
25172590
* Calculates the Euclidean distance between this vector expression and a vector literal.
25182591
*
25192592
* @param vector The other vector (as an array of doubles) to compare against.
25202593
* @return A new [Expr] representing the Euclidean distance between the two vectors.
25212594
*/
2522-
fun euclideanDistance(vector: DoubleArray) = Companion.euclideanDistance(this, vector)
2595+
fun euclideanDistance(vector: DoubleArray): Expr = Companion.euclideanDistance(this, vector)
25232596

25242597
/**
2598+
* Calculates the Euclidean distance between this vector expression and a vector literal.
2599+
*
2600+
* @param vector The other vector (represented as an [VectorValue]) to compare against.
2601+
* @return A new [Expr] representing the Euclidean distance between the two vectors.
25252602
*/
2526-
fun euclideanDistance(vector: VectorValue) = Companion.euclideanDistance(this, vector)
2603+
fun euclideanDistance(vector: VectorValue): Expr = Companion.euclideanDistance(this, vector)
25272604

25282605
/**
25292606
*/
@@ -2834,18 +2911,18 @@ abstract class Expr internal constructor() {
28342911
fun exists(): BooleanExpr = Companion.exists(this)
28352912

28362913
/**
2837-
* Creates an expression that returns the [catchExpr] argument if there is an
2838-
* error, else return the result of this expression.
2914+
* Creates an expression that returns the [catchExpr] argument if there is an error, else return
2915+
* the result of this expression.
28392916
*
2840-
* @param catchExpr The catch expression that will be evaluated and
2841-
* returned if the this expression produces an error.
2917+
* @param catchExpr The catch expression that will be evaluated and returned if the this
2918+
* expression produces an error.
28422919
* @return A new [Expr] representing the ifError operation.
28432920
*/
28442921
fun ifError(catchExpr: Expr): Expr = Companion.ifError(this, catchExpr)
28452922

28462923
/**
2847-
* Creates an expression that returns the [catchValue] argument if there is an
2848-
* error, else return the result of this expression.
2924+
* Creates an expression that returns the [catchValue] argument if there is an error, else return
2925+
* the result of this expression.
28492926
*
28502927
* @param catchValue The value that will be returned if this expression produces an error.
28512928
* @return A new [Expr] representing the ifError operation.
@@ -2966,10 +3043,7 @@ internal constructor(
29663043
/** A class that represents a filter condition. */
29673044
open class BooleanExpr internal constructor(name: String, params: Array<out Expr>) :
29683045
FunctionExpr(name, params, InternalOptions.EMPTY) {
2969-
internal constructor(
2970-
name: String,
2971-
param: Expr
2972-
) : this(name, arrayOf(param))
3046+
internal constructor(name: String, param: Expr) : this(name, arrayOf(param))
29733047
internal constructor(
29743048
name: String,
29753049
param: Expr,
@@ -2980,10 +3054,7 @@ open class BooleanExpr internal constructor(name: String, params: Array<out Expr
29803054
param1: Expr,
29813055
param2: Expr
29823056
) : this(name, arrayOf(param1, param2))
2983-
internal constructor(
2984-
name: String,
2985-
fieldName: String
2986-
) : this(name, arrayOf(field(fieldName)))
3057+
internal constructor(name: String, fieldName: String) : this(name, arrayOf(field(fieldName)))
29873058
internal constructor(
29883059
name: String,
29893060
fieldName: String,

0 commit comments

Comments
 (0)