Skip to content

Commit c324298

Browse files
committed
More expression work
1 parent d6cd6d9 commit c324298

File tree

1 file changed

+125
-22
lines changed
  • firebase-firestore/src/main/java/com/google/firebase/firestore/pipeline

1 file changed

+125
-22
lines changed

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

Lines changed: 125 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,53 @@ abstract class Expr internal constructor() {
570570
fun bitRightShift(bitsFieldName: String, number: Int): Expr =
571571
FunctionExpr("bit_right_shift", bitsFieldName, number)
572572

573+
@JvmStatic
574+
fun round(numericExpr: Expr, decimalPlace: Int): Expr =
575+
FunctionExpr("round", numericExpr, constant(decimalPlace))
576+
577+
@JvmStatic
578+
fun round(numericField: String, decimalPlace: Int): Expr =
579+
FunctionExpr("round", numericField, constant(decimalPlace))
580+
581+
@JvmStatic fun round(numericExpr: Expr): Expr = FunctionExpr("round", numericExpr)
582+
583+
@JvmStatic fun round(numericField: String): Expr = FunctionExpr("round", numericField)
584+
585+
@JvmStatic
586+
fun round(numericExpr: Expr, decimalPlace: Expr): Expr =
587+
FunctionExpr("round", numericExpr, decimalPlace)
588+
589+
@JvmStatic
590+
fun round(numericField: String, decimalPlace: Expr): Expr =
591+
FunctionExpr("round", numericField, decimalPlace)
592+
593+
@JvmStatic fun ceil(numericExpr: Expr): Expr = FunctionExpr("ceil", numericExpr)
594+
595+
@JvmStatic fun ceil(numericField: String): Expr = FunctionExpr("ceil", numericField)
596+
597+
@JvmStatic fun floor(numericExpr: Expr): Expr = FunctionExpr("floor", numericExpr)
598+
599+
@JvmStatic fun floor(numericField: String): Expr = FunctionExpr("floor", numericField)
600+
601+
@JvmStatic
602+
fun pow(numericExpr: Expr, exponent: Number): Expr =
603+
FunctionExpr("pow", numericExpr, constant(exponent))
604+
605+
@JvmStatic
606+
fun pow(numericField: String, exponent: Number): Expr =
607+
FunctionExpr("pow", numericField, constant(exponent))
608+
609+
@JvmStatic
610+
fun pow(numericExpr: Expr, exponent: Expr): Expr = FunctionExpr("pow", numericExpr, exponent)
611+
612+
@JvmStatic
613+
fun pow(numericField: String, exponent: Expr): Expr =
614+
FunctionExpr("pow", numericField, exponent)
615+
616+
@JvmStatic fun sqrt(numericExpr: Expr): Expr = FunctionExpr("sqrt", numericExpr)
617+
618+
@JvmStatic fun sqrt(numericField: String): Expr = FunctionExpr("sqrt", numericField)
619+
573620
/**
574621
* Creates an expression that adds this expression to another expression.
575622
*
@@ -1243,35 +1290,69 @@ abstract class Expr internal constructor() {
12431290
fun map(elements: Map<String, Any>): Expr =
12441291
map(elements.flatMap { listOf(constant(it.key), toExprOrConstant(it.value)) }.toTypedArray())
12451292

1246-
/** @return A new [Expr] representing the mapGet operation. */
1247-
@JvmStatic fun mapGet(map: Expr, key: Expr): Expr = FunctionExpr("map_get", map, key)
1248-
1249-
/** @return A new [Expr] representing the mapGet operation. */
1250-
@JvmStatic fun mapGet(map: Expr, key: String): Expr = FunctionExpr("map_get", map, key)
1251-
1252-
/** @return A new [Expr] representing the mapGet operation. */
1293+
/**
1294+
* Accesses a value from a map (object) field using the provided [key].
1295+
*
1296+
* @param mapExpression The expression representing the map.
1297+
* @param key The key to access in the map.
1298+
* @return A new [Expr] representing the value associated with the given key in the map.
1299+
*/
12531300
@JvmStatic
1254-
fun mapGet(fieldName: String, key: Expr): Expr = FunctionExpr("map_get", fieldName, key)
1301+
fun mapGet(mapExpression: Expr, key: String): Expr = FunctionExpr("map_get", mapExpression, key)
12551302

1256-
/** @return A new [Expr] representing the mapGet operation. */
1303+
/**
1304+
* Accesses a value from a map (object) field using the provided [key].
1305+
*
1306+
* @param fieldName The field name of the map field.
1307+
* @param key The key to access in the map.
1308+
* @return A new [Expr] representing the value associated with the given key in the map.
1309+
*/
12571310
@JvmStatic
12581311
fun mapGet(fieldName: String, key: String): Expr = FunctionExpr("map_get", fieldName, key)
12591312

1260-
/** @return A new [Expr] representing the mapMerge operation. */
1313+
/**
1314+
* Creates an expression that merges multiple maps into a single map. If multiple maps have the
1315+
* same key, the later value is used.
1316+
*
1317+
* @param firstMap First map expression that will be merged.
1318+
* @param secondMap Second map expression that will be merged.
1319+
* @param otherMaps Additional maps to merge.
1320+
* @return A new [Expr] representing the mapMerge operation.
1321+
*/
12611322
@JvmStatic
12621323
fun mapMerge(firstMap: Expr, secondMap: Expr, vararg otherMaps: Expr): Expr =
12631324
FunctionExpr("map_merge", firstMap, secondMap, *otherMaps)
12641325

1265-
/** @return A new [Expr] representing the mapMerge operation. */
1326+
/**
1327+
* Creates an expression that merges multiple maps into a single map. If multiple maps have the
1328+
* same key, the later value is used.
1329+
*
1330+
* @param firstMapFieldName First map field name that will be merged.
1331+
* @param secondMap Second map expression that will be merged.
1332+
* @param otherMaps Additional maps to merge.
1333+
* @return A new [Expr] representing the mapMerge operation.
1334+
*/
12661335
@JvmStatic
1267-
fun mapMerge(mapField: String, secondMap: Expr, vararg otherMaps: Expr): Expr =
1268-
FunctionExpr("map_merge", mapField, secondMap, *otherMaps)
1336+
fun mapMerge(firstMapFieldName: String, secondMap: Expr, vararg otherMaps: Expr): Expr =
1337+
FunctionExpr("map_merge", firstMapFieldName, secondMap, *otherMaps)
12691338

1270-
/** @return A new [Expr] representing the mapRemove operation. */
1339+
/**
1340+
* Creates an expression that removes a key from the map produced by evaluating an expression.
1341+
*
1342+
* @param mapExpr An expression return a map value.
1343+
* @param key The name of the key to remove from the input map.
1344+
* @return A new [Expr] that evaluates to a modified map.
1345+
*/
12711346
@JvmStatic
1272-
fun mapRemove(firstMap: Expr, key: Expr): Expr = FunctionExpr("map_remove", firstMap, key)
1347+
fun mapRemove(mapExpr: Expr, key: Expr): Expr = FunctionExpr("map_remove", mapExpr, key)
12731348

1274-
/** @return A new [Expr] representing the mapRemove operation. */
1349+
/**
1350+
* Creates an expression that removes a key from the map produced by evaluating an expression.
1351+
*
1352+
* @param mapField The name of a field containing a map value.
1353+
* @param key The name of the key to remove from the input map.
1354+
* @return A new [Expr] that evaluates to a modified map.
1355+
*/
12751356
@JvmStatic
12761357
fun mapRemove(mapField: String, key: Expr): Expr = FunctionExpr("map_remove", mapField, key)
12771358

@@ -2348,6 +2429,22 @@ abstract class Expr internal constructor() {
23482429
*/
23492430
fun mod(other: Any) = Companion.mod(this, other)
23502431

2432+
fun round() = Companion.round(this)
2433+
2434+
fun round(decimalPlace: Int) = Companion.round(this, decimalPlace)
2435+
2436+
fun round(decimalPlace: Expr) = Companion.round(this, decimalPlace)
2437+
2438+
fun ceil() = Companion.ceil(this)
2439+
2440+
fun floor() = Companion.floor(this)
2441+
2442+
fun pow(exponentExpr: Number) = Companion.pow(this, exponentExpr)
2443+
2444+
fun pow(exponentExpr: Expr) = Companion.pow(this, exponentExpr)
2445+
2446+
fun sqrt() = Companion.sqrt(this)
2447+
23512448
/**
23522449
* Creates an expression that checks if this expression, when evaluated, is equal to any of the
23532450
* provided [values].
@@ -2591,17 +2688,23 @@ abstract class Expr internal constructor() {
25912688
fun strConcat(vararg string: Any) = Companion.strConcat(this, *string)
25922689

25932690
/**
2594-
*/
2595-
fun mapGet(key: Expr) = Companion.mapGet(this, key)
2596-
2597-
/**
2691+
* Accesses a map (object) value using the provided [key].
2692+
*
2693+
* @param key The key to access in the map.
2694+
* @return A new [Expr] representing the value associated with the given key in the map.
25982695
*/
25992696
fun mapGet(key: String) = Companion.mapGet(this, key)
26002697

26012698
/**
2699+
* Creates an expression that merges multiple maps into a single map. If multiple maps have the
2700+
* same key, the later value is used.
2701+
*
2702+
* @param mapExpr Map expression that will be merged.
2703+
* @param otherMaps Additional maps to merge.
2704+
* @return A new [Expr] representing the mapMerge operation.
26022705
*/
2603-
fun mapMerge(secondMap: Expr, vararg otherMaps: Expr) =
2604-
Companion.mapMerge(this, secondMap, *otherMaps)
2706+
fun mapMerge(mapExpr: Expr, vararg otherMaps: Expr) =
2707+
Companion.mapMerge(this, mapExpr, *otherMaps)
26052708

26062709
/**
26072710
*/

0 commit comments

Comments
 (0)