Skip to content

Commit f97c8c2

Browse files
committed
API refinement
1 parent b832d08 commit f97c8c2

28 files changed

+1489
-1455
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: 46 additions & 41 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.field;
19+
import static com.google.cloud.firestore.pipeline.expressions.Expression.field;
2020

2121
import com.google.api.core.ApiFuture;
2222
import com.google.api.core.BetaApi;
@@ -27,11 +27,13 @@
2727
import com.google.api.gax.rpc.ResponseObserver;
2828
import com.google.api.gax.rpc.StreamController;
2929
import com.google.cloud.Timestamp;
30+
import com.google.cloud.firestore.pipeline.expressions.AggregateFunction;
3031
import com.google.cloud.firestore.pipeline.expressions.AliasedAggregate;
31-
import com.google.cloud.firestore.pipeline.expressions.AliasedExpr;
32-
import com.google.cloud.firestore.pipeline.expressions.BooleanExpr;
33-
import com.google.cloud.firestore.pipeline.expressions.Expr;
32+
import com.google.cloud.firestore.pipeline.expressions.AliasedExpression;
33+
import com.google.cloud.firestore.pipeline.expressions.BooleanExpression;
34+
import com.google.cloud.firestore.pipeline.expressions.Expression;
3435
import com.google.cloud.firestore.pipeline.expressions.Field;
36+
import com.google.cloud.firestore.pipeline.expressions.FunctionExpression;
3537
import com.google.cloud.firestore.pipeline.expressions.Ordering;
3638
import com.google.cloud.firestore.pipeline.expressions.Selectable;
3739
import com.google.cloud.firestore.pipeline.stages.AddFields;
@@ -97,14 +99,14 @@
9799
* Firestore firestore; // A valid firestore instance.
98100
*
99101
* // Example 1: Select specific fields and rename 'rating' to 'bookRating'
100-
* List<PipelineResult> results1 = firestore.pipeline()
102+
* PipelineSnapshot results1 = firestore.pipeline()
101103
* .collection("books")
102-
* .select("title", "author", field("rating").as("bookRating"))
104+
* .select(field("title"), field("author"), field("rating").as("bookRating"))
103105
* .execute()
104106
* .get();
105107
*
106108
* // Example 2: Filter documents where 'genre' is "Science Fiction" and 'published' is after 1950
107-
* List<PipelineResult> results2 = firestore.pipeline()
109+
* PipelineSnapshot results2 = firestore.pipeline()
108110
* .collection("books")
109111
* .where(and(eq("genre", "Science Fiction"), gt("published", 1950)))
110112
* .execute()
@@ -117,7 +119,7 @@
117119
* .get();
118120
*
119121
* // Example 3: Calculate the average rating of books published after 1980
120-
* List<PipelineResult> results3 = firestore.pipeline()
122+
* PipelineSnapshot results3 = firestore.pipeline()
121123
* .collection("books")
122124
* .where(gt("published", 1980))
123125
* .aggregate(avg("rating").as("averageRating"))
@@ -156,9 +158,8 @@ private Pipeline append(Stage stage) {
156158
*
157159
* <ul>
158160
* <li>{@link Field}: References an existing document field.
159-
* <li>{@link Function}: Performs a calculation using functions like `add`, `multiply` with
160-
* assigned aliases using {@link
161-
* com.google.cloud.firestore.pipeline.expressions.Expr#as(String)}.
161+
* <li>{@link FunctionExpression}: Performs a calculation using functions like `add`, `multiply`
162+
* with assigned aliases using {@link Expression#as(String)}.
162163
* </ul>
163164
*
164165
* <p>Example:
@@ -232,8 +233,8 @@ public Pipeline removeFields(Field... fields) {
232233
*
233234
* <ul>
234235
* <li>{@link Field}: References an existing document field.
235-
* <li>{@link Function}: Represents the result of a function with an assigned alias name using
236-
* {@link com.google.cloud.firestore.pipeline.expressions.Expr#as(String)}
236+
* <li>{@link FunctionExpression}: Represents the result of a function with an assigned alias
237+
* name using {@link Expression#as(String)}
237238
* </ul>
238239
*
239240
* <p>If no selections are provided, the output of this stage is empty. Use {@link
@@ -287,18 +288,19 @@ public Pipeline select(String... fields) {
287288

288289
/**
289290
* Filters the documents from previous stages to only include those matching the specified {@link
290-
* FilterCondition}.
291+
* BooleanExpression}.
291292
*
292293
* <p>This stage allows you to apply conditions to the data, similar to a "WHERE" clause in SQL.
293294
* You can filter documents based on their field values, using implementions of {@link
294-
* FilterCondition}, typically including but not limited to:
295+
* BooleanExpression}, typically including but not limited to:
295296
*
296297
* <ul>
297-
* <li>field comparators: {@link Function#eq}, {@link Function#lt} (less than), {@link
298-
* Function#gt} (greater than), etc.
299-
* <li>logical operators: {@link Function#and}, {@link Function#or}, {@link Function#not}, etc.
300-
* <li>advanced functions: {@link Function#regexMatch(String, String)}, {@link
301-
* Function#arrayContains(Expr, Expr)}, etc.
298+
* <li>field comparators: {@link FunctionExpression#equal}, {@link FunctionExpression#lessThan}
299+
* (less than), {@link FunctionExpression#greaterThan} (greater than), etc.
300+
* <li>logical operators: {@link FunctionExpression#and}, {@link FunctionExpression#or}, {@link
301+
* FunctionExpression#not}, etc.
302+
* <li>advanced functions: {@link FunctionExpression#regexMatch(String, String)}, {@link
303+
* FunctionExpression#arrayContains(Expression, Expression)}, etc.
302304
* </ul>
303305
*
304306
* <p>Example:
@@ -308,16 +310,16 @@ public Pipeline select(String... fields) {
308310
* .where(
309311
* and(
310312
* gt("rating", 4.0), // Filter for ratings greater than 4.0
311-
* field("genre").eq("Science Fiction") // Equivalent to gt("genre", "Science Fiction")
313+
* field("genre").eq("Science Fiction") // Equivalent to eq("genre", "Science Fiction")
312314
* )
313315
* );
314316
* }</pre>
315317
*
316-
* @param condition The {@link FilterCondition} to apply.
318+
* @param condition The {@link BooleanExpression} to apply.
317319
* @return A new Pipeline object with this stage appended to the stage list.
318320
*/
319321
@BetaApi
320-
public Pipeline where(BooleanExpr condition) {
322+
public Pipeline where(BooleanExpression condition) {
321323
return append(new Where(condition));
322324
}
323325

@@ -380,8 +382,8 @@ public Pipeline limit(int limit) {
380382
* Performs aggregation operations on the documents from previous stages.
381383
*
382384
* <p>This stage allows you to calculate aggregate values over a set of documents. You define the
383-
* aggregations to perform using {@link AliasedExpr} expressions which are typically results of
384-
* calling {@link Expr#as(String)} on {@link Accumulator} instances.
385+
* aggregations to perform using {@link AliasedExpression} expressions which are typically results
386+
* of calling {@link Expression#as(String)} on {@link AggregateFunction} instances.
385387
*
386388
* <p>Example:
387389
*
@@ -394,8 +396,8 @@ public Pipeline limit(int limit) {
394396
* );
395397
* }</pre>
396398
*
397-
* @param accumulators The {@link AliasedExpr} expressions, each wrapping an {@link Accumulator}
398-
* and provide a name for the accumulated results.
399+
* @param accumulators The {@link AliasedExpression} expressions, each wrapping an {@link
400+
* AggregateFunction} and provide a name for the accumulated results.
399401
* @return A new Pipeline object with this stage appended to the stage list.
400402
*/
401403
@BetaApi
@@ -415,9 +417,10 @@ public Pipeline aggregate(AliasedAggregate... accumulators) {
415417
* If no grouping fields are provided, a single group containing all documents is used. Not
416418
* specifying groups is the same as putting the entire inputs into one group.
417419
* <li>**Accumulators:** One or more accumulation operations to perform within each group. These
418-
* are defined using {@link AliasedExpr} expressions, which are typically created by calling
419-
* {@link Expr#as(String)} on {@link Accumulator} instances. Each aggregation calculates a
420-
* value (e.g., sum, average, count) based on the documents within its group.
420+
* are defined using {@link AliasedExpression} expressions, which are typically created by
421+
* calling {@link Expression#as(String)} on {@link AggregateFunction} instances. Each
422+
* aggregation calculates a value (e.g., sum, average, count) based on the documents within
423+
* its group.
421424
* </ul>
422425
*
423426
* <p>Example:
@@ -468,17 +471,17 @@ public Pipeline distinct(String... fields) {
468471
}
469472

470473
/**
471-
* Returns a set of distinct {@link Expr} values from the inputs to this stage.
474+
* Returns a set of distinct {@link Expression} values from the inputs to this stage.
472475
*
473476
* <p>This stage run through the results from previous stages to include only results with unique
474-
* combinations of {@link Expr} values ({@link Field}, {@link Function}, etc).
477+
* combinations of {@link Expression} values ({@link Field}, {@link FunctionExpression}, etc).
475478
*
476479
* <p>The parameters to this stage are defined using {@link Selectable} expressions, which can be:
477480
*
478481
* <ul>
479482
* <li>{@link Field}: References an existing document field.
480-
* <li>{@link Function}: Represents the result of a function with an assigned alias name using
481-
* {@link com.google.cloud.firestore.pipeline.expressions.Expr#as(String)}
483+
* <li>{@link FunctionExpression}: Represents the result of a function with an assigned alias
484+
* name using {@link Expression#as(String)}
482485
* </ul>
483486
*
484487
* <p>Example:
@@ -548,7 +551,9 @@ public Pipeline findNearest(
548551
* // Find books with similar "topicVectors" to the given targetVector
549552
* firestore.pipeline().collection("books")
550553
* .findNearest(
551-
* FindNearest.of(field("topicVectors"), targetVector, FindNearest.DistanceMeasure.COSINE),
554+
* field("topicVectors"),
555+
* targetVector,
556+
* FindNearest.DistanceMeasure.COSINE,
552557
* new FindNearestOptions()
553558
* .withLimit(10)
554559
* .withDistanceField("distance"));
@@ -563,7 +568,7 @@ public Pipeline findNearest(
563568
*/
564569
@BetaApi
565570
public Pipeline findNearest(
566-
Expr property,
571+
Expression property,
567572
double[] vector,
568573
FindNearest.DistanceMeasure distanceMeasure,
569574
FindNearestOptions options) {
@@ -617,7 +622,7 @@ public Pipeline sort(Ordering... orders) {
617622
* // }
618623
*
619624
* // Emit parents as document.
620-
* firestore.pipeline().collection("people").replace("parents");
625+
* firestore.pipeline().collection("people").replaceWith("parents");
621626
*
622627
* // Output
623628
* // {
@@ -652,7 +657,7 @@ public Pipeline replaceWith(String fieldName) {
652657
* // }
653658
*
654659
* // Emit parents as document.
655-
* firestore.pipeline().collection("people").replace(field("parents"));
660+
* firestore.pipeline().collection("people").replaceWith(field("parents"));
656661
*
657662
* // Output
658663
* // {
@@ -665,7 +670,7 @@ public Pipeline replaceWith(String fieldName) {
665670
* @return A new {@code Pipeline} object with this stage appended to the stage list.
666671
*/
667672
@BetaApi
668-
public Pipeline replaceWith(Expr expr) {
673+
public Pipeline replaceWith(Expression expr) {
669674
return append(new ReplaceWith(expr));
670675
}
671676

@@ -979,7 +984,7 @@ public Pipeline genericStage(String name, List<Object> params, GenericOptions op
979984
* <p>Example:
980985
*
981986
* <pre>{@code
982-
* ApiFuture<List<PipelineResult>> futureResults = firestore.pipeline().collection("books")
987+
* ApiFuture<PipelineSnapshot> futureResults = firestore.pipeline().collection("books")
983988
* .where(gt("rating", 4.5))
984989
* .select("title", "author", "rating")
985990
* .execute();
@@ -1228,7 +1233,7 @@ public void onComplete() {
12281233
}
12291234
};
12301235

1231-
logger.log(Level.INFO, "Sending pipeline request: " + request.getStructuredPipeline());
1236+
logger.log(Level.FINEST, "Sending pipeline request: " + request.getStructuredPipeline());
12321237

12331238
rpcContext.streamRequest(request, observer, rpcContext.getClient().executePipelineCallable());
12341239
}

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

Lines changed: 2 additions & 2 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;

0 commit comments

Comments
 (0)