Skip to content
This repository was archived by the owner on May 8, 2026. It is now read-only.

Commit e162660

Browse files
committed
Add pipeline DML tests and fix update verification
1 parent 5f25f12 commit e162660

14 files changed

Lines changed: 368 additions & 368 deletions

File tree

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

Lines changed: 9 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,10 @@
4242
import com.google.cloud.firestore.pipeline.stages.Aggregate;
4343
import com.google.cloud.firestore.pipeline.stages.AggregateOptions;
4444
import com.google.cloud.firestore.pipeline.stages.Delete;
45-
import com.google.cloud.firestore.pipeline.stages.DeleteOptions;
4645
import com.google.cloud.firestore.pipeline.stages.Distinct;
4746
import com.google.cloud.firestore.pipeline.stages.FindNearest;
4847
import com.google.cloud.firestore.pipeline.stages.FindNearestOptions;
4948
import com.google.cloud.firestore.pipeline.stages.Insert;
50-
import com.google.cloud.firestore.pipeline.stages.InsertOptions;
5149
import com.google.cloud.firestore.pipeline.stages.Limit;
5250
import com.google.cloud.firestore.pipeline.stages.Offset;
5351
import com.google.cloud.firestore.pipeline.stages.PipelineExecuteOptions;
@@ -63,9 +61,7 @@
6361
import com.google.cloud.firestore.pipeline.stages.Unnest;
6462
import com.google.cloud.firestore.pipeline.stages.UnnestOptions;
6563
import com.google.cloud.firestore.pipeline.stages.Update;
66-
import com.google.cloud.firestore.pipeline.stages.UpdateOptions;
6764
import com.google.cloud.firestore.pipeline.stages.Upsert;
68-
import com.google.cloud.firestore.pipeline.stages.UpsertOptions;
6965
import com.google.cloud.firestore.pipeline.stages.Where;
7066
import com.google.cloud.firestore.telemetry.MetricsUtil.MetricsContext;
7167
import com.google.cloud.firestore.telemetry.TelemetryConstants;
@@ -1013,29 +1009,6 @@ public Pipeline delete() {
10131009
return append(new Delete());
10141010
}
10151011

1016-
/**
1017-
* Performs a delete operation on documents from previous stages.
1018-
*
1019-
* @param target The collection to delete from.
1020-
* @return A new {@code Pipeline} object with this stage appended to the stage list.
1021-
*/
1022-
@BetaApi
1023-
public Pipeline delete(CollectionReference target) {
1024-
return append(Delete.withCollection(target));
1025-
}
1026-
1027-
/**
1028-
* Performs a delete operation on documents from previous stages.
1029-
*
1030-
* @param deleteStage The {@code Delete} stage to append.
1031-
* @param options The {@code DeleteOptions} to apply to the stage.
1032-
* @return A new {@code Pipeline} object with this stage appended to the stage list.
1033-
*/
1034-
@InternalApi
1035-
public Pipeline delete(Delete deleteStage, DeleteOptions options) {
1036-
return append(deleteStage.withOptions(options));
1037-
}
1038-
10391012
/**
10401013
* Performs an upsert operation using documents from previous stages.
10411014
*
@@ -1054,19 +1027,18 @@ public Pipeline upsert() {
10541027
*/
10551028
@BetaApi
10561029
public Pipeline upsert(CollectionReference target) {
1057-
return append(Upsert.withCollection(target));
1030+
return append(new Upsert().withCollection(target));
10581031
}
10591032

