Skip to content

Commit ab2aaab

Browse files
committed
add public docs
1 parent a5f852b commit ab2aaab

File tree

8 files changed

+1538
-144
lines changed

8 files changed

+1538
-144
lines changed

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

Lines changed: 506 additions & 37 deletions
Large diffs are not rendered by default.

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

Lines changed: 27 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,11 @@
3232
import javax.annotation.Nullable;
3333

3434
/**
35-
* A DocumentSnapshot contains data read from a document in a Firestore database. The data can be
36-
* extracted with the {@link #getData()} or {@link #get(String)} methods.
35+
* A PipelineResult contains data read from a Firestore Pipeline. The data can be extracted with the
36+
* {@link #getData()} or {@link #get(String)} methods.
3737
*
38-
* <p>If the DocumentSnapshot points to a non-existing document, getData() and its corresponding
39-
* methods will return null. You can always explicitly check for a document's existence by calling
40-
* {@link #exists()}.
38+
* <p>If the PipelineResult represents a non-document result, getReference() will return a null
39+
* value.
4140
*
4241
* <p><b>Subclassing Note</b>: Firestore classes are not meant to be subclassed except for use in
4342
* test mocks. Subclassing is not supported in production code and new SDK releases may break code
@@ -50,31 +49,30 @@ public final class PipelineResult {
5049
private final FirestoreRpcContext<?> rpcContext;
5150
@Nullable private final DocumentReference docRef;
5251
@Nullable private final Map<String, Value> fields;
53-
@Nullable private final Timestamp readTime;
52+
@Nonnull private final Timestamp executionTime;
5453
@Nullable private final Timestamp updateTime;
5554
@Nullable private final Timestamp createTime;
5655

5756
PipelineResult(
5857
FirestoreRpcContext<?> rpcContext,
5958
@Nullable DocumentReference docRef,
6059
@Nullable Map<String, Value> fields,
61-
@Nullable Timestamp readTime,
60+
@Nonnull Timestamp executionTime,
6261
@Nullable Timestamp updateTime,
6362
@Nullable Timestamp createTime) { // Elevated access level for mocking.
6463
this.rpcContext = rpcContext;
6564
this.docRef = docRef;
6665
this.fields = fields;
67-
this.readTime = readTime;
66+
this.executionTime = executionTime;
6867
this.updateTime = updateTime;
6968
this.createTime = createTime;
7069
}
7170

7271
/**
73-
* Returns the ID of the document contained in this snapshot.
74-
*
75-
* @return The id of the document.
72+
* Returns the ID of the document represented by this result. Returns null if this result is not
73+
* corresponding to a Firestore document.
7674
*/
77-
@Nonnull
75+
@Nullable
7876
@BetaApi
7977
public String getId() {
8078
return docRef.getId();
@@ -93,23 +91,16 @@ static PipelineResult fromDocument(
9391
Timestamp.fromProto(document.getCreateTime()));
9492
}
9593

