feat(firestore): add DML stages (Insert, Upsert) and atomic execution option to Java SDK pipelines - #14040
feat(firestore): add DML stages (Insert, Upsert) and atomic execution option to Java SDK pipelines#14040wu-hui wants to merge 1 commit into
Conversation
… option to Java SDK pipelines - Implement Insert.java and Upsert.java stages in com.google.cloud.firestore.pipeline.stages - Add insert() and upsert() builder methods to Pipeline.java - Add withAtomic() option to PipelineExecuteOptions.java and wire proto request (newTransaction + autoCommitTransaction) - Add proto serialization unit tests in PipelineProtoTest.java - Add system integration test suite in ITPipelineTest.java covering insert, upsert, atomic execution, and transaction execution BUG=b/545136773 TAG=agy
There was a problem hiding this comment.
Code Review
This pull request introduces the Insert and Upsert pipeline stages to the Firestore Pipeline API, along with an atomic execution option in PipelineExecuteOptions that automatically configures a read-write transaction. Unit and integration tests have been added to verify these new stages and execution options. The feedback suggests simplifying the toStageArgs method in Upsert.java by passing the map of expressions directly to PipelineUtils.encodeValue instead of manually iterating and encoding each entry.
| @Override | ||
| Iterable<Value> toStageArgs() { | ||
| List<Value> args = new ArrayList<>(); | ||
| if (transformedFields != null && transformedFields.length > 0) { | ||
| Map<String, Expression> map = PipelineUtils.selectablesToMap(transformedFields); | ||
| Map<String, Value> encodedMap = new HashMap<>(); | ||
| for (Map.Entry<String, Expression> entry : map.entrySet()) { | ||
| encodedMap.put(entry.getKey(), PipelineUtils.encodeValue(entry.getValue())); | ||
| } | ||
| args.add(PipelineUtils.encodeValue(encodedMap)); | ||
| } | ||
| return args; | ||
| } |
There was a problem hiding this comment.
The manual loop to encode each entry of the map is redundant. PipelineUtils.encodeValue recursively encodes map values, so we can pass the Map<String, Expression> directly to PipelineUtils.encodeValue to simplify the implementation.
@Override
Iterable<Value> toStageArgs() {
List<Value> args = new ArrayList<>();
if (transformedFields != null && transformedFields.length > 0) {
Map<String, Expression> map = PipelineUtils.selectablesToMap(transformedFields);
args.add(PipelineUtils.encodeValue(map));
}
return args;
}
Summary
Adds DML stages (
Insert,Upsert) and the atomic execution option to the Java SDK (java-firestore) Firestore Pipelines subsystem to achieve parity with Node and Web SDKs.Key Changes
Insert.java: Added new stage class forinsertoperation withcollectionreference anddocument_idexpression options.Upsert.java: Added new stage class forupsertoperation with transformation expressions argument,collectionreference, anddocument_idexpression options.PipelineExecuteOptions.java: AddedwithAtomic(boolean atomic)option.Pipeline.java:insert(...)andupsert(...)builder methods.executeInternalto populatenewTransaction(readWrite) andautoCommitTransaction = trueonExecutePipelineRequestwhenatomicis enabled.PipelineProtoTest.javaverifying proto generation forInsertandUpsertstages.ITPipelineTest.javacoveringinsert,upsertwith transforms,atomicoption, and transaction runner execution (transaction.execute(pipeline)).Buganizer Ticket
Fixes http://b/545136773 (under umbrella http://b/500350942)