Skip to content

Commit ccaf9d4

Browse files
committed
API refinement
1 parent b832d08 commit ccaf9d4

37 files changed

+2402
-2022
lines changed

google-cloud-firestore/src/main/java/com/google/cloud/firestore/AggregateQuery.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.google.cloud.firestore;
1818

19-
import static com.google.cloud.firestore.pipeline.expressions.Expr.and;
19+
import static com.google.cloud.firestore.pipeline.expressions.Expression.and;
2020
import static com.google.cloud.firestore.telemetry.TraceUtil.ATTRIBUTE_KEY_ATTEMPT;
2121
import static com.google.cloud.firestore.telemetry.TraceUtil.SPAN_NAME_RUN_AGGREGATION_QUERY;
2222

@@ -29,7 +29,7 @@
2929
import com.google.api.gax.rpc.StreamController;
3030
import com.google.cloud.Timestamp;
3131
import com.google.cloud.firestore.pipeline.expressions.AliasedAggregate;
32-
import com.google.cloud.firestore.pipeline.expressions.BooleanExpr;
32+
import com.google.cloud.firestore.pipeline.expressions.BooleanExpression;
3333
import com.google.cloud.firestore.telemetry.TraceUtil;
3434
import com.google.cloud.firestore.telemetry.TraceUtil.Scope;
3535
import com.google.cloud.firestore.v1.FirestoreSettings;
@@ -83,7 +83,7 @@ public Query getQuery() {
8383
Pipeline pipeline() {
8484
Pipeline pipeline = getQuery().pipeline();
8585

86-
List<BooleanExpr> existsExprs =
86+
List<BooleanExpression> existsExprs =
8787
this.aggregateFieldList.stream()
8888
.map(PipelineUtils::toPipelineExistsExpr)
8989
.filter(Objects::nonNull)
@@ -95,7 +95,7 @@ Pipeline pipeline() {
9595
pipeline.where(
9696
and(
9797
existsExprs.get(0),
98-
existsExprs.subList(1, existsExprs.size()).toArray(new BooleanExpr[0])));
98+
existsExprs.subList(1, existsExprs.size()).toArray(new BooleanExpression[0])));
9999
}
100100