96-
/**
97-
* Returns the time at which this snapshot was read.
98-
*
99-
* @return The read time of this snapshot.
100-
*/
94+
/** Returns the time at which the pipeline producing this result is executed. */
10195
@Nullable
10296
@BetaApi
103-
public Timestamp getReadTime() {
104-
return readTime;
97+
public Timestamp getExecutionTime() {
98+
return executionTime;
10599
}
106100

107101
/**
108-
* Returns the time at which this document was last updated. Returns null for non-existing
109-
* documents.
110-
*
111-
* @return The last time the document in the snapshot was updated. Null if the document doesn't
112-
* exist.
102+
* Returns the time at which this document was last updated. Returns null if this result is not
103+
* corresponding to a Firestore document.
113104
*/
114105
@Nullable
115106
@BetaApi
@@ -118,10 +109,8 @@ public Timestamp getUpdateTime() {
118109
}
119110

120111
/**
121-
* Returns the time at which this document was created. Returns null for non-existing documents.
122-
*
123-
* @return The last time the document in the snapshot was created. Null if the document doesn't
124-
* exist.
112+
* Returns the time at which this document was created. Returns null if this result is not
113+
* corresponding to a Firestore document.
125114
*/
126115
@Nullable
127116
@BetaApi
@@ -141,12 +130,12 @@ public boolean exists() {
141130
}
142131

143132
/**
144-
* Returns the fields of the document as a Map or null if the document doesn't exist. Field values
133+
* Returns the fields of the result as a Map or null if the result doesn't exist. Field values
145134
* will be converted to their native Java representation.
146135
*
147-
* @return The fields of the document as a Map or null if the document doesn't exist.
136+
* @return The fields of the document as a Map or null if the result doesn't exist.
148137
*/
149-
@Nullable
138+
@Nonnull
150139
@BetaApi
151140
public Map<String, Object> getData() {
152141
if (fields == null) {
@@ -162,10 +151,10 @@ public Map<String, Object> getData() {
162151
}
163152

164153
/**
165-
* Returns the contents of the document converted to a POJO or null if the document doesn't exist.
154+
* Returns the contents of the document converted to a POJO or null if the result doesn't exist.
166155
*
167156
* @param valueType The Java class to create
168-
* @return The contents of the document in an object of type T or null if the document doesn't
157+
* @return The contents of the document in an object of type T or null if the result doesn't
169158
* exist.
170159
*/
171160
@Nullable
@@ -176,7 +165,7 @@ public <T> T toObject(@Nonnull Class<T> valueType) {
176165
}
177166

178167
/**
179-
* Returns whether or not the field exists in the document. Returns false if the document does not
168+
* Returns whether or not the field exists in the document. Returns false if the result does not
180169
* exist.
181170
*
182171
* @param field the path to the field.
@@ -188,7 +177,7 @@ public boolean contains(@Nonnull String field) {
188177
}
189178

190179
/**
191-
* Returns whether or not the field exists in the document. Returns false if the document does not
180+
* Returns whether or not the field exists in the document. Returns false if the result does not
192181
* exist.
193182
*
194183
* @param fieldPath the path to the field.
@@ -212,7 +201,7 @@ public Object get(@Nonnull String field) {
212201
}
213202

214203
/**
215-
* Returns the value at the field, converted to a POJO, or null if the field or document doesn't
204+
* Returns the value at the field, converted to a POJO, or null if the field or result doesn't
216205
* exist.
217206
*
218207
* @param field The path to the field
@@ -244,7 +233,7 @@ public Object get(@Nonnull FieldPath fieldPath) {
244233
}
245234

246235
/**
247-
* Returns the value at the field, converted to a POJO, or null if the field or document doesn't
236+
* Returns the value at the field, converted to a POJO, or null if the field or result doesn't
248237
* exist.
249238
*
250239
* @param fieldPath The path to the field
@@ -390,7 +379,6 @@ public GeoPoint getGeoPoint(@Nonnull String field) {
390379
*
391380
* @return The reference to the document.
392381
*/
393-
@Nonnull
394382
@BetaApi
395383
public DocumentReference getReference() {
396384
return docRef;
@@ -455,6 +443,6 @@ public int hashCode() {
455443
public String toString() {
456444
return String.format(
457445
"%s{doc=%s, fields=%s, readTime=%s, updateTime=%s, createTime=%s}",
458-
getClass().getSimpleName(), docRef, fields, readTime, updateTime, createTime);
446+
getClass().getSimpleName(), docRef, fields, executionTime, updateTime, createTime);
459447
}
460448
}

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,25 @@
99
import com.google.common.base.Preconditions;
1010
import javax.annotation.Nonnull;
1111

12+
/**
13+
* A factory for creating {@link Pipeline} instances, which provide a framework for building data
14+
* transformation and query pipelines for Firestore.
15+
*
16+
* <p>Start by calling {@link Firestore#pipeline()} to obtain an instance of {@code PipelineSource}.
17+
* From there, you can use the provided methods (like {@link #collection(String)}) to specify the
18+
* data source for your pipeline.
19+
*
20+
* <p>This class is typically used to start building Firestore pipelines. It allows you to define
21+
* the initial data source for a pipeline.
22+
*
23+
* <p>Example Usage:
24+
*
25+
* <pre>{@code
26+
* firestore.pipeline() // Get a PipelineSource instance
27+
* .collection("users") // Create a pipeline that operates on a collection
28+
* .select("name"); // Add stages to the pipeline
29+
* }</pre>
30+
*/
1231
@BetaApi
1332
public class PipelineSource {
1433
private final Firestore db;
@@ -18,12 +37,28 @@ public class PipelineSource {
1837
this.db = db;
1938
}
2039

40+
/**
41+
* Creates a new {@link Pipeline} that operates on the specified Firestore collection.
42+
*
43+
* @param path The path to the Firestore collection (e.g., "users").
44+
* @return A new {@code Pipeline} instance targeting the specified collection.
45+
*/
2146
@Nonnull
2247
@BetaApi
2348
public Pipeline collection(@Nonnull String path) {
2449
return new Pipeline(this.db, new Collection(path));
2550
}
2651

52+
/**
53+
* Creates a new {@link Pipeline} that operates on all documents in a collection group.
54+
*
55+
* <p>A collection group consists of all collections with the same ID. For example, if you have
56+
* collections named "users" under different documents, you can query them together using a
57+
* collection group query.
58+
*
59+
* @param collectionId The ID of the collection group.
60+
* @return A new {@code Pipeline} instance targeting the specified collection group.
61+
*/
2762
@Nonnull
2863
@BetaApi
2964
public Pipeline collectionGroup(@Nonnull String collectionId) {
@@ -34,12 +69,27 @@ public Pipeline collectionGroup(@Nonnull String collectionId) {
3469
return new Pipeline(this.db, new CollectionGroup(collectionId));
3570
}
3671

72+
/**
73+
* Creates a new {@link Pipeline} that operates on all documents in the Firestore database.
74+
*
75+
* <p>Use this method with caution as it can lead to very large result sets. It is usually only
76+
* useful at development stage.
77+
*
78+
* @return A new {@code Pipeline} instance targeting all documents in the database.
79+
*/
3780
@Nonnull
3881
@BetaApi
3982
public Pipeline database() {
4083
return new Pipeline(this.db, new Database());
4184
}
4285

86+
/**
87+
* Creates a new {@link Pipeline} that operates on a specific set of Firestore documents.
88+
*
89+
* @param docs The {@link DocumentReference} instances representing the documents to include in
90+
* the pipeline.
91+
* @return A new {@code Pipeline} instance targeting the specified documents.
92+
*/
4393
@Nonnull
4494
@BetaApi
4595
public Pipeline documents(DocumentReference... docs) {

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

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import com.google.cloud.firestore.Query.FilterInternal;
1414
import com.google.cloud.firestore.Query.LimitType;
1515
import com.google.cloud.firestore.Query.UnaryFilterInternal;
16-
import com.google.cloud.firestore.pipeline.PaginatingPipeline;
1716
import com.google.cloud.firestore.pipeline.expressions.Accumulator;
1817
import com.google.cloud.firestore.pipeline.expressions.AccumulatorTarget;
1918
import com.google.cloud.firestore.pipeline.expressions.Expr;
@@ -125,37 +124,8 @@ static Pipeline toPaginatedPipeline(
125124
Integer limit,
126125
LimitType limitType,
127126
Integer offset) {
128-
129-
// Handle null limit, setting a default maximum
130-
int effectiveLimit = (limit != null) ? limit : Integer.MAX_VALUE;
131-
132-
PaginatingPipeline paginate = pipeline.paginate(effectiveLimit);
133-
134-
// Apply start and end cursors if present
135-
if (start != null) {
136-
paginate = paginate.withStartCursor(start);
137-
}
138-
if (end != null) {
139-
paginate = paginate.withEndCursor(end);
140-
}
141-
if (offset != null) {
142-
paginate = paginate.offset(offset);
143-
}
144-
145-
// Handle limitType, defaulting to firstPage
146-
if (limitType != null) {
147-
switch (limitType) {
148-
case First:
149-
return paginate.firstPage();
150-
case Last:
151-
return paginate.lastPage();
152-
default:
153-
// Handle other LimitType cases as needed, or throw an exception
154-
throw new IllegalArgumentException("Unsupported limit type: " + limitType);
155-
}
156-
} else {
157-
return paginate.firstPage();
158-
}
127+
throw new UnsupportedOperationException(
128+
"Converting to pagination pipeline is not support yet.");
159129
}
160130

161131
@InternalApi

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2170,11 +2170,9 @@ public Pipeline pipeline() {
21702170
normalizedOrderbys.stream()
21712171
.map(
21722172
fieldOrder ->
2173-
Ordering.of(
2174-
Field.of(fieldOrder.fieldReference.getFieldPath()),
2175-
fieldOrder.direction == Direction.ASCENDING
2176-
? Ordering.Direction.ASCENDING
2177-
: Ordering.Direction.DESCENDING))
2173+
fieldOrder.direction == Direction.ASCENDING
2174+
? Field.of(fieldOrder.fieldReference.getFieldPath()).ascending()
2175+
: Field.of(fieldOrder.fieldReference.getFieldPath()).descending())
21782176
.collect(Collectors.toList());
21792177
ppl = ppl.sort(orders, Density.REQUIRED, Truncation.UNSPECIFIED);
21802178
}

0 commit comments

Comments
 (0)