10601033
/**
10611034
* Performs an upsert operation using documents from previous stages.
10621035
*
10631036
* @param upsertStage The {@code Upsert} stage to append.
1064-
* @param options The {@code UpsertOptions} to apply to the stage.
10651037
* @return A new {@code Pipeline} object with this stage appended to the stage list.
10661038
*/
10671039
@InternalApi
1068-
public Pipeline upsert(Upsert upsertStage, UpsertOptions options) {
1069-
return append(upsertStage.withOptions(options));
1040+
public Pipeline upsert(Upsert upsertStage) {
1041+
return append(upsertStage);
10701042
}
10711043

10721044
/**
@@ -1094,12 +1066,11 @@ public Pipeline update(Selectable... transformations) {
10941066
* Performs an update operation using documents from previous stages.
10951067
*
10961068
* @param update The {@code Update} stage to append.
1097-
* @param options The {@code UpdateOptions} to apply to the stage.
10981069
* @return A new {@code Pipeline} object with this stage appended to the stage list.
10991070
*/
11001071
@InternalApi
1101-
public Pipeline update(Update updateStage, UpdateOptions options) {
1102-
return append(updateStage.withOptions(options));
1072+
public Pipeline update(Update update) {
1073+
return append(update);
11031074
}
11041075

11051076
/**
@@ -1120,19 +1091,18 @@ public Pipeline insert() {
11201091
*/
11211092
@BetaApi
11221093
public Pipeline insert(CollectionReference target) {
1123-
return append(Insert.withCollection(target));
1094+
return append(new Insert().withCollection(target));
11241095
}
11251096

11261097
/**
11271098
* Performs an insert operation using documents from previous stages.
11281099
*
11291100
* @param insertStage The {@code Insert} stage to append.
1130-
* @param options The {@code InsertOptions} to apply to the stage.
11311101
* @return A new {@code Pipeline} object with this stage appended to the stage list.
11321102
*/
11331103
@InternalApi
1134-
public Pipeline insert(Insert insertStage, InsertOptions options) {
1135-
return append(insertStage.withOptions(options));
1104+
public Pipeline insert(Insert insertStage) {
1105+
return append(insertStage);
11361106
}
11371107

11381108
/**
@@ -1476,7 +1446,7 @@ public void onComplete() {
14761446
}
14771447
};
14781448

1479-
logger.log(Level.FINEST, "Sending pipeline request: " + request.getStructuredPipeline());
1449+
logger.log(Level.WARNING, "Sending pipeline request: " + request.getStructuredPipeline());
14801450

14811451
rpcContext.streamRequest(request, observer, rpcContext.getClient().executePipelineCallable());
14821452
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.google.cloud.firestore.pipeline.stages.CollectionOptions;
2525
import com.google.cloud.firestore.pipeline.stages.Database;
2626
import com.google.cloud.firestore.pipeline.stages.Documents;
27+
import com.google.cloud.firestore.pipeline.stages.Literals;
2728
import com.google.common.base.Preconditions;
2829
import java.util.Arrays;
2930
import javax.annotation.Nonnull;
@@ -157,6 +158,19 @@ public Pipeline documents(String... docs) {
157158
.toArray(DocumentReference[]::new)));
158159
}
159160

161+
/**
162+
* Creates a new {@link Pipeline} that operates on a static set of documents
163+
* represented as Maps.
164+
*
165+
* @param data The Maps representing documents to include in the pipeline.
166+
* @return A new {@code Pipeline} instance with a literals source.
167+
*/
168+
@Nonnull
169+
@BetaApi
170+
public final Pipeline literals(java.util.Map<String, Object>... data) {
171+
return new Pipeline(this.rpcContext, new Literals(data));
172+
}
173+
160174
/**
161175
* Creates a new {@link Pipeline} from the given {@link Query}. Under the hood, this will
162176
* translate the query semantics (order by document ID, etc.) to an equivalent pipeline.

google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Delete.java

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,42 +27,17 @@
2727

2828
@InternalApi
2929
public final class Delete extends Stage {
30-
31-
@Nullable private final String path;
32-
33-
private Delete(@Nullable String path, InternalOptions options) {
30+
private Delete(InternalOptions options) {
3431
super("delete", options);
35-
this.path = path;
3632
}
3733

3834
@BetaApi
3935
public Delete() {
40-
this(null, InternalOptions.EMPTY);
41-
}
42-
43-
@BetaApi
44-
public static Delete withCollection(CollectionReference target) {
45-
String path = target.getPath();
46-
return new Delete(path.startsWith("/") ? path : "/" + path, InternalOptions.EMPTY);
47-
}
48-
49-
@InternalApi
50-
public Delete withOptions(DeleteOptions options) {
51-
return new Delete(path, this.options.adding(options));
52-
}
53-
54-
@InternalApi
55-
public Delete withReturns(DeleteReturn returns) {
56-
return new Delete(
57-
path, this.options.with("returns", PipelineUtils.encodeValue(returns.getValue())));
36+
this(InternalOptions.EMPTY);
5837
}
5938

6039
@Override
6140
Iterable<Value> toStageArgs() {
62-
List<Value> args = new ArrayList<>();
63-
if (path != null) {
64-
args.add(Value.newBuilder().setReferenceValue(path).build());
65-
}
66-
return args;
41+
return new ArrayList<>();
6742
}
6843
}

google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/DeleteOptions.java

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

google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Insert.java

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,59 +20,41 @@
2020
import com.google.api.core.InternalApi;
2121
import com.google.cloud.firestore.CollectionReference;
2222
import com.google.cloud.firestore.PipelineUtils;
23+
import com.google.cloud.firestore.pipeline.expressions.Expression;
2324
import com.google.cloud.firestore.pipeline.expressions.Selectable;
2425
import com.google.firestore.v1.Value;
2526
import java.util.ArrayList;
2627
import java.util.List;
2728
import javax.annotation.Nullable;
2829

29-
@InternalApi
30+
@BetaApi
3031
public final class Insert extends Stage {
3132

32-
@Nullable private final String path;
33-
34-
private Insert(@Nullable String path, InternalOptions options) {
33+
private Insert(InternalOptions options) {
3534
super("insert", options);
36-
this.path = path;
3735
}
3836

3937
@BetaApi
4038
public Insert() {
41-
this(null, InternalOptions.EMPTY);
39+
this(InternalOptions.EMPTY);
4240
}
4341

4442
@BetaApi
45-
public static Insert withCollection(CollectionReference target) {
43+
public Insert withCollection(CollectionReference target) {
4644
String path = target.getPath();
47-
return new Insert(path.startsWith("/") ? path : "/" + path, InternalOptions.EMPTY);
48-
}
49-
50-
@InternalApi
51-
public Insert withOptions(InsertOptions options) {
52-
return new Insert(path, this.options.adding(options));
53-
}
54-
55-
@InternalApi
56-
public Insert withReturns(InsertReturn returns) {
45+
String normalizedPath = path.startsWith("/") ? path : "/" + path;
5746
return new Insert(
58-
path, this.options.with("returns", PipelineUtils.encodeValue(returns.getValue())));
47+
this.options.with(
48+
"collection", Value.newBuilder().setReferenceValue(normalizedPath).build()));
5949
}
6050

6151
@BetaApi
62-
public Insert withTransformations(Selectable... transformations) {
63-
return new Insert(
64-
path,
65-
this.options.with(
66-
"transformations",
67-
PipelineUtils.encodeValue(PipelineUtils.selectablesToMap(transformations))));
52+
public Insert withIdExpression(Expression idExpr) {
53+
return new Insert(this.options.with("document_id", PipelineUtils.encodeValue(idExpr)));
6854
}
6955

7056
@Override
7157
Iterable<Value> toStageArgs() {
72-
List<Value> args = new ArrayList<>();
73-
if (path != null) {
74-
args.add(Value.newBuilder().setReferenceValue(path).build());
75-
}
76-
return args;
58+
return java.util.Collections.emptyList();
7759
}
7860
}

google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/InsertOptions.java

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

0 commit comments

Comments
 (0)