Skip to content

feat(firestore): add DML stages (Insert, Upsert) and atomic execution option to Java SDK pipelines - #14040

Open
wu-hui wants to merge 1 commit into
mainfrom
feat-java-pipeline-dml
Open

feat(firestore): add DML stages (Insert, Upsert) and atomic execution option to Java SDK pipelines#14040
wu-hui wants to merge 1 commit into
mainfrom
feat-java-pipeline-dml

Conversation

@wu-hui

@wu-hui wu-hui commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

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 for insert operation with collection reference and document_id expression options.
  • Upsert.java: Added new stage class for upsert operation with transformation expressions argument, collection reference, and document_id expression options.
  • PipelineExecuteOptions.java: Added withAtomic(boolean atomic) option.
  • Pipeline.java:
    • Added insert(...) and upsert(...) builder methods.
    • Configured executeInternal to populate newTransaction (readWrite) and autoCommitTransaction = true on ExecutePipelineRequest when atomic is enabled.
  • Unit & System Integration Tests:
    • Added unit test suite in PipelineProtoTest.java verifying proto generation for Insert and Upsert stages.
    • Added system integration tests in ITPipelineTest.java covering insert, upsert with transforms, atomic option, and transaction runner execution (transaction.execute(pipeline)).

Buganizer Ticket

Fixes http://b/545136773 (under umbrella http://b/500350942)

… 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
@wu-hui
wu-hui requested review from a team as code owners August 11, 2026 14:55

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +84 to +96
@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;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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;
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant