Skip to content

Commit 309fa91

Browse files
committed
WIP
1 parent 83d94e4 commit 309fa91

File tree

2 files changed

+36
-24
lines changed

2 files changed

+36
-24
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ internal constructor(internal val alias: String, internal val expr: AggregateFun
2222

2323
/** A class that represents an aggregate function. */
2424
class AggregateFunction
25-
private constructor(private val name: String, private val params: Array<out Expr>) {
25+
private constructor(
26+
private val name: String,
27+
private val params: Array<out Expr>,
28+
private val options: InternalOptions = InternalOptions.EMPTY
29+
) {
2630
private constructor(name: String) : this(name, emptyArray())
2731
private constructor(name: String, expr: Expr) : this(name, arrayOf(expr))
2832
private constructor(name: String, fieldName: String) : this(name, Expr.field(fieldName))
@@ -71,6 +75,7 @@ private constructor(private val name: String, private val params: Array<out Expr
7175
for (param in params) {
7276
builder.addArgs(param.toProto(userDataReader))
7377
}
78+
options.forEach(builder::putOptions)
7479
return Value.newBuilder().setFunctionValue(builder).build()
7580
}
7681
}

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

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,14 +1124,10 @@ abstract class Expr internal constructor() {
11241124
fun arrayConcat(firstArrayField: String, secondArray: Any, vararg otherArrays: Any): Expr =
11251125
FunctionExpr("array_concat", firstArrayField, secondArray, *otherArrays)
11261126

1127-
/**
1128-
* @return A new [Expr] representing the arrayReverse operation.
1129-
*/
1127+
/** @return A new [Expr] representing the arrayReverse operation. */
11301128
@JvmStatic fun arrayReverse(array: Expr): Expr = FunctionExpr("array_reverse", array)
11311129

1132-
/**
1133-
* @return A new [Expr] representing the arrayReverse operation.
1134-
*/
1130+
/** @return A new [Expr] representing the arrayReverse operation. */
11351131
@JvmStatic fun arrayReverse(fieldName: String): Expr = FunctionExpr("array_reverse", fieldName)
11361132

11371133
/**
@@ -1184,7 +1180,8 @@ abstract class Expr internal constructor() {
11841180
* @return A new [BooleanExpr] representing the arrayContainsAll operation.
11851181
*/
11861182
@JvmStatic
1187-
fun arrayContainsAll(array: Expr, values: List<Any>) = arrayContainsAll(array, ListOfExprs(toArrayOfExprOrConstant(values)))
1183+
fun arrayContainsAll(array: Expr, values: List<Any>) =
1184+
arrayContainsAll(array, ListOfExprs(toArrayOfExprOrConstant(values)))
11881185

11891186
/**
11901187
* Creates an expression that checks if [array] contains all elements of [arrayExpression].
@@ -1206,7 +1203,11 @@ abstract class Expr internal constructor() {
12061203
*/
12071204
@JvmStatic
12081205
fun arrayContainsAll(arrayFieldName: String, values: List<Any>) =
1209-
BooleanExpr("array_contains_all", arrayFieldName, ListOfExprs(toArrayOfExprOrConstant(values)))
1206+
BooleanExpr(
1207+
"array_contains_all",
1208+
arrayFieldName,
1209+
ListOfExprs(toArrayOfExprOrConstant(values))
1210+
)
12101211

12111212
/**
12121213
* Creates an expression that checks if array field contains all elements of [arrayExpression].
@@ -1250,7 +1251,11 @@ abstract class Expr internal constructor() {
12501251
*/
12511252
@JvmStatic
12521253
fun arrayContainsAny(arrayFieldName: String, values: List<Any>) =
1253-
BooleanExpr("array_contains_any", arrayFieldName, ListOfExprs(toArrayOfExprOrConstant(values)))
1254+
BooleanExpr(
1255+
"array_contains_any",
1256+
arrayFieldName,
1257+
ListOfExprs(toArrayOfExprOrConstant(values))
1258+
)
12541259

12551260
/**
12561261
* Creates an expression that checks if array field contains any elements of [arrayExpression].
@@ -1277,25 +1282,20 @@ abstract class Expr internal constructor() {
12771282
* @param arrayFieldName The name of the field containing an array to calculate the length of.
12781283
* @return A new [Expr] representing the the length of the array.
12791284
*/
1280-
@JvmStatic fun arrayLength(arrayFieldName: String): Expr = FunctionExpr("array_length", arrayFieldName)
1285+
@JvmStatic
1286+
fun arrayLength(arrayFieldName: String): Expr = FunctionExpr("array_length", arrayFieldName)
12811287

1282-
/**
1283-
* @return A new [Expr] representing the cond operation.
1284-
*/
1288+
/** @return A new [Expr] representing the cond operation. */
12851289
@JvmStatic
12861290
fun cond(condition: BooleanExpr, then: Expr, otherwise: Expr): Expr =
12871291
FunctionExpr("cond", condition, then, otherwise)
12881292

1289-
/**
1290-
* @return A new [Expr] representing the cond operation.
1291-
*/
1293+
/** @return A new [Expr] representing the cond operation. */
12921294
@JvmStatic
12931295
fun cond(condition: BooleanExpr, then: Any, otherwise: Any): Expr =
12941296
FunctionExpr("cond", condition, then, otherwise)
12951297

1296-
/**
1297-
* @return A new [Expr] representing the exists operation.
1298-
*/
1298+
/** @return A new [Expr] representing the exists operation. */
12991299
@JvmStatic fun exists(expr: Expr) = BooleanExpr("exists", expr)
13001300
}
13011301

@@ -1700,7 +1700,8 @@ abstract class Expr internal constructor() {
17001700
* @param arrayExpression The elements to check for in the array.
17011701
* @return A new [BooleanExpr] representing the arrayContainsAll operation.
17021702
*/
1703-
fun arrayContainsAll(arrayExpression: Expr): BooleanExpr = Companion.arrayContainsAll(this, arrayExpression)
1703+
fun arrayContainsAll(arrayExpression: Expr): BooleanExpr =
1704+
Companion.arrayContainsAll(this, arrayExpression)
17041705

17051706
/**
17061707
* Creates an expression that checks if array contains any of the specified [values].
@@ -1716,7 +1717,8 @@ abstract class Expr internal constructor() {
17161717
* @param arrayExpression The elements to check for in the array.
17171718
* @return A new [BooleanExpr] representing the arrayContainsAny operation.
17181719
*/
1719-
fun arrayContainsAny(arrayExpression: Expr): BooleanExpr = Companion.arrayContainsAny(this, arrayExpression)
1720+
fun arrayContainsAny(arrayExpression: Expr): BooleanExpr =
1721+
Companion.arrayContainsAny(this, arrayExpression)
17201722

17211723
/**
17221724
* Creates an expression that calculates the length of an array expression.
@@ -1872,7 +1874,11 @@ internal class ListOfExprs(private val expressions: Array<out Expr>) : Expr() {
18721874
* [FunctionExpr] instances.
18731875
*/
18741876
open class FunctionExpr
1875-
internal constructor(private val name: String, private val params: Array<out Expr>) : Expr() {
1877+
internal constructor(
1878+
private val name: String,
1879+
private val params: Array<out Expr>,
1880+
private val options: InternalOptions = InternalOptions.EMPTY
1881+
) : Expr() {
18761882
internal constructor(
18771883
name: String,
18781884
param: Expr,
@@ -1896,13 +1902,14 @@ internal constructor(private val name: String, private val params: Array<out Exp
18961902
for (param in params) {
18971903
builder.addArgs(param.toProto(userDataReader))
18981904
}
1905+
options.forEach(builder::putOptions)
18991906
return Value.newBuilder().setFunctionValue(builder).build()
19001907
}
19011908
}
19021909

19031910
/** An interface that represents a filter condition. */
19041911
open class BooleanExpr internal constructor(name: String, params: Array<out Expr>) :
1905-
FunctionExpr(name, params) {
1912+
FunctionExpr(name, params, InternalOptions.EMPTY) {
19061913
internal constructor(
19071914
name: String,
19081915
params: List<Any>

0 commit comments

Comments
 (0)