|
43 | 43 | import com.google.cloud.firestore.pipeline.stages.Aggregate; |
44 | 44 | import com.google.cloud.firestore.pipeline.stages.AggregateOptions; |
45 | 45 | import com.google.cloud.firestore.pipeline.stages.Define; |
| 46 | +import com.google.cloud.firestore.pipeline.stages.Delete; |
46 | 47 | import com.google.cloud.firestore.pipeline.stages.Distinct; |
47 | 48 | import com.google.cloud.firestore.pipeline.stages.FindNearest; |
48 | 49 | import com.google.cloud.firestore.pipeline.stages.FindNearestOptions; |
|
60 | 61 | import com.google.cloud.firestore.pipeline.stages.Union; |
61 | 62 | import com.google.cloud.firestore.pipeline.stages.Unnest; |
62 | 63 | import com.google.cloud.firestore.pipeline.stages.UnnestOptions; |
| 64 | +import com.google.cloud.firestore.pipeline.stages.Update; |
63 | 65 | import com.google.cloud.firestore.pipeline.stages.Where; |
64 | 66 | import com.google.cloud.firestore.telemetry.MetricsUtil.MetricsContext; |
65 | 67 | import com.google.cloud.firestore.telemetry.TelemetryConstants; |
@@ -1055,7 +1057,6 @@ public Pipeline sample(Sample sample) { |
1055 | 1057 | * @param other The other {@code Pipeline} that is part of union. |
1056 | 1058 | * @return A new {@code Pipeline} object with this stage appended to the stage list. |
1057 | 1059 | */ |
1058 | | - @BetaApi |
1059 | 1060 | public Pipeline union(Pipeline other) { |
1060 | 1061 | if (other.rpcContext == null) { |
1061 | 1062 | throw new IllegalArgumentException( |
@@ -1213,7 +1214,119 @@ public Pipeline unnest(Selectable field, UnnestOptions options) { |
1213 | 1214 | } |
1214 | 1215 |
|
1215 | 1216 | /** |
1216 | | - * Adds a generic stage to the pipeline. |
| 1217 | + * Performs a delete operation on documents from previous stages. |
| 1218 | + * |
| 1219 | + * <p>Example: |
| 1220 | + * |
| 1221 | + * <pre>{@code |
| 1222 | + * // Delete all documents in the "logs" collection where "status" is "archived" |
| 1223 | + * firestore.pipeline() |
| 1224 | + * .collection("logs") |
| 1225 | + * .where(field("status").equal("archived")) |
| 1226 | + * .delete() |
| 1227 | + * .execute() |
| 1228 | + * .get(); |
| 1229 | + * }</pre> |
| 1230 | + * |
| 1231 | + * @return A new {@code Pipeline} object with this stage appended to the stage list. |
| 1232 | + */ |
| 1233 | + @BetaApi |
| 1234 | + public Pipeline delete() { |
| 1235 | + return append(new Delete()); |
| 1236 | + } |
| 1237 | + |
| 1238 | + /** |
| 1239 | + * Performs an update operation using documents from previous stages. |
| 1240 | + * |
| 1241 | + * <p>This method updates the documents in place based on the data flowing through the pipeline. |
| 1242 | + * To specify transformations, use {@link #update(Selectable...)}. |
| 1243 | + * |
| 1244 | + * <p>Example 1: Update a collection's schema by adding a new field and removing an old one. |
| 1245 | + * |
| 1246 | + * <pre>{@code |
| 1247 | + * firestore.pipeline() |
| 1248 | + * .collection("books") |
| 1249 | + * .addFields(constant("Fiction").as("genre")) |
| 1250 | + * .removeFields("old_genre") |
| 1251 | + * .update() |
| 1252 | + * .execute() |
| 1253 | + * .get(); |
| 1254 | + * }</pre> |
| 1255 | + * |
| 1256 | + * <p>Example 2: Update documents in place with data from literals. |
| 1257 | + * |
| 1258 | + * <pre>{@code |
| 1259 | + * Map<String, Object> updateData = new HashMap<>(); |
| 1260 | + * updateData.put("__name__", firestore.collection("books").document("book1")); |
| 1261 | + * updateData.put("status", "Updated"); |
| 1262 | + * |
| 1263 | + * firestore.pipeline() |
| 1264 | + * .literals(updateData) |
| 1265 | + * .update() |
| 1266 | + * .execute() |
| 1267 | + * .get(); |
| 1268 | + * }</pre> |
| 1269 | + * |
| 1270 | + * @return A new {@code Pipeline} object with this stage appended to the stage list. |
| 1271 | + */ |
| 1272 | + @BetaApi |
| 1273 | + public Pipeline update() { |
| 1274 | + return append(new Update()); |
| 1275 | + } |
| 1276 | + |
| 1277 | + /** |
| 1278 | + * Performs an update operation using documents from previous stages with specified |
| 1279 | + * transformations. |
| 1280 | + * |
| 1281 | + * <p>Example: |
| 1282 | + * |
| 1283 | + * <pre>{@code |
| 1284 | + * // Update the "status" field to "Discounted" for all books where price > 50 |
| 1285 | + * firestore.pipeline() |
| 1286 | + * .collection("books") |
| 1287 | + * .where(field("price").greaterThan(50)) |
| 1288 | + * .update(constant("Discounted").as("status")) |
| 1289 | + * .execute() |
| 1290 | + * .get(); |
| 1291 | + * }</pre> |
| 1292 | + * |
| 1293 | + * @param transformedFields The transformations to apply. |
| 1294 | + * @return A new {@code Pipeline} object with this stage appended to the stage list. |
| 1295 | + */ |
| 1296 | + @BetaApi |
| 1297 | + public Pipeline update(Selectable... transformedFields) { |
| 1298 | + return append(new Update().withTransformedFields(transformedFields)); |
| 1299 | + } |
| 1300 | + |
| 1301 | + /** |
| 1302 | + * Performs an update operation using an {@link Update} stage. |
| 1303 | + * |
| 1304 | + * <p>This method allows you to use a pre-configured {@link Update} stage. |
| 1305 | + * |
| 1306 | + * <p>Example: |
| 1307 | + * |
| 1308 | + * <pre>{@code |
| 1309 | + * Update updateStage = new Update().withTransformedFields(constant("Updated").as("status")); |
| 1310 | + * |
| 1311 | + * firestore.pipeline() |
| 1312 | + * .collection("books") |
| 1313 | + * .where(field("title").equal("The Hitchhiker's Guide to the Galaxy")) |
| 1314 | + * .update(updateStage) |
| 1315 | + * .execute() |
| 1316 | + * .get(); |
| 1317 | + * }</pre> |
| 1318 | + * |
| 1319 | + * @param update The {@code Update} stage to append. |
| 1320 | + * @return A new {@code Pipeline} object with this stage appended to the stage list. |
| 1321 | + */ |
| 1322 | + @BetaApi |
| 1323 | + public Pipeline update(Update update) { |
| 1324 | + return append(update); |
| 1325 | + } |
| 1326 | + |
| 1327 | + /** |
| 1328 | + * Performs an insert operation using documents from previous stages. Adds a generic stage to the |
| 1329 | + * pipeline. |
1217 | 1330 | * |
1218 | 1331 | * <p>This method provides a flexible way to extend the pipeline's functionality by adding custom |
1219 | 1332 | * stages. Each generic stage is defined by a unique `name` and a set of `params` that control its |
|
0 commit comments