17
17
package com .google .cloud .firestore ;
18
18
19
19
import static com .google .cloud .firestore .pipeline .expressions .AggregateFunction .countAll ;
20
- import static com .google .cloud .firestore .pipeline .expressions .Expr .and ;
21
- import static com .google .cloud .firestore .pipeline .expressions .Expr .arrayContainsAny ;
22
- import static com .google .cloud .firestore .pipeline .expressions .Expr .eqAny ;
23
- import static com .google .cloud .firestore .pipeline .expressions .Expr .field ;
24
- import static com .google .cloud .firestore .pipeline .expressions .Expr .not ;
25
- import static com .google .cloud .firestore .pipeline .expressions .Expr .or ;
20
+ import static com .google .cloud .firestore .pipeline .expressions .Expression .and ;
21
+ import static com .google .cloud .firestore .pipeline .expressions .Expression .arrayContainsAny ;
22
+ import static com .google .cloud .firestore .pipeline .expressions .Expression .field ;
23
+ import static com .google .cloud .firestore .pipeline .expressions .Expression .not ;
24
+ import static com .google .cloud .firestore .pipeline .expressions .Expression .or ;
26
25
import static com .google .cloud .firestore .pipeline .expressions .FunctionUtils .aggregateFunctionToValue ;
27
26
import static com .google .cloud .firestore .pipeline .expressions .FunctionUtils .exprToValue ;
28
27
34
33
import com .google .cloud .firestore .Query .UnaryFilterInternal ;
35
34
import com .google .cloud .firestore .pipeline .expressions .AggregateFunction ;
36
35
import com .google .cloud .firestore .pipeline .expressions .AliasedAggregate ;
37
- import com .google .cloud .firestore .pipeline .expressions .AliasedExpr ;
38
- import com .google .cloud .firestore .pipeline .expressions .BooleanExpr ;
39
- import com .google .cloud .firestore .pipeline .expressions .Expr ;
36
+ import com .google .cloud .firestore .pipeline .expressions .AliasedExpression ;
37
+ import com .google .cloud .firestore .pipeline .expressions .BooleanExpression ;
38
+ import com .google .cloud .firestore .pipeline .expressions .Expression ;
40
39
import com .google .cloud .firestore .pipeline .expressions .Field ;
41
40
import com .google .cloud .firestore .pipeline .expressions .Selectable ;
42
41
import com .google .common .collect .Lists ;
@@ -56,7 +55,7 @@ public static Value encodeValue(Object value) {
56
55
}
57
56
58
57
@ InternalApi
59
- public static Value encodeValue (Expr value ) {
58
+ public static Value encodeValue (Expression value ) {
60
59
return exprToValue (value );
61
60
}
62
61
@@ -93,35 +92,36 @@ public static Value encodeValue(Map<String, Value> options) {
93
92
}
94
93
95
94
@ InternalApi
96
- static BooleanExpr toPipelineBooleanExpr (FilterInternal f ) {
95
+ static BooleanExpression toPipelineBooleanExpr (FilterInternal f ) {
97
96
if (f instanceof ComparisonFilterInternal ) {
98
97
ComparisonFilterInternal comparisonFilter = (ComparisonFilterInternal ) f ;
99
98
Field field = Field .ofServerPath (comparisonFilter .fieldReference .getFieldPath ());
100
99
Value value = comparisonFilter .value ;
101
100
switch (comparisonFilter .operator ) {
102
101
case LESS_THAN :
103
- return and (field .exists (), field .lt (value ));
102
+ return and (field .exists (), field .lessThan (value ));
104
103
case LESS_THAN_OR_EQUAL :
105
- return and (field .exists (), field .lte (value ));
104
+ return and (field .exists (), field .lessThanOrEqual (value ));
106
105
case GREATER_THAN :
107
- return and (field .exists (), field .gt (value ));
106
+ return and (field .exists (), field .greaterThan (value ));
108
107
case GREATER_THAN_OR_EQUAL :
109
- return and (field .exists (), field .gte (value ));
108
+ return and (field .exists (), field .greaterThanOrEqual (value ));
110
109
case EQUAL :
111
- return and (field .exists (), field .eq (value ));
110
+ return and (field .exists (), field .equal (value ));
112
111
case NOT_EQUAL :
113
- return and (field .exists (), not (field .eq (value )));
112
+ return and (field .exists (), not (field .equal (value )));
114
113
case ARRAY_CONTAINS :
115
114
return and (field .exists (), field .arrayContains (value ));
116
115
case IN :
117
116
List <Value > valuesList = value .getArrayValue ().getValuesList ();
118
- return and (field .exists (), eqAny (field , Lists .newArrayList (valuesList )));
117
+ return and (field .exists (), Expression . equalAny (field , Lists .newArrayList (valuesList )));
119
118
case ARRAY_CONTAINS_ANY :
120
119
List <Value > valuesListAny = value .getArrayValue ().getValuesList ();
121
120
return and (field .exists (), arrayContainsAny (field , Lists .newArrayList (valuesListAny )));
122
121
case NOT_IN :
123
122
List <Value > notInValues = value .getArrayValue ().getValuesList ();
124
- return and (field .exists (), not (eqAny (field , Lists .newArrayList (notInValues ))));
123
+ return and (
124
+ field .exists (), not (Expression .equalAny (field , Lists .newArrayList (notInValues ))));
125
125
default :
126
126
// Handle OPERATOR_UNSPECIFIED and UNRECOGNIZED cases as needed
127
127
throw new IllegalArgumentException ("Unsupported operator: " + comparisonFilter .operator );
@@ -130,21 +130,21 @@ static BooleanExpr toPipelineBooleanExpr(FilterInternal f) {
130
130
CompositeFilterInternal compositeFilter = (CompositeFilterInternal ) f ;
131
131
switch (compositeFilter .getOperator ()) {
132
132
case AND :
133
- List <BooleanExpr > conditions =
133
+ List <BooleanExpression > conditions =
134
134
compositeFilter .getFilters ().stream ()
135
135
.map (PipelineUtils ::toPipelineBooleanExpr )
136
136
.collect (Collectors .toList ());
137
137
return and (
138
138
conditions .get (0 ),
139
- conditions .subList (1 , conditions .size ()).toArray (new BooleanExpr [0 ]));
139
+ conditions .subList (1 , conditions .size ()).toArray (new BooleanExpression [0 ]));
140
140
case OR :
141
- List <BooleanExpr > orConditions =
141
+ List <BooleanExpression > orConditions =
142
142
compositeFilter .getFilters ().stream ()
143
143
.map (PipelineUtils ::toPipelineBooleanExpr )
144
144
.collect (Collectors .toList ());
145
145
return or (
146
146
orConditions .get (0 ),
147
- orConditions .subList (1 , orConditions .size ()).toArray (new BooleanExpr [0 ]));
147
+ orConditions .subList (1 , orConditions .size ()).toArray (new BooleanExpression [0 ]));
148
148
default :
149
149
// Handle OPERATOR_UNSPECIFIED and UNRECOGNIZED cases as needed
150
150
throw new IllegalArgumentException (
@@ -196,15 +196,15 @@ static AliasedAggregate toPipelineAggregatorTarget(AggregateField f) {
196
196
case "count" :
197
197
return countAll ().as (f .getAlias ());
198
198
case "average" :
199
- return Field .ofServerPath (fieldPath ).avg ().as (f .getAlias ());
199
+ return Field .ofServerPath (fieldPath ).average ().as (f .getAlias ());
200
200
default :
201
201
// Handle the 'else' case appropriately in your Java code
202
202
throw new IllegalArgumentException ("Unsupported operator: " + operator );
203
203
}
204
204
}
205
205
206
206
@ InternalApi
207
- static BooleanExpr toPipelineExistsExpr (AggregateField f ) {
207
+ static BooleanExpression toPipelineExistsExpr (AggregateField f ) {
208
208
String fieldPath = f .getFieldPath ();
209
209
210
210
if (fieldPath .isEmpty ()) {
@@ -214,23 +214,23 @@ static BooleanExpr toPipelineExistsExpr(AggregateField f) {
214
214
}
215
215
216
216
@ InternalApi
217
- public static Map <String , Expr > selectablesToMap (Selectable ... selectables ) {
218
- Map <String , Expr > projMap = new HashMap <>();
217
+ public static Map <String , Expression > selectablesToMap (Selectable ... selectables ) {
218
+ Map <String , Expression > projMap = new HashMap <>();
219
219
for (Selectable proj : selectables ) {
220
220
if (proj instanceof Field ) {
221
221
Field fieldProj = (Field ) proj ;
222
222
projMap .put (fieldProj .getPath ().getEncodedPath (), fieldProj );
223
- } else if (proj instanceof AliasedExpr ) {
224
- AliasedExpr aliasedExpr = (AliasedExpr ) proj ;
223
+ } else if (proj instanceof AliasedExpression ) {
224
+ AliasedExpression aliasedExpr = (AliasedExpression ) proj ;
225
225
projMap .put (aliasedExpr .getAlias (), aliasedExpr .getExpr ());
226
226
}
227
227
}
228
228
return projMap ;
229
229
}
230
230
231
231
@ InternalApi
232
- public static Map <String , Expr > fieldNamesToMap (String ... fields ) {
233
- Map <String , Expr > projMap = new HashMap <>();
232
+ public static Map <String , Expression > fieldNamesToMap (String ... fields ) {
233
+ Map <String , Expression > projMap = new HashMap <>();
234
234
for (String field : fields ) {
235
235
projMap .put (field , field (field ));
236
236
}
0 commit comments