Skip to content
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

Add new bulk create constructor without optional _id field #245

Merged

Conversation

camerondurham
Copy link
Contributor

@camerondurham camerondurham commented Apr 3, 2024

Change (latest - revision 2)

Added new create_no_id and new_no_id constructors/helpers to support bulk create operations where no _id field is required.

Change (revision 1)

Changed types to id: Option<S> when _id is optional in the bulk request, otherwise, keep id parameter as String.

This change is making the Bulk operation constructor parameters more closely match the Bulk API, specifically when _id is required or not.

Summarized from the docs: https://www.elastic.co/guide/en/elasticsearch/reference/7.10/docs-bulk.html#bulk-api-request-body

  • create: _id (optional, string)
  • delete: _id (required, string)
  • index: _id (optional, string)
  • update _id (required, string)

Issues Resolved

Related to, and may close issue #241 .

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@camerondurham camerondurham force-pushed the consistent-api-constructor branch 2 times, most recently from 68db8b7 to 1abe182 Compare April 3, 2024 07:17
@camerondurham camerondurham marked this pull request as ready for review April 3, 2024 15:46
@dblock
Copy link
Member

dblock commented Apr 3, 2024

@Xtansia take a look?

Regarding a breaking change: if it can be avoided it's best. Then we don't need to do a major release and break users. You can deprecate the old method.

Copy link

codecov bot commented Apr 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.85%. Comparing base (41417d4) to head (2dc360c).
Report is 2 commits behind head on main.

❗ Current head 2dc360c differs from pull request most recent head 56e0316. Consider uploading reports for the commit 56e0316 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #245      +/-   ##
==========================================
+ Coverage   79.71%   79.85%   +0.13%     
==========================================
  Files         418      417       -1     
  Lines       71104    69599    -1505     
==========================================
- Hits        56682    55575    -1107     
+ Misses      14422    14024     -398     
Flag Coverage Δ
integration 79.85% <ø> (+0.13%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@camerondurham
Copy link
Contributor Author

camerondurham commented Apr 3, 2024

It totally makes sense to avoid breaking change. And "making the Rust interface more consistent" doesn't seem to add enough value to warrant a version bump, imo. I'll revise to add new optional constructor from #241 in a non-breaking way.

Testing

And thanks for running test cases, I see I missed updating a bunch of tests will work on that.

I had some trouble running these tests locally so didn't catch this before opening the CR.

https://github.com/opensearch-project/opensearch-rs/actions/runs/8535970109/job/23406883030?pr=245#step:5:446

15  |   ops.push(BulkOperation::index(json!({
    |  __________^^^^^^^^^^^^^^^^^^^^_-
16  | |         "user": "kimchy",
17  | |         "post_date": "2009-11-15T00:00:00Z",
18  | |         "message": "Trying out OpenSearch, so far so good?"
19  | |     }))
    | |______- an argument of type `Option<_>` is missing

@Xtansia
Copy link
Collaborator

Xtansia commented Apr 3, 2024

I also don't feel this warrants a breaking version bump just for this, however there is an opportunity where you could PR a non-breaking change directly into 2.x and make the breaking change in main. Then it'll be usable sooner via a minor version, and the "corrected" version can just wait for whenever we cut a 3.0.0

@camerondurham camerondurham changed the title Use optional when id is optional in bulk requests Add new bulk create constructor without optional _id field passed in Apr 6, 2024
@camerondurham camerondurham changed the title Add new bulk create constructor without optional _id field passed in Add new bulk create constructor without optional _id field Apr 6, 2024
Copy link
Collaborator

@Xtansia Xtansia left a comment

Choose a reason for hiding this comment

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

Changes look good, I just have some thoughts about the naming.
Could you please also add an entry to the CHANGELOG.md under the "Added" header.
You can ignore the Link Checker workflow failure.

opensearch/src/root/bulk.rs Outdated Show resolved Hide resolved
opensearch/src/root/bulk.rs Outdated Show resolved Hide resolved
opensearch/src/root/bulk.rs Outdated Show resolved Hide resolved
camerondurham and others added 2 commits April 7, 2024 18:11
@camerondurham
Copy link
Contributor Author

camerondurham commented Apr 8, 2024

Thanks for the review @Xtansia, I accepted all suggestions and added an entry to the changelog.

@Xtansia Xtansia merged commit 28e3d47 into opensearch-project:main Apr 8, 2024
31 checks passed
@Xtansia Xtansia added the backport 2.x Backport to the 2.x branch label Apr 8, 2024
@opensearch-trigger-bot
Copy link

The backport to 2.x failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-2.x 2.x
# Navigate to the new working tree
cd .worktrees/backport-2.x
# Create a new branch
git switch --create backport/backport-245-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 28e3d47a54c4fe1ce0a3647c872411602dc6b1e2
# Push it to GitHub
git push --set-upstream origin backport/backport-245-to-2.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-2.x

Then, create a pull request where the base branch is 2.x and the compare/head branch is backport/backport-245-to-2.x.

Xtansia pushed a commit to Xtansia/opensearch-rs that referenced this pull request Apr 8, 2024
…h-project#245)

* Use Option<S> when id is optional in bulk request

Signed-off-by: Cameron Durham <[email protected]>

* Revert "Use Option<S> when id is optional in bulk request"

Signed-off-by: Cameron Durham <[email protected]>

* Add no_id constructor and test case

Signed-off-by: Cameron Durham <[email protected]>

* Change constructor name from _no_id to _without_id

Co-authored-by: Thomas Farr <[email protected]>
Signed-off-by: Cam <[email protected]>

* Add entry to CHANGELOG

Signed-off-by: camerondurham <[email protected]>

---------

Signed-off-by: Cameron Durham <[email protected]>
Signed-off-by: Cam <[email protected]>
Signed-off-by: camerondurham <[email protected]>
Co-authored-by: Thomas Farr <[email protected]>
(cherry picked from commit 28e3d47)
dblock pushed a commit that referenced this pull request Apr 8, 2024
* Use Option<S> when id is optional in bulk request

Signed-off-by: Cameron Durham <[email protected]>

* Revert "Use Option<S> when id is optional in bulk request"

Signed-off-by: Cameron Durham <[email protected]>

* Add no_id constructor and test case

Signed-off-by: Cameron Durham <[email protected]>

* Change constructor name from _no_id to _without_id

Co-authored-by: Thomas Farr <[email protected]>
Signed-off-by: Cam <[email protected]>

* Add entry to CHANGELOG

Signed-off-by: camerondurham <[email protected]>

---------

Signed-off-by: Cameron Durham <[email protected]>
Signed-off-by: Cam <[email protected]>
Signed-off-by: camerondurham <[email protected]>
Co-authored-by: Thomas Farr <[email protected]>
(cherry picked from commit 28e3d47)

Co-authored-by: Cam <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x Backport to the 2.x branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants