-
Notifications
You must be signed in to change notification settings - Fork 263
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
PHPLIB-1182: Support codec option in operation classes #1140
Merged
alcaeus
merged 37 commits into
mongodb:master
from
alcaeus:phplib-1182-codec-operations
Aug 25, 2023
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
7b10f77
Add Codec support to find operations
alcaeus 2ceed92
Add codec support to insert operations
alcaeus db998c3
Add codec support to replace operation
alcaeus d30c8b8
Add codec support to aggregate operation
alcaeus 5320217
Add codec support to BulkWrite operation
alcaeus dead64b
Add codec support to findAndModify operations
alcaeus 274d50a
Add codec support to Watch operation
alcaeus c67ff64
Support passing default codec to collection class
alcaeus 97c6035
Remove temporary variable usage in operations
alcaeus a3f463a
Enforce iterator type when creating ChangeStreamIterator
alcaeus 4d32785
Remove unnecessary null-coalesce
alcaeus 4a0d944
Ensure operation-level type map gets precedence over collection-level…
alcaeus 8ce7221
Reference psalm issue regarding unions and assert-if type annotations
alcaeus 45e5a77
Add iterator type in ReadableStream
alcaeus 6ee86c4
Assume _id property will be present in change stream result document.
alcaeus 21edb06
Prohibit specifying typeMap and codec options for operations
alcaeus 53f9fbf
Defer server selection until executing operation
alcaeus f484bd7
Remove useless assertion
alcaeus f06b40d
Assert iterator type in ChangeStreamIterator::getInnerIterator
alcaeus 1f23d34
Make assertions on encoded result conditional
alcaeus 18a0ed1
Extract factory to created decoded fixtures
alcaeus 38aaf71
Split document creation for legibility
alcaeus 1d9699f
Insert fixture through factory in test object
alcaeus ec53fe7
Trigger warning when calling CodecCursor::setTypeMap
alcaeus c4d46b8
Encode documents before type checks
alcaeus 4eceaf6
Use more descriptive value in failing tests
alcaeus 1cb170c
Add clarifying comment on skipping validation
alcaeus 56fc1ef
Simplify double isset check
alcaeus 003f73b
Split chained calls when inheriting options
alcaeus 66b9308
Defer server selection in Collection::drop()
alcaeus 69c32c8
Split inheritReadOptions method
alcaeus 6f8cdea
Use decode() instead of decodeIfSupported()
alcaeus ed56c09
Add explanatory comment for ID filling behaviour
alcaeus e3d68a7
Handle null values in findAndModify responses
alcaeus 0ed7f67
Update comment regarding missing identifiers in tests
alcaeus 9cdb66a
Use intersection type for change streams
alcaeus f532119
Prohibit specifying codec and typeMap options to Watch
alcaeus 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 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 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.
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.
Watch constructs the ChangeStreamIterator and has access to its internal cursor, even though it currently sends it as-is directly from the private
executeAggregate()
method. Watch also constructs the$resumeCallable
here.I was going to ask why ChangeStream bothers with calling
setTypeMap(['root' => 'bson'])
when that could otherwise be done in Watch; however, even if we did move that logic to Watch, ChangeStream would still need to know about the codec in order to process return values forcurrent()
.And you previously explained that Watch cannot apply the codec itself since doing so might interfere with resume token collection.
I think this is fine as-is but just want to confirm with you before signing off. Feel free to resolve after reading if my understanding is correct.
Another reason for asking was that ChangeStream is in the public API (although undocumented), so I'm paying extra attention the signature change above.
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.
Since
ChangeStream
needs to be in control of the codec used in the cursor (as it needs to be sure about the return types), I figured it would make more sense forChangeStream
to apply its codec to the underlying cursor instead of relying on that being set correctly. As is,Watch
is only accepting thecodec
option on behalf ofChangeStream
, and passing it on without needing to know about internal workings ofChangeStream
.The main problem with applying the codec in the original
Aggregate
operation is that while the aggregation pipeline results will always have an_id
field to be used as resume token, we cannot make such guarantees after the codec has been applied. After that, the_id
field may have been discarded or assigned to an object property we don't know about.Also note that while
ChangeStream
andChangeStreamIterator
are part of the public API, both their constructors are marked as internal; indicating that while we expect users to interact with these classes, we don't expect them to instantiate them on their own. The signature change here is backward compatible, as the$codec
parameter defaults tonull
, so any previously working instantiations of that class will continue to function as expected.