Skip to content

Commit 8a58ed2

Browse files
committed
More expression work
1 parent eb02ca4 commit 8a58ed2

File tree

4 files changed

+223
-62
lines changed

4 files changed

+223
-62
lines changed

firebase-firestore/api.txt

+24-24
Original file line numberDiff line numberDiff line change
@@ -691,35 +691,35 @@ package com.google.firebase.firestore.pipeline {
691691

692692
public final class AggregateFunction {
693693
method public com.google.firebase.firestore.pipeline.AggregateWithAlias alias(String alias);
694-
method public static com.google.firebase.firestore.pipeline.AggregateFunction avg(com.google.firebase.firestore.pipeline.Expr expr);
694+
method public static com.google.firebase.firestore.pipeline.AggregateFunction avg(com.google.firebase.firestore.pipeline.Expr expression);
695695
method public static com.google.firebase.firestore.pipeline.AggregateFunction avg(String fieldName);
696-
method public static com.google.firebase.firestore.pipeline.AggregateFunction count(com.google.firebase.firestore.pipeline.Expr expr);
696+
method public static com.google.firebase.firestore.pipeline.AggregateFunction count(com.google.firebase.firestore.pipeline.Expr expression);
697697
method public static com.google.firebase.firestore.pipeline.AggregateFunction count(String fieldName);
698698
method public static com.google.firebase.firestore.pipeline.AggregateFunction countAll();
699699
method public static com.google.firebase.firestore.pipeline.AggregateFunction countIf(com.google.firebase.firestore.pipeline.BooleanExpr condition);
700700
method public static com.google.firebase.firestore.pipeline.AggregateFunction generic(String name, com.google.firebase.firestore.pipeline.Expr... expr);
701-
method public static com.google.firebase.firestore.pipeline.AggregateFunction max(com.google.firebase.firestore.pipeline.Expr expr);
702-
method public static com.google.firebase.firestore.pipeline.AggregateFunction max(String fieldName);
703-
method public static com.google.firebase.firestore.pipeline.AggregateFunction min(com.google.firebase.firestore.pipeline.Expr expr);
704-
method public static com.google.firebase.firestore.pipeline.AggregateFunction min(String fieldName);
705-
method public static com.google.firebase.firestore.pipeline.AggregateFunction sum(com.google.firebase.firestore.pipeline.Expr expr);
701+
method public static com.google.firebase.firestore.pipeline.AggregateFunction maximum(com.google.firebase.firestore.pipeline.Expr expression);
702+
method public static com.google.firebase.firestore.pipeline.AggregateFunction maximum(String fieldName);
703+
method public static com.google.firebase.firestore.pipeline.AggregateFunction minimum(com.google.firebase.firestore.pipeline.Expr expression);
704+
method public static com.google.firebase.firestore.pipeline.AggregateFunction minimum(String fieldName);
705+
method public static com.google.firebase.firestore.pipeline.AggregateFunction sum(com.google.firebase.firestore.pipeline.Expr expression);
706706
method public static com.google.firebase.firestore.pipeline.AggregateFunction sum(String fieldName);
707707
field public static final com.google.firebase.firestore.pipeline.AggregateFunction.Companion Companion;
708708
}
709709

710710
public static final class AggregateFunction.Companion {
711-
method public com.google.firebase.firestore.pipeline.AggregateFunction avg(com.google.firebase.firestore.pipeline.Expr expr);
711+
method public com.google.firebase.firestore.pipeline.AggregateFunction avg(com.google.firebase.firestore.pipeline.Expr expression);
712712
method public com.google.firebase.firestore.pipeline.AggregateFunction avg(String fieldName);
713-
method public com.google.firebase.firestore.pipeline.AggregateFunction count(com.google.firebase.firestore.pipeline.Expr expr);
713+
method public com.google.firebase.firestore.pipeline.AggregateFunction count(com.google.firebase.firestore.pipeline.Expr expression);
714714
method public com.google.firebase.firestore.pipeline.AggregateFunction count(String fieldName);
715715
method public com.google.firebase.firestore.pipeline.AggregateFunction countAll();
716716
method public com.google.firebase.firestore.pipeline.AggregateFunction countIf(com.google.firebase.firestore.pipeline.BooleanExpr condition);
717717
method public com.google.firebase.firestore.pipeline.AggregateFunction generic(String name, com.google.firebase.firestore.pipeline.Expr... expr);
718-
method public com.google.firebase.firestore.pipeline.AggregateFunction max(com.google.firebase.firestore.pipeline.Expr expr);
719-
method public com.google.firebase.firestore.pipeline.AggregateFunction max(String fieldName);
720-
method public com.google.firebase.firestore.pipeline.AggregateFunction min(com.google.firebase.firestore.pipeline.Expr expr);
721-
method public com.google.firebase.firestore.pipeline.AggregateFunction min(String fieldName);
722-
method public com.google.firebase.firestore.pipeline.AggregateFunction sum(com.google.firebase.firestore.pipeline.Expr expr);
718+
method public com.google.firebase.firestore.pipeline.AggregateFunction maximum(com.google.firebase.firestore.pipeline.Expr expression);
719+
method public com.google.firebase.firestore.pipeline.AggregateFunction maximum(String fieldName);
720+
method public com.google.firebase.firestore.pipeline.AggregateFunction minimum(com.google.firebase.firestore.pipeline.Expr expression);
721+
method public com.google.firebase.firestore.pipeline.AggregateFunction minimum(String fieldName);
722+
method public com.google.firebase.firestore.pipeline.AggregateFunction sum(com.google.firebase.firestore.pipeline.Expr expression);
723723
method public com.google.firebase.firestore.pipeline.AggregateFunction sum(String fieldName);
724724
}
725725

@@ -738,8 +738,8 @@ package com.google.firebase.firestore.pipeline {
738738
}
739739

740740
public class BooleanExpr extends com.google.firebase.firestore.pipeline.FunctionExpr {
741-
method public final com.google.firebase.firestore.pipeline.Expr cond(com.google.firebase.firestore.pipeline.Expr then, com.google.firebase.firestore.pipeline.Expr otherwise);
742-
method public final com.google.firebase.firestore.pipeline.Expr cond(Object then, Object otherwise);
741+
method public final com.google.firebase.firestore.pipeline.Expr cond(com.google.firebase.firestore.pipeline.Expr thenExpr, com.google.firebase.firestore.pipeline.Expr elseExpr);
742+
method public final com.google.firebase.firestore.pipeline.Expr cond(Object thenValue, Object elseValue);
743743
method public final com.google.firebase.firestore.pipeline.AggregateFunction countIf();
744744
method public static final com.google.firebase.firestore.pipeline.BooleanExpr generic(String name, com.google.firebase.firestore.pipeline.Expr... expr);
745745
method public final com.google.firebase.firestore.pipeline.BooleanExpr not();
@@ -1062,8 +1062,8 @@ package com.google.firebase.firestore.pipeline {
10621062
method public final com.google.firebase.firestore.pipeline.Expr mapRemove(String key);
10631063
method public static final com.google.firebase.firestore.pipeline.Expr mapRemove(String mapField, com.google.firebase.firestore.pipeline.Expr key);
10641064
method public static final com.google.firebase.firestore.pipeline.Expr mapRemove(String mapField, String key);
1065-
method public final com.google.firebase.firestore.pipeline.AggregateFunction max();
1066-
method public final com.google.firebase.firestore.pipeline.AggregateFunction min();
1065+
method public final com.google.firebase.firestore.pipeline.AggregateFunction maximum();
1066+
method public final com.google.firebase.firestore.pipeline.AggregateFunction minimum();
10671067
method public final com.google.firebase.firestore.pipeline.Expr mod(com.google.firebase.firestore.pipeline.Expr divisor);
10681068
method public static final com.google.firebase.firestore.pipeline.Expr mod(com.google.firebase.firestore.pipeline.Expr dividend, com.google.firebase.firestore.pipeline.Expr divisor);
10691069
method public static final com.google.firebase.firestore.pipeline.Expr mod(com.google.firebase.firestore.pipeline.Expr dividend, Number divisor);
@@ -1194,18 +1194,18 @@ package com.google.firebase.firestore.pipeline {
11941194
method public static final com.google.firebase.firestore.pipeline.Expr trim(com.google.firebase.firestore.pipeline.Expr stringExpression);
11951195
method public static final com.google.firebase.firestore.pipeline.Expr trim(String fieldName);
11961196
method public final com.google.firebase.firestore.pipeline.Expr unixMicrosToTimestamp();
1197-
method public static final com.google.firebase.firestore.pipeline.Expr unixMicrosToTimestamp(com.google.firebase.firestore.pipeline.Expr input);
1197+
method public static final com.google.firebase.firestore.pipeline.Expr unixMicrosToTimestamp(com.google.firebase.firestore.pipeline.Expr expr);
11981198
method public static final com.google.firebase.firestore.pipeline.Expr unixMicrosToTimestamp(String fieldName);
11991199
method public final com.google.firebase.firestore.pipeline.Expr unixMillisToTimestamp();
12001200
method public static final com.google.firebase.firestore.pipeline.Expr unixMillisToTimestamp(com.google.firebase.firestore.pipeline.Expr expr);
12011201
method public static final com.google.firebase.firestore.pipeline.Expr unixMillisToTimestamp(String fieldName);
12021202
method public final com.google.firebase.firestore.pipeline.Expr unixSecondsToTimestamp();
1203-
method public static final com.google.firebase.firestore.pipeline.Expr unixSecondsToTimestamp(com.google.firebase.firestore.pipeline.Expr input);
1203+
method public static final com.google.firebase.firestore.pipeline.Expr unixSecondsToTimestamp(com.google.firebase.firestore.pipeline.Expr expr);
12041204
method public static final com.google.firebase.firestore.pipeline.Expr unixSecondsToTimestamp(String fieldName);
12051205
method public static final com.google.firebase.firestore.pipeline.Expr vector(com.google.firebase.firestore.VectorValue vector);
12061206
method public static final com.google.firebase.firestore.pipeline.Expr vector(double[] vector);
12071207
method public final com.google.firebase.firestore.pipeline.Expr vectorLength();
1208-
method public static final com.google.firebase.firestore.pipeline.Expr vectorLength(com.google.firebase.firestore.pipeline.Expr vector);
1208+
method public static final com.google.firebase.firestore.pipeline.Expr vectorLength(com.google.firebase.firestore.pipeline.Expr vectorExpression);
12091209
method public static final com.google.firebase.firestore.pipeline.Expr vectorLength(String fieldName);
12101210
method public static final com.google.firebase.firestore.pipeline.BooleanExpr xor(com.google.firebase.firestore.pipeline.BooleanExpr condition, com.google.firebase.firestore.pipeline.BooleanExpr... conditions);
12111211
field public static final com.google.firebase.firestore.pipeline.Expr.Companion Companion;
@@ -1456,15 +1456,15 @@ package com.google.firebase.firestore.pipeline {
14561456
method public com.google.firebase.firestore.pipeline.Expr toUpper(String fieldName);
14571457
method public com.google.firebase.firestore.pipeline.Expr trim(com.google.firebase.firestore.pipeline.Expr stringExpression);
14581458
method public com.google.firebase.firestore.pipeline.Expr trim(String fieldName);
1459-
method public com.google.firebase.firestore.pipeline.Expr unixMicrosToTimestamp(com.google.firebase.firestore.pipeline.Expr input);
1459+
method public com.google.firebase.firestore.pipeline.Expr unixMicrosToTimestamp(com.google.firebase.firestore.pipeline.Expr expr);
14601460
method public com.google.firebase.firestore.pipeline.Expr unixMicrosToTimestamp(String fieldName);
14611461
method public com.google.firebase.firestore.pipeline.Expr unixMillisToTimestamp(com.google.firebase.firestore.pipeline.Expr expr);
14621462
method public com.google.firebase.firestore.pipeline.Expr unixMillisToTimestamp(String fieldName);
1463-
method public com.google.firebase.firestore.pipeline.Expr unixSecondsToTimestamp(com.google.firebase.firestore.pipeline.Expr input);
1463+
method public com.google.firebase.firestore.pipeline.Expr unixSecondsToTimestamp(com.google.firebase.firestore.pipeline.Expr expr);
14641464
method public com.google.firebase.firestore.pipeline.Expr unixSecondsToTimestamp(String fieldName);
14651465
method public com.google.firebase.firestore.pipeline.Expr vector(com.google.firebase.firestore.VectorValue vector);
14661466
method public com.google.firebase.firestore.pipeline.Expr vector(double[] vector);
1467-
method public com.google.firebase.firestore.pipeline.Expr vectorLength(com.google.firebase.firestore.pipeline.Expr vector);
1467+
method public com.google.firebase.firestore.pipeline.Expr vectorLength(com.google.firebase.firestore.pipeline.Expr vectorExpression);
14681468
method public com.google.firebase.firestore.pipeline.Expr vectorLength(String fieldName);
14691469
method public com.google.firebase.firestore.pipeline.BooleanExpr xor(com.google.firebase.firestore.pipeline.BooleanExpr condition, com.google.firebase.firestore.pipeline.BooleanExpr... conditions);
14701470
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ public void aggregateResultsMany() {
244244
.aggregate(
245245
AggregateFunction.countAll().alias("count"),
246246
AggregateFunction.avg("rating").alias("avgRating"),
247-
field("rating").max().alias("maxRating"))
247+
field("rating").maximum().alias("maxRating"))
248248
.execute();
249249
assertThat(waitFor(execute).getResults())
250250
.comparingElementsUsing(DATA_CORRESPONDENCE)
@@ -304,8 +304,8 @@ public void minAndMaxAccumulations() {
304304
.collection(randomCol)
305305
.aggregate(
306306
AggregateFunction.countAll().alias("count"),
307-
field("rating").max().alias("maxRating"),
308-
field("published").min().alias("minPublished"))
307+
field("rating").maximum().alias("maxRating"),
308+
field("published").minimum().alias("minPublished"))
309309
.execute();
310310
assertThat(waitFor(execute).getResults())
311311
.comparingElementsUsing(DATA_CORRESPONDENCE)

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

+92-13
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,108 @@ private constructor(
3535

3636
@JvmStatic fun generic(name: String, vararg expr: Expr) = AggregateFunction(name, expr)
3737

38+
/**
39+
* Creates an aggregation that counts the total number of stage inputs.
40+
*
41+
* @return A new [AggregateFunction] representing the countAll aggregation.
42+
*/
3843
@JvmStatic fun countAll() = AggregateFunction("count")
3944

45+
/**
46+
* Creates an aggregation that counts the number of stage inputs where the input field exists.
47+
*
48+
* @param fieldName The name of the field to count.
49+
* @return A new [AggregateFunction] representing the 'count' aggregation.
50+
*/
4051
@JvmStatic fun count(fieldName: String) = AggregateFunction("count", fieldName)
4152

42-
@JvmStatic fun count(expr: Expr) = AggregateFunction("count", expr)
43-
53+
/**
54+
* Creates an aggregation that counts the number of stage inputs with valid evaluations of the
55+
* provided [expression].
56+
*
57+
* @param expression The expression to count.
58+
* @return A new [AggregateFunction] representing the 'count' aggregation.
59+
*/
60+
@JvmStatic fun count(expression: Expr) = AggregateFunction("count", expression)
61+
62+
/**
63+
* Creates an aggregation that counts the number of stage inputs where the provided boolean
64+
* expression evaluates to true.
65+
*
66+
* @param condition The boolean expression to evaluate on each input.
67+
* @return A new [AggregateFunction] representing the count aggregation.
68+
*/
4469
@JvmStatic fun countIf(condition: BooleanExpr) = AggregateFunction("countIf", condition)
4570

71+
/**
72+
* Creates an aggregation that calculates the sum of a field's values across multiple stage
73+
* inputs.
74+
*
75+
* @param fieldName The name of the field containing numeric values to sum up.
76+
* @return A new [AggregateFunction] representing the average aggregation.
77+
*/
4678
@JvmStatic fun sum(fieldName: String) = AggregateFunction("sum", fieldName)
4779

48-
@JvmStatic fun sum(expr: Expr) = AggregateFunction("sum", expr)
49-
80+
/**
81+
* Creates an aggregation that calculates the sum of values from an expression across multiple
82+
* stage inputs.
83+
*
84+
* @param expression The expression to sum up.
85+
* @return A new [AggregateFunction] representing the sum aggregation.
86+
*/
87+
@JvmStatic fun sum(expression: Expr) = AggregateFunction("sum", expression)
88+
89+
/**
90+
* Creates an aggregation that calculates the average (mean) of a field's values across multiple
91+
* stage inputs.
92+
*
93+
* @param fieldName The name of the field containing numeric values to average.
94+
* @return A new [AggregateFunction] representing the average aggregation.
95+
*/
5096
@JvmStatic fun avg(fieldName: String) = AggregateFunction("avg", fieldName)
5197

52-
@JvmStatic fun avg(expr: Expr) = AggregateFunction("avg", expr)
53-
54-
@JvmStatic fun min(fieldName: String) = AggregateFunction("min", fieldName)
55-
56-
@JvmStatic fun min(expr: Expr) = AggregateFunction("min", expr)
57-
58-
@JvmStatic fun max(fieldName: String) = AggregateFunction("max", fieldName)
59-
60-
@JvmStatic fun max(expr: Expr) = AggregateFunction("max", expr)
98+
/**
99+
* Creates an aggregation that calculates the average (mean) of values from an expression across
100+
* multiple stage inputs.
101+
*
102+
* @param expression The expression representing the values to average.
103+
* @return A new [AggregateFunction] representing the average aggregation.
104+
*/
105+
@JvmStatic fun avg(expression: Expr) = AggregateFunction("avg", expression)
106+
107+
/**
108+
* Creates an aggregation that finds the minimum value of a field across multiple stage inputs.
109+
*
110+
* @param fieldName The name of the field to find the minimum value of.
111+
* @return A new [AggregateFunction] representing the minimum aggregation.
112+
*/
113+
@JvmStatic fun minimum(fieldName: String) = AggregateFunction("min", fieldName)
114+
115+
/**
116+
* Creates an aggregation that finds the minimum value of an expression across multiple stage
117+
* inputs.
118+
*
119+
* @param expression The expression to find the minimum value of.
120+
* @return A new [AggregateFunction] representing the minimum aggregation.
121+
*/
122+
@JvmStatic fun minimum(expression: Expr) = AggregateFunction("min", expression)
123+
124+
/**
125+
* Creates an aggregation that finds the maximum value of a field across multiple stage inputs.
126+
*
127+
* @param fieldName The name of the field to find the maximum value of.
128+
* @return A new [AggregateFunction] representing the maximum aggregation.
129+
*/
130+
@JvmStatic fun maximum(fieldName: String) = AggregateFunction("max", fieldName)
131+
132+
/**
133+
* Creates an aggregation that finds the maximum value of an expression across multiple stage
134+
* inputs.
135+
*
136+
* @param expression The expression to find the maximum value of.
137+
* @return A new [AggregateFunction] representing the maximum aggregation.
138+
*/
139+
@JvmStatic fun maximum(expression: Expr) = AggregateFunction("max", expression)
61140
}
62141

63142
/**

0 commit comments

Comments
 (0)