diff options
author | Greg Studer <greg@10gen.com> | 2014-09-19 13:30:00 -0400 |
---|---|---|
committer | Greg Studer <greg@10gen.com> | 2014-10-16 18:38:12 -0400 |
commit | 22f8b6259602a76f8d22cba8b1098f9e3c90a36f (patch) | |
tree | 7cf4bd3d8b5439c4e42ca1be7ee6161a69af73a2 /src/mongo/db/ops/path_support.h | |
parent | 02c1c52514c7d6b54ff2d6dd6a3c564c3543f0a5 (diff) | |
download | mongo-22f8b6259602a76f8d22cba8b1098f9e3c90a36f.tar.gz |
SERVER-14973 consolidate shard key parsing, cleanup shard key patterns
Diffstat (limited to 'src/mongo/db/ops/path_support.h')
-rw-r--r-- | src/mongo/db/ops/path_support.h | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/src/mongo/db/ops/path_support.h b/src/mongo/db/ops/path_support.h index 2641b39f658..ce9d2bcf595 100644 --- a/src/mongo/db/ops/path_support.h +++ b/src/mongo/db/ops/path_support.h @@ -33,6 +33,9 @@ #include "mongo/base/status.h" #include "mongo/bson/mutable/element.h" #include "mongo/db/field_ref.h" +#include "mongo/db/field_ref_set.h" +#include "mongo/db/matcher/expression.h" +#include "mongo/db/matcher/expression_leaf.h" #include "mongo/platform/cstdint.h" namespace mongo { @@ -43,6 +46,9 @@ namespace mongo { // doesn't exist. static const size_t kMaxPaddingAllowed = 1500000; + // Convenience type to hold equality matches at particular paths from a MatchExpression + typedef map<StringData, const EqualityMatchExpression*> EqualityMatches; + /** * Finds the longest portion of 'prefix' that exists in document rooted at 'root' and is * "viable." A viable path is one that, if fully created on a given doc, would not @@ -93,6 +99,93 @@ namespace mongo { mutablebson::Element elemFound, mutablebson::Element newElem); + /** + * Uses the above methods to set the given value at the specified path in a mutable + * Document, creating parents of the path if necessary. + * + * Returns PathNotViable if the path cannot be created without modifying the type of another + * element, see above. + */ + Status setElementAtPath(const FieldRef& path, + const BSONElement& value, + mutablebson::Document* doc); + + /** + * Finds and returns-by-path all the equality matches in a particular MatchExpression. + * + * This method is meant to be used with the methods below, which allow efficient use of the + * equality matches without needing to serialize to a BSONObj. + * + * Returns NotSingleValueField if the match expression has equality operators for + * conflicting paths - equality paths conflict if they are the same or one path is a prefix + * of the other. + * + * Ex: + * { a : 1, b : 1 } -> no conflict + * { a : 1, a.b : 1 } -> conflict + * { _id : { x : 1 }, _id.y : 1 } -> conflict + * { a : 1, a : 1 } -> conflict + */ + Status extractEqualityMatches(const MatchExpression& root, EqualityMatches* equalities); + + /** + * Same as the above, but ignores all paths except for paths in a specified set. + * Equality matches with paths completely distinct from these paths are ignored. + * + * For a full equality match, the path of an equality found must not be a suffix of one of + * the specified path - otherwise it isn't clear how to construct a full value for a field + * at that path. + * + * Generally this is useful for shard keys and _ids which need unambiguous extraction from + * queries. + * + * Ex: + * { a : 1 }, full path 'a' -> a $eq 1 extracted + * { a : 1 }, full path 'a.b' -> a $eq 1 extracted + * { 'a.b' : 1 }, full path 'a' -> NotExactValueField error + * ('a.b' doesn't specify 'a' fully) + * { 'a.b' : 1 }, full path 'a.b' -> 'a.b' $eq 1 extracted + * { '_id' : 1 }, full path '_id' -> '_id' $eq 1 extracted + * { '_id.x' : 1 }, full path '_id' -> NotExactValueFieldError + */ + Status extractFullEqualityMatches(const MatchExpression& root, + const FieldRefSet& fullPathsToExtract, + EqualityMatches* equalities); + + /** + * Returns the equality match which is at or a parent of the specified path string. The + * path string must be a valid dotted path. + * + * If a parent equality is found, returns the BSONElement data from that equality (which + * includes the BSON value), the path of the parent element (prefixStr), and the remainder + * of the path (which may be empty). + * + * EOO() is returned if there were no equalities at any point along the path. + * + * Ex: + * Given equality matches of: + * 'a.b' : 1, 'c' : 2 + * Path 'a' has no equality match parent (EOO) + * Path 'c' has an eqmatch parent of 'c' : 2 + * Path 'c.d' has an eqmatch parent of 'c' : 2 + * Path 'a.b' has an eqmatch parent of 'a.b' : 1 + * Path 'a.b.c' has an eqmatch parent of 'a.b' : 1 + * + */ + const BSONElement& findParentEqualityElement(const EqualityMatches& equalities, + const FieldRef& path, + int* parentPathParts); + + /** + * Adds the BSON values from equality matches into the given document at the equality match + * paths. + * + * Returns PathNotViable similar to setElementAtPath above. If equality paths do not + * conflict, as is enforced by extractEqualityMatches, this function should return OK. + */ + Status addEqualitiesToDoc(const EqualityMatches& equalities, + mutablebson::Document* doc); + } // namespace pathsupport } // namespace mongo |