Fix #2570,#2572: Allow upserts to recognize $and clauses - #2571
Conversation
📈 Unit Test Coverage Delta vs Main Branch
|
Unit Test Coverage Report
|
📉 Integration Test Coverage Delta vs Main Branch (dse69-it)
|
Integration Test Coverage Report (dse69-it)
|
📉 Integration Test Coverage Delta vs Main Branch (hcd-it)
|
Integration Test Coverage Report (hcd-it)
|
There was a problem hiding this comment.
Pull request overview
Enables upserts to reconstruct documents from equality filters nested in $and clauses.
Changes:
- Recursively reconstructs upsert documents and validates overlapping paths.
- Moves reconstruction into
DocumentUpdater, with_id-only reconstruction for replacements. - Adds error handling and unit tests for reconstruction.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
DocumentUpdaterTest.java |
Updates calls for the new reconstructor parameter. |
FindCollectionOperationTest.java |
Tests reconstruction and path validation. |
errors.yaml |
Defines the overlapping-upsert-path error. |
DocumentUpdater.java |
Integrates operation-specific reconstruction. |
ReadAndUpdateCollectionOperation.java |
Delegates upsert reconstruction. |
FindCollectionOperation.java |
Traverses $and filters and validates paths. |
UpdateException.java |
Registers the new error code. |
UpdateOperation.java |
Changes the action accessor return type. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| public ReadDocument newEmptyDocument() { | ||
| return ReadDocument.from(null, null, objectMapper().createObjectNode()); |
There was a problem hiding this comment.
This was a bug before my PR as well (as it wasn't guaranteed for an IDCollectionFilter to be present in getNewDocument(). My PR just amplifies the issue by never having the id set in the ReadDocument at all.
The issue is a deeper one which I'm not 100% sure how to solve
There was a problem hiding this comment.
I think we may need to save writableShreddedDocument.id() and use that in readDocumentAgain()? I'm really not sure though
$and clauses$and clauses
…s behavior w/ findOneAndReplace
be38117 to
373fd29
Compare
What this PR does:
Updates Collection update operations to allow
$eqfilters nested inside of$andsto be included in the reconstructed document. See #2570 for a lot more information.$andnodes, and "validated" when being reconstructed, throwing a newUNSUPPORTED_OVERLAPPING_UPSERT_PATHSerror when contradictory paths are given, similar to Mongo's implementation.This PR also addresses the TODO to have document reconstruction be inside of
documentUpdaterrather than split into two places._id. This preventsFindOneAndReplaceoperations from unnecessarily/wrongly throwing errors when contradictory filters exist outside the_idfield.Finally, this PR fixes #2572 which wrongly allows certain non-
$eqfields to be included in the reconstructed document.P.S. I left a comment for a minor optimization which could address one of aaron's comments + would remove an extra deepCopy in replace operations. Lmk if you just want me to do it in this PR, it's like a 4 line change
it should work, I just need to finish testing
Which issue(s) this PR fixes:
Fixes #2570 and #2572
Checklist