-
Notifications
You must be signed in to change notification settings - Fork 76
make options and returns internal, add update stage #2335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Update.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /* | ||
| * Copyright 2024 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.google.cloud.firestore.pipeline.stages; | ||
|
|
||
| import com.google.api.core.BetaApi; | ||
| import com.google.api.core.InternalApi; | ||
| import com.google.cloud.firestore.CollectionReference; | ||
| import com.google.cloud.firestore.PipelineUtils; | ||
| import com.google.cloud.firestore.pipeline.expressions.Selectable; | ||
| import com.google.firestore.v1.Value; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| @InternalApi | ||
| public final class Update extends Stage { | ||
|
|
||
| @Nullable private final String path; | ||
|
|
||
| private Update(@Nullable String path, InternalOptions options) { | ||
| super("update", options); | ||
| this.path = path; | ||
| } | ||
|
|
||
| @BetaApi | ||
| public Update() { | ||
| this(null, InternalOptions.EMPTY); | ||
| } | ||
|
|
||
| @BetaApi | ||
| public static Update withCollection(CollectionReference target) { | ||
| String path = target.getPath(); | ||
| return new Update(path.startsWith("/") ? path : "/" + path, InternalOptions.EMPTY); | ||
| } | ||
|
|
||
| @InternalApi | ||
| public Update withOptions(UpdateOptions options) { | ||
| return new Update(path, this.options.adding(options)); | ||
| } | ||
|
|
||
| @InternalApi | ||
| public Update withReturns(UpdateReturn returns) { | ||
| return new Update( | ||
| path, this.options.with("returns", PipelineUtils.encodeValue(returns.getValue()))); | ||
| } | ||
|
|
||
| @BetaApi | ||
| public Update withTransformations(Selectable... transformations) { | ||
| return new Update( | ||
| path, | ||
| this.options.with( | ||
| "transformations", | ||
| PipelineUtils.encodeValue(PipelineUtils.selectablesToMap(transformations)))); | ||
| } | ||
|
|
||
| @Override | ||
| Iterable<Value> toStageArgs() { | ||
| List<Value> args = new ArrayList<>(); | ||
| if (path != null) { | ||
| args.add(Value.newBuilder().setReferenceValue(path).build()); | ||
| } | ||
| return args; | ||
| } | ||
| } |
49 changes: 49 additions & 0 deletions
49
...oud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/UpdateOptions.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /* | ||
| * Copyright 2024 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.google.cloud.firestore.pipeline.stages; | ||
|
|
||
| import com.google.api.core.BetaApi; | ||
|
|
||
| /** Options for an Update pipeline stage. */ | ||
| @BetaApi | ||
| public class UpdateOptions extends WriteOptions<UpdateOptions> { | ||
|
|
||
| /** Creates a new, empty `UpdateOptions` object. */ | ||
| public UpdateOptions() { | ||
| super(InternalOptions.EMPTY); | ||
| } | ||
|
|
||
| UpdateOptions(InternalOptions options) { | ||
| super(options); | ||
| } | ||
|
|
||
| @Override | ||
| UpdateOptions self(InternalOptions options) { | ||
| return new UpdateOptions(options); | ||
| } | ||
|
|
||
| /** | ||
| * Sets the conflict resolution strategy. | ||
| * | ||
| * @param conflictResolution The conflict resolution strategy. | ||
| * @return A new options object with the conflict resolution set. | ||
| */ | ||
| @BetaApi | ||
| public UpdateOptions withConflictResolution(ConflictResolution conflictResolution) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Firestore is not adding a |
||
| return with("conflict_resolution", conflictResolution.getValue()); | ||
| } | ||
| } | ||
36 changes: 36 additions & 0 deletions
36
...loud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/UpdateReturn.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.google.cloud.firestore.pipeline.stages; | ||
|
|
||
| import com.google.api.core.InternalApi; | ||
|
|
||
| /** Defines the return value options for an Update pipeline stage. */ | ||
| @InternalApi | ||
| public enum UpdateReturn { | ||
| EMPTY("EMPTY"), | ||
| DOCUMENT_ID("DOCUMENT_ID"); | ||
|
|
||
| private final String value; | ||
|
|
||
| UpdateReturn(String value) { | ||
| this.value = value; | ||
| } | ||
|
|
||
| public String getValue() { | ||
| return value; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Firestore Is not supporting this option near term so we don't need to add this. Additionally when we do, this is not an enum concept, it is a list of field references so we should just be able to use the existing data representations for that.