101101
return pipeline.aggregate(

google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java

Lines changed: 122 additions & 59 deletions
Large diffs are not rendered by default.

google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ public final class PipelineResult {
6464
this.docRef = docRef;
6565
this.fields = fields;
6666
this.executionTime = executionTime;
67-
if(updateTime != null && updateTime.equals(Timestamp.ofTimeMicroseconds(0))) {
67+
if (updateTime != null && updateTime.equals(Timestamp.ofTimeMicroseconds(0))) {
6868
updateTime = null;
6969
}
7070
this.updateTime = updateTime;
7171

72-
if(createTime != null && createTime.equals(Timestamp.ofTimeMicroseconds(0))) {
72+
if (createTime != null && createTime.equals(Timestamp.ofTimeMicroseconds(0))) {
7373
createTime = null;
7474
}
7575
this.createTime = createTime;
@@ -166,7 +166,7 @@ public Map<String, Object> getData() {
166166
*/
167167
@Nullable
168168
@BetaApi
169-
public <T> T toObject(@Nonnull Class<T> valueType) {
169+
<T> T toObject(@Nonnull Class<T> valueType) {
170170
Map<String, Object> data = getData();
171171
return data == null ? null : CustomClassMapper.convertToCustomClass(data, valueType, docRef);
172172
}

google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineSnapshot.java

Lines changed: 0 additions & 89 deletions
This file was deleted.

google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.java

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@
1717
package com.google.cloud.firestore;
1818

1919
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;
2625
import static com.google.cloud.firestore.pipeline.expressions.FunctionUtils.aggregateFunctionToValue;
2726
import static com.google.cloud.firestore.pipeline.expressions.FunctionUtils.exprToValue;
2827

@@ -34,9 +33,9 @@
3433
import com.google.cloud.firestore.Query.UnaryFilterInternal;
3534
import com.google.cloud.firestore.pipeline.expressions.AggregateFunction;
3635
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;
4039
import com.google.cloud.firestore.pipeline.expressions.Field;
4140
import com.google.cloud.firestore.pipeline.expressions.Selectable;
4241
import com.google.common.collect.Lists;
@@ -56,7 +55,7 @@ public static Value encodeValue(Object value) {
5655
}
5756

5857
@InternalApi
59-
public static Value encodeValue(Expr value) {
58+
public static Value encodeValue(Expression value) {
6059
return exprToValue(value);
6160
}
6261

@@ -93,35 +92,36 @@ public static Value encodeValue(Map<String, Value> options) {
9392
}
9493

9594
@InternalApi
96-
static BooleanExpr toPipelineBooleanExpr(FilterInternal f) {
95+
static BooleanExpression toPipelineBooleanExpr(FilterInternal f) {
9796
if (f instanceof ComparisonFilterInternal) {
9897
ComparisonFilterInternal comparisonFilter = (ComparisonFilterInternal) f;
9998
Field field = Field.ofServerPath(comparisonFilter.fieldReference.getFieldPath());
10099
Value value = comparisonFilter.value;
101100
switch (comparisonFilter.operator) {
102101
case LESS_THAN:
103-
return and(field.exists(), field.lt(value));
102+
return and(field.exists(), field.lessThan(value));
104103
case LESS_THAN_OR_EQUAL:
105-
return and(field.exists(), field.lte(value));
104+
return and(field.exists(), field.lessThanOrEqual(value));
106105
case GREATER_THAN:
107-
return and(field.exists(), field.gt(value));
106+
return and(field.exists(), field.greaterThan(value));
108107
case GREATER_THAN_OR_EQUAL:
109-
return and(field.exists(), field.gte(value));
108+
return and(field.exists(), field.greaterThanOrEqual(value));
110109
case EQUAL:
111-
return and(field.exists(), field.eq(value));
110+
return and(field.exists(), field.equal(value));
112111
case NOT_EQUAL:
113-
return and(field.exists(), not(field.eq(value)));
112+
return and(field.exists(), not(field.equal(value)));
114113
case ARRAY_CONTAINS:
115114
return and(field.exists(), field.arrayContains(value));
116115
case IN:
117116
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)));
119118
case ARRAY_CONTAINS_ANY:
120119
List<Value> valuesListAny = value.getArrayValue().getValuesList();
121120
return and(field.exists(), arrayContainsAny(field, Lists.newArrayList(valuesListAny)));
122121
case NOT_IN:
123122
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))));
125125
default:
126126
// Handle OPERATOR_UNSPECIFIED and UNRECOGNIZED cases as needed
127127
throw new IllegalArgumentException("Unsupported operator: " + comparisonFilter.operator);
@@ -130,21 +130,21 @@ static BooleanExpr toPipelineBooleanExpr(FilterInternal f) {
130130
CompositeFilterInternal compositeFilter = (CompositeFilterInternal) f;
131131
switch (compositeFilter.getOperator()) {
132132
case AND:
133-
List<BooleanExpr> conditions =
133+
List<BooleanExpression> conditions =
134134
compositeFilter.getFilters().stream()
135135
.map(PipelineUtils::toPipelineBooleanExpr)
136136
.collect(Collectors.toList());
137137
return and(
138138
conditions.get(0),
139-
conditions.subList(1, conditions.size()).toArray(new BooleanExpr[0]));
139+
conditions.subList(1, conditions.size()).toArray(new BooleanExpression[0]));
140140
case OR:
141-
List<BooleanExpr> orConditions =
141+
List<BooleanExpression> orConditions =
142142
compositeFilter.getFilters().stream()
143143
.map(PipelineUtils::toPipelineBooleanExpr)
144144
.collect(Collectors.toList());
145145
return or(
146146
orConditions.get(0),
147-
orConditions.subList(1, orConditions.size()).toArray(new BooleanExpr[0]));
147+
orConditions.subList(1, orConditions.size()).toArray(new BooleanExpression[0]));
148148
default:
149149
// Handle OPERATOR_UNSPECIFIED and UNRECOGNIZED cases as needed
150150
throw new IllegalArgumentException(
@@ -196,15 +196,15 @@ static AliasedAggregate toPipelineAggregatorTarget(AggregateField f) {
196196
case "count":
197197
return countAll().as(f.getAlias());
198198
case "average":
199-
return Field.ofServerPath(fieldPath).avg().as(f.getAlias());
199+
return Field.ofServerPath(fieldPath).average().as(f.getAlias());
200200
default:
201201
// Handle the 'else' case appropriately in your Java code
202202
throw new IllegalArgumentException("Unsupported operator: " + operator);
203203
}
204204
}
205205

206206
@InternalApi
207-
static BooleanExpr toPipelineExistsExpr(AggregateField f) {
207+
static BooleanExpression toPipelineExistsExpr(AggregateField f) {
208208
String fieldPath = f.getFieldPath();
209209

210210
if (fieldPath.isEmpty()) {
@@ -214,23 +214,23 @@ static BooleanExpr toPipelineExistsExpr(AggregateField f) {
214214
}
215215

216216
@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<>();
219219
for (Selectable proj : selectables) {
220220
if (proj instanceof Field) {
221221
Field fieldProj = (Field) proj;
222222
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;
225225
projMap.put(aliasedExpr.getAlias(), aliasedExpr.getExpr());
226226
}
227227
}
228228
return projMap;
229229
}
230230

231231
@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<>();
234234
for (String field : fields) {
235235
projMap.put(field, field(field));
236236
}

google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717
package com.google.cloud.firestore;
1818

1919
import static com.google.cloud.firestore.PipelineUtils.toPipelineBooleanExpr;
20-
import static com.google.cloud.firestore.pipeline.expressions.Expr.and;
21-
import static com.google.cloud.firestore.pipeline.expressions.Expr.eq;
22-
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.or;
2322
import static com.google.cloud.firestore.telemetry.TraceUtil.*;
2423
import static com.google.common.collect.Lists.reverse;
2524
import static com.google.firestore.v1.StructuredQuery.FieldFilter.Operator.ARRAY_CONTAINS;
@@ -43,7 +42,8 @@
4342
import com.google.auto.value.AutoValue;
4443
import com.google.cloud.Timestamp;
4544
import com.google.cloud.firestore.Query.QueryOptions.Builder;
46-
import com.google.cloud.firestore.pipeline.expressions.BooleanExpr;
45+
import com.google.cloud.firestore.pipeline.expressions.BooleanExpression;
46+
import com.google.cloud.firestore.pipeline.expressions.Expression;
4747
import com.google.cloud.firestore.pipeline.expressions.Field;
4848
import com.google.cloud.firestore.pipeline.expressions.Ordering;
4949
import com.google.cloud.firestore.pipeline.expressions.Selectable;
@@ -2190,7 +2190,7 @@ Pipeline pipeline() {
21902190
fields.get(0).exists(),
21912191
fields.subList(1, fields.size()).stream()
21922192
.map((Field field) -> field.exists())
2193-
.toArray(BooleanExpr[]::new)));
2193+
.toArray(BooleanExpression[]::new)));
21942194
}
21952195

21962196
// Cursors, Limit, Offset
@@ -2236,17 +2236,17 @@ private static Ordering reverseOrdering(Ordering ordering) {
22362236
}
22372237
}
22382238

2239-
private static BooleanExpr getCursorExclusiveCondition(
2239+
private static BooleanExpression getCursorExclusiveCondition(
22402240
boolean isStart, Ordering ordering, Value value) {
22412241
if (isStart && ordering.getDir() == Ordering.Direction.ASCENDING
22422242
|| !isStart && ordering.getDir() == Ordering.Direction.DESCENDING) {
2243-
return ordering.getExpr().gt(value);
2243+
return ordering.getExpr().greaterThan(value);
22442244
} else {
2245-
return ordering.getExpr().lt(value);
2245+
return ordering.getExpr().lessThan(value);
22462246
}
22472247
}
22482248

2249-
private static BooleanExpr whereConditionsFromCursor(
2249+
private static BooleanExpression whereConditionsFromCursor(
22502250
Cursor bound, List<Ordering> orderings, boolean isStart) {
22512251
List<Value> boundPosition = bound.getValuesList();
22522252
int size = boundPosition.size();
@@ -2255,18 +2255,19 @@ private static BooleanExpr whereConditionsFromCursor(
22552255
}
22562256

22572257
int last = size - 1;
2258-
BooleanExpr condition =
2258+
BooleanExpression condition =
22592259
getCursorExclusiveCondition(isStart, orderings.get(last), boundPosition.get(last));
22602260
if (isBoundInclusive(bound, isStart)) {
2261-
condition = or(condition, eq(orderings.get(last).getExpr(), boundPosition.get(last)));
2261+
condition =
2262+
or(condition, Expression.equal(orderings.get(last).getExpr(), boundPosition.get(last)));
22622263
}
22632264
for (int i = size - 2; i >= 0; i--) {
22642265
final Ordering ordering = orderings.get(i);
22652266
final Value value = boundPosition.get(i);
22662267
condition =
22672268
or(
22682269
getCursorExclusiveCondition(isStart, ordering, value),
2269-
and(ordering.getExpr().eq(value), condition));
2270+
and(ordering.getExpr().equal(value), condition));
22702271
}
22712272
return condition;
22722273
}

0 commit comments

Comments
 (0)