Composite attribute support - #2
Merged
Merged
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adds composite attribute support, following CoreModel #11. Requires CoreModel 2.11.0.
Storage
A composite maps onto MongoDB's embedded document — its native shape for structured values, so no flattening or serialization is needed:
Element key paths are the dotted paths the server already understands, so
location.latitude > 30becomes an ordinary query with no rewriting:Decoding iterates the declared elements rather than the stored document, so a stale field the schema no longer declares is ignored rather than mis-typed, and an element missing from the document decodes as
.nullso the decoded shape always matches the schema.The in-memory evaluation fallback (used for predicates the server can't run, e.g. custom functions) also descends into composite elements.
Also included
.arithmeticexpressions (new in CoreModel 2.11.0) are rejected for server-side queries and returnnilfrom the in-memory fallback rather than being silently mis-evaluated; both markedTODO.containsFunctiondoes recurse into arithmetic operands, since an operand can contain a function call.Testing
12 tests covering BSON encode/decode, nested composites, missing and unknown elements, wrong element types, null handling, key-path resolution (including the empty-key-path edge case), and the generated server queries for flat and nested element paths. All pass.
Caveat: these are server-free unit tests. The composite logic lives in the conversion and key-path code they cover, but the end-to-end query path has not been exercised against a live
mongod— no local instance was available. Worth an integration run before merging.