diff options
author | Jason Rassi <rassi@10gen.com> | 2015-11-09 20:04:43 -0500 |
---|---|---|
committer | Jason Rassi <rassi@10gen.com> | 2015-11-12 16:28:55 -0500 |
commit | c051996996ae7e4f5f93cb38b1f140e0331fceb7 (patch) | |
tree | 5e6c3675d80352fd859e99495b42f5a7b938d679 /src | |
parent | bb62b1223f72c3ad8af0b77019c2ce3390d677a1 (diff) | |
download | mongo-c051996996ae7e4f5f93cb38b1f140e0331fceb7.tar.gz |
SERVER-19510 Move ExtensionsCallback out of MatchExpressionParser
Diffstat (limited to 'src')
21 files changed, 257 insertions, 201 deletions
diff --git a/src/mongo/db/auth/authz_manager_external_state_mock.cpp b/src/mongo/db/auth/authz_manager_external_state_mock.cpp index 797d6a147ea..94617a82fbe 100644 --- a/src/mongo/db/auth/authz_manager_external_state_mock.cpp +++ b/src/mongo/db/auth/authz_manager_external_state_mock.cpp @@ -274,7 +274,7 @@ Status AuthzManagerExternalStateMock::_queryVector( const BSONObj& query, std::vector<BSONObjCollection::iterator>* result) { StatusWithMatchExpression parseResult = - MatchExpressionParser::parse(query, MatchExpressionParser::ExtensionsCallback()); + MatchExpressionParser::parse(query, ExtensionsCallback()); if (!parseResult.isOK()) { return parseResult.getStatus(); } diff --git a/src/mongo/db/exec/projection.h b/src/mongo/db/exec/projection.h index 87a3f97a2fd..aa03665bd3a 100644 --- a/src/mongo/db/exec/projection.h +++ b/src/mongo/db/exec/projection.h @@ -37,6 +37,8 @@ namespace mongo { +class ExtensionsCallback; + struct ProjectionStageParams { enum ProjectionImplementation { // The default case. Will handle every projection. @@ -49,7 +51,7 @@ struct ProjectionStageParams { SIMPLE_DOC }; - ProjectionStageParams(const MatchExpressionParser::ExtensionsCallback& wc) + ProjectionStageParams(const ExtensionsCallback& wc) : projImpl(NO_FAST_PATH), fullExpression(NULL), extensionsCallback(&wc) {} ProjectionImplementation projImpl; @@ -67,7 +69,7 @@ struct ProjectionStageParams { BSONObj coveredKeyObj; // Used for creating context for the match extensions processing. Not owned. - const MatchExpressionParser::ExtensionsCallback* extensionsCallback; + const ExtensionsCallback* extensionsCallback; }; /** diff --git a/src/mongo/db/exec/projection_exec.cpp b/src/mongo/db/exec/projection_exec.cpp index d0eb29d1827..f5ea2cfd901 100644 --- a/src/mongo/db/exec/projection_exec.cpp +++ b/src/mongo/db/exec/projection_exec.cpp @@ -74,7 +74,7 @@ ProjectionExec::ProjectionExec() ProjectionExec::ProjectionExec(const BSONObj& spec, const MatchExpression* queryExpression, - const MatchExpressionParser::ExtensionsCallback& extensionsCallback) + const ExtensionsCallback& extensionsCallback) : _include(true), _special(false), _source(spec), diff --git a/src/mongo/db/exec/projection_exec.h b/src/mongo/db/exec/projection_exec.h index 9be352118d3..6558b75fbf3 100644 --- a/src/mongo/db/exec/projection_exec.h +++ b/src/mongo/db/exec/projection_exec.h @@ -66,8 +66,7 @@ public: ProjectionExec(const BSONObj& spec, const MatchExpression* queryExpression, - const MatchExpressionParser::ExtensionsCallback& extensionsCallback = - MatchExpressionParser::ExtensionsCallback()); + const ExtensionsCallback& extensionsCallback = ExtensionsCallback()); ~ProjectionExec(); /** diff --git a/src/mongo/db/matcher/SConscript b/src/mongo/db/matcher/SConscript index 506e2ba1cbc..af686b9f96b 100644 --- a/src/mongo/db/matcher/SConscript +++ b/src/mongo/db/matcher/SConscript @@ -37,6 +37,7 @@ env.Library( 'expression_tree.cpp', 'expression_where_base.cpp', 'expression_where_noop.cpp', + 'extensions_callback.cpp', 'extensions_callback_noop.cpp', 'match_details.cpp', 'matchable.cpp', diff --git a/src/mongo/db/matcher/expression.h b/src/mongo/db/matcher/expression.h index 52f026d589e..0a67870d4ff 100644 --- a/src/mongo/db/matcher/expression.h +++ b/src/mongo/db/matcher/expression.h @@ -41,8 +41,11 @@ namespace mongo { +class MatchExpression; class TreeMatchExpression; +typedef StatusWith<std::unique_ptr<MatchExpression>> StatusWithMatchExpression; + class MatchExpression { MONGO_DISALLOW_COPYING(MatchExpression); diff --git a/src/mongo/db/matcher/expression_parser.cpp b/src/mongo/db/matcher/expression_parser.cpp index 6692e41aead..0c385c78d69 100644 --- a/src/mongo/db/matcher/expression_parser.cpp +++ b/src/mongo/db/matcher/expression_parser.cpp @@ -33,7 +33,6 @@ #include "mongo/bson/bsonmisc.h" #include "mongo/bson/bsonobj.h" #include "mongo/bson/bsonobjbuilder.h" -#include "mongo/bson/util/bson_extract.h" #include "mongo/db/matcher/expression_array.h" #include "mongo/db/matcher/expression_leaf.h" #include "mongo/db/matcher/expression_tree.h" @@ -953,103 +952,6 @@ StatusWith<std::vector<uint32_t>> MatchExpressionParser::_parseBitPositionsArray return bitPositions; } -StatusWithMatchExpression MatchExpressionParser::ExtensionsCallback::parseWhere( - BSONElement where) const { - return {Status(ErrorCodes::NoMatchParseContext, "no context for parsing $where")}; -} - -StatusWithMatchExpression MatchExpressionParser::ExtensionsCallback::parseText( - BSONElement text) const { - return {Status(ErrorCodes::NoMatchParseContext, "no context for parsing $text")}; -} - -StatusWith<WhereMatchExpressionBase::WhereParams> -MatchExpressionParser::ExtensionsCallback::extractWhereMatchExpressionParams(BSONElement where) { - WhereMatchExpressionBase::WhereParams params; - - switch (where.type()) { - case mongo::String: - case mongo::Code: - params.code = where._asCode(); - params.scope = BSONObj(); - break; - case mongo::CodeWScope: - params.code = where._asCode(); - params.scope = where.codeWScopeObject().getOwned(); - break; - default: - return {ErrorCodes::BadValue, "$where got bad type"}; - } - - if (params.code.empty()) { - return {ErrorCodes::BadValue, "code for $where cannot be empty"}; - } - - return params; -} - -StatusWith<TextMatchExpressionBase::TextParams> -MatchExpressionParser::ExtensionsCallback::extractTextMatchExpressionParams(BSONElement text) { - TextMatchExpressionBase::TextParams params; - if (text.type() != Object) { - return {ErrorCodes::BadValue, "$text expects an object"}; - } - BSONObj queryObj = text.Obj(); - - // - // Parse required fields. - // - - Status queryStatus = bsonExtractStringField(queryObj, "$search", ¶ms.query); - if (!queryStatus.isOK()) { - return queryStatus; - } - - // - // Parse optional fields. - // - - int expectedFieldCount = 1; - - Status languageStatus = bsonExtractStringField(queryObj, "$language", ¶ms.language); - if (languageStatus == ErrorCodes::TypeMismatch) { - return languageStatus; - } else if (languageStatus == ErrorCodes::NoSuchKey) { - params.language = string(); - } else { - invariantOK(languageStatus); - expectedFieldCount++; - } - - Status caseSensitiveStatus = - bsonExtractBooleanField(queryObj, "$caseSensitive", ¶ms.caseSensitive); - if (caseSensitiveStatus == ErrorCodes::TypeMismatch) { - return caseSensitiveStatus; - } else if (caseSensitiveStatus == ErrorCodes::NoSuchKey) { - params.caseSensitive = TextMatchExpressionBase::kCaseSensitiveDefault; - } else { - invariantOK(caseSensitiveStatus); - expectedFieldCount++; - } - - Status diacriticSensitiveStatus = - bsonExtractBooleanField(queryObj, "$diacriticSensitive", ¶ms.diacriticSensitive); - if (diacriticSensitiveStatus == ErrorCodes::TypeMismatch) { - return diacriticSensitiveStatus; - } else if (diacriticSensitiveStatus == ErrorCodes::NoSuchKey) { - params.diacriticSensitive = TextMatchExpressionBase::kDiacriticSensitiveDefault; - } else { - invariantOK(diacriticSensitiveStatus); - expectedFieldCount++; - } - - if (queryObj.nFields() != expectedFieldCount) { - return {ErrorCodes::BadValue, "extra fields in $text"}; - } - - return {std::move(params)}; -} - // Geo StatusWithMatchExpression expressionParserGeoCallbackDefault(const char* name, int type, diff --git a/src/mongo/db/matcher/expression_parser.h b/src/mongo/db/matcher/expression_parser.h index 5af324291da..465928ab184 100644 --- a/src/mongo/db/matcher/expression_parser.h +++ b/src/mongo/db/matcher/expression_parser.h @@ -35,50 +35,16 @@ #include "mongo/db/matcher/expression.h" #include "mongo/db/matcher/expression_leaf.h" #include "mongo/db/matcher/expression_tree.h" -#include "mongo/db/matcher/expression_text_base.h" -#include "mongo/db/matcher/expression_where_base.h" +#include "mongo/db/matcher/extensions_callback.h" #include "mongo/stdx/functional.h" namespace mongo { class OperationContext; -typedef StatusWith<std::unique_ptr<MatchExpression>> StatusWithMatchExpression; - class MatchExpressionParser { public: /** - * Certain match clauses (the "extension" clauses, namely $text and $where) require context in - * order to perform parsing. This context is captured inside of an ExtensionsCallback object. - * - * The default implementations of parseText() and parseWhere() simply return an error Status. - * Instead of constructing an ExtensionsCallback object directly, an instance of one of the - * derived classes (ExtensionsCallbackReal or ExtensionsCallbackNoop) should generally be used - * instead. - */ - class ExtensionsCallback { - public: - virtual StatusWithMatchExpression parseText(BSONElement text) const; - - virtual StatusWithMatchExpression parseWhere(BSONElement where) const; - - virtual ~ExtensionsCallback() {} - - protected: - /** - * Helper method which extracts parameters from the given $text element. - */ - static StatusWith<TextMatchExpressionBase::TextParams> extractTextMatchExpressionParams( - BSONElement text); - - /** - * Helper method which extracts parameters from the given $where element. - */ - static StatusWith<WhereMatchExpressionBase::WhereParams> extractWhereMatchExpressionParams( - BSONElement where); - }; - - /** * caller has to maintain ownership obj * the tree has views (BSONElement) into obj */ diff --git a/src/mongo/db/matcher/extensions_callback.cpp b/src/mongo/db/matcher/extensions_callback.cpp new file mode 100644 index 00000000000..a2fd775865b --- /dev/null +++ b/src/mongo/db/matcher/extensions_callback.cpp @@ -0,0 +1,132 @@ +/** + * Copyright (C) 2015 MongoDB Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the GNU Affero General Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#include "mongo/platform/basic.h" + +#include "mongo/db/matcher/extensions_callback.h" + +#include "mongo/bson/util/bson_extract.h" + +namespace mongo { + +StatusWithMatchExpression ExtensionsCallback::parseWhere(BSONElement where) const { + return {Status(ErrorCodes::NoMatchParseContext, "no context for parsing $where")}; +} + +StatusWithMatchExpression ExtensionsCallback::parseText(BSONElement text) const { + return {Status(ErrorCodes::NoMatchParseContext, "no context for parsing $text")}; +} + +StatusWith<TextMatchExpressionBase::TextParams> +ExtensionsCallback::extractTextMatchExpressionParams(BSONElement text) { + TextMatchExpressionBase::TextParams params; + if (text.type() != Object) { + return {ErrorCodes::BadValue, "$text expects an object"}; + } + BSONObj queryObj = text.Obj(); + + // + // Parse required fields. + // + + Status queryStatus = bsonExtractStringField(queryObj, "$search", ¶ms.query); + if (!queryStatus.isOK()) { + return queryStatus; + } + + // + // Parse optional fields. + // + + int expectedFieldCount = 1; + + Status languageStatus = bsonExtractStringField(queryObj, "$language", ¶ms.language); + if (languageStatus == ErrorCodes::TypeMismatch) { + return languageStatus; + } else if (languageStatus == ErrorCodes::NoSuchKey) { + params.language = std::string(); + } else { + invariantOK(languageStatus); + expectedFieldCount++; + } + + Status caseSensitiveStatus = + bsonExtractBooleanField(queryObj, "$caseSensitive", ¶ms.caseSensitive); + if (caseSensitiveStatus == ErrorCodes::TypeMismatch) { + return caseSensitiveStatus; + } else if (caseSensitiveStatus == ErrorCodes::NoSuchKey) { + params.caseSensitive = TextMatchExpressionBase::kCaseSensitiveDefault; + } else { + invariantOK(caseSensitiveStatus); + expectedFieldCount++; + } + + Status diacriticSensitiveStatus = + bsonExtractBooleanField(queryObj, "$diacriticSensitive", ¶ms.diacriticSensitive); + if (diacriticSensitiveStatus == ErrorCodes::TypeMismatch) { + return diacriticSensitiveStatus; + } else if (diacriticSensitiveStatus == ErrorCodes::NoSuchKey) { + params.diacriticSensitive = TextMatchExpressionBase::kDiacriticSensitiveDefault; + } else { + invariantOK(diacriticSensitiveStatus); + expectedFieldCount++; + } + + if (queryObj.nFields() != expectedFieldCount) { + return {ErrorCodes::BadValue, "extra fields in $text"}; + } + + return {std::move(params)}; +} + +StatusWith<WhereMatchExpressionBase::WhereParams> +ExtensionsCallback::extractWhereMatchExpressionParams(BSONElement where) { + WhereMatchExpressionBase::WhereParams params; + + switch (where.type()) { + case mongo::String: + case mongo::Code: + params.code = where._asCode(); + params.scope = BSONObj(); + break; + case mongo::CodeWScope: + params.code = where._asCode(); + params.scope = where.codeWScopeObject().getOwned(); + break; + default: + return {ErrorCodes::BadValue, "$where got bad type"}; + } + + if (params.code.empty()) { + return {ErrorCodes::BadValue, "code for $where cannot be empty"}; + } + + return params; +} + +} // namespace mongo diff --git a/src/mongo/db/matcher/extensions_callback.h b/src/mongo/db/matcher/extensions_callback.h new file mode 100644 index 00000000000..869d90ef8f3 --- /dev/null +++ b/src/mongo/db/matcher/extensions_callback.h @@ -0,0 +1,68 @@ +/** + * Copyright (C) 2015 MongoDB Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the GNU Affero General Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#pragma once + +#include "mongo/db/matcher/expression.h" +#include "mongo/db/matcher/expression_text_base.h" +#include "mongo/db/matcher/expression_where_base.h" + +namespace mongo { + +/** + * Certain match clauses (the "extension" clauses, namely $text and $where) require context in + * order to perform parsing. This context is captured inside of an ExtensionsCallback object. + * + * The default implementations of parseText() and parseWhere() simply return an error Status. + * Instead of constructing an ExtensionsCallback object directly, an instance of one of the + * derived classes (ExtensionsCallbackReal or ExtensionsCallbackNoop) should generally be used + * instead. + */ +class ExtensionsCallback { +public: + virtual StatusWithMatchExpression parseText(BSONElement text) const; + + virtual StatusWithMatchExpression parseWhere(BSONElement where) const; + + virtual ~ExtensionsCallback() {} + +protected: + /** + * Helper method which extracts parameters from the given $text element. + */ + static StatusWith<TextMatchExpressionBase::TextParams> extractTextMatchExpressionParams( + BSONElement text); + + /** + * Helper method which extracts parameters from the given $where element. + */ + static StatusWith<WhereMatchExpressionBase::WhereParams> extractWhereMatchExpressionParams( + BSONElement where); +}; + +} // namespace mongo diff --git a/src/mongo/db/matcher/extensions_callback_noop.h b/src/mongo/db/matcher/extensions_callback_noop.h index b66955add43..127e1d422a6 100644 --- a/src/mongo/db/matcher/extensions_callback_noop.h +++ b/src/mongo/db/matcher/extensions_callback_noop.h @@ -28,7 +28,7 @@ #pragma once -#include "mongo/db/matcher/expression_parser.h" +#include "mongo/db/matcher/extensions_callback.h" namespace mongo { @@ -37,7 +37,7 @@ namespace mongo { * be used for matching. It should be used when parsing context is not available (for example, when * the relevant namespace does not exist, or in mongos). */ -class ExtensionsCallbackNoop : public MatchExpressionParser::ExtensionsCallback { +class ExtensionsCallbackNoop : public ExtensionsCallback { public: /** * Returns a TextNoOpMatchExpression, or an error Status if parsing fails. diff --git a/src/mongo/db/matcher/extensions_callback_real.h b/src/mongo/db/matcher/extensions_callback_real.h index 6d4caf5c286..45b97e4b9c3 100644 --- a/src/mongo/db/matcher/extensions_callback_real.h +++ b/src/mongo/db/matcher/extensions_callback_real.h @@ -28,17 +28,18 @@ #pragma once -#include "mongo/db/matcher/expression_parser.h" +#include "mongo/db/matcher/extensions_callback.h" namespace mongo { class NamespaceString; +class OperationContext; /** * ExtensionsCallbackReal uses the provided OperationContext and namespace to capture context * necessary for parsing $text and $where clauses. */ -class ExtensionsCallbackReal : public MatchExpressionParser::ExtensionsCallback { +class ExtensionsCallbackReal : public ExtensionsCallback { public: /** * Does not take ownership of 'nss' or 'txn'. diff --git a/src/mongo/db/matcher/matcher.cpp b/src/mongo/db/matcher/matcher.cpp index 1275a5c4408..c0ed2bf6985 100644 --- a/src/mongo/db/matcher/matcher.cpp +++ b/src/mongo/db/matcher/matcher.cpp @@ -41,8 +41,7 @@ namespace mongo { -Matcher::Matcher(const BSONObj& pattern, - const MatchExpressionParser::ExtensionsCallback& extensionsCallback) +Matcher::Matcher(const BSONObj& pattern, const ExtensionsCallback& extensionsCallback) : _pattern(pattern) { StatusWithMatchExpression statusWithMatcher = MatchExpressionParser::parse(pattern, extensionsCallback); diff --git a/src/mongo/db/matcher/matcher.h b/src/mongo/db/matcher/matcher.h index c1369c154cf..e49602804a2 100644 --- a/src/mongo/db/matcher/matcher.h +++ b/src/mongo/db/matcher/matcher.h @@ -49,8 +49,7 @@ class Matcher { public: explicit Matcher(const BSONObj& pattern, - const MatchExpressionParser::ExtensionsCallback& extensionsCallback = - MatchExpressionParser::ExtensionsCallback()); + const ExtensionsCallback& extensionsCallback = ExtensionsCallback()); bool matches(const BSONObj& doc, MatchDetails* details = NULL) const; diff --git a/src/mongo/db/ops/modifier_pull.cpp b/src/mongo/db/ops/modifier_pull.cpp index 530ecfffb5e..ac7e5c41e8c 100644 --- a/src/mongo/db/ops/modifier_pull.cpp +++ b/src/mongo/db/ops/modifier_pull.cpp @@ -118,7 +118,7 @@ Status ModifierPull::init(const BSONElement& modExpr, const Options& opts, bool* // Build the matcher around the object we built above. Currently, we do not allow $pull // operations to contain $text/$where clauses, so preserving this behaviour. StatusWithMatchExpression parseResult = - MatchExpressionParser::parse(_exprObj, MatchExpressionParser::ExtensionsCallback()); + MatchExpressionParser::parse(_exprObj, ExtensionsCallback()); if (!parseResult.isOK()) { return parseResult.getStatus(); } diff --git a/src/mongo/db/query/canonical_query.cpp b/src/mongo/db/query/canonical_query.cpp index 12fdd177746..ed22674e0db 100644 --- a/src/mongo/db/query/canonical_query.cpp +++ b/src/mongo/db/query/canonical_query.cpp @@ -102,9 +102,7 @@ bool matchExpressionLessThan(const MatchExpression* lhs, const MatchExpression* // static StatusWith<std::unique_ptr<CanonicalQuery>> CanonicalQuery::canonicalize( - NamespaceString nss, - const BSONObj& query, - const MatchExpressionParser::ExtensionsCallback& extensionsCallback) { + NamespaceString nss, const BSONObj& query, const ExtensionsCallback& extensionsCallback) { const BSONObj emptyObj; return CanonicalQuery::canonicalize( std::move(nss), query, emptyObj, emptyObj, 0, 0, extensionsCallback); @@ -115,7 +113,7 @@ StatusWith<std::unique_ptr<CanonicalQuery>> CanonicalQuery::canonicalize( NamespaceString nss, const BSONObj& query, bool explain, - const MatchExpressionParser::ExtensionsCallback& extensionsCallback) { + const ExtensionsCallback& extensionsCallback) { const BSONObj emptyObj; return CanonicalQuery::canonicalize(std::move(nss), query, @@ -137,7 +135,7 @@ StatusWith<std::unique_ptr<CanonicalQuery>> CanonicalQuery::canonicalize( const BSONObj& query, long long skip, long long limit, - const MatchExpressionParser::ExtensionsCallback& extensionsCallback) { + const ExtensionsCallback& extensionsCallback) { const BSONObj emptyObj; return CanonicalQuery::canonicalize( std::move(nss), query, emptyObj, emptyObj, skip, limit, extensionsCallback); @@ -149,7 +147,7 @@ StatusWith<std::unique_ptr<CanonicalQuery>> CanonicalQuery::canonicalize( const BSONObj& query, const BSONObj& sort, const BSONObj& proj, - const MatchExpressionParser::ExtensionsCallback& extensionsCallback) { + const ExtensionsCallback& extensionsCallback) { return CanonicalQuery::canonicalize( std::move(nss), query, sort, proj, 0, 0, extensionsCallback); } @@ -162,7 +160,7 @@ StatusWith<std::unique_ptr<CanonicalQuery>> CanonicalQuery::canonicalize( const BSONObj& proj, long long skip, long long limit, - const MatchExpressionParser::ExtensionsCallback& extensionsCallback) { + const ExtensionsCallback& extensionsCallback) { const BSONObj emptyObj; return CanonicalQuery::canonicalize( std::move(nss), query, sort, proj, skip, limit, emptyObj, extensionsCallback); @@ -177,7 +175,7 @@ StatusWith<std::unique_ptr<CanonicalQuery>> CanonicalQuery::canonicalize( long long skip, long long limit, const BSONObj& hint, - const MatchExpressionParser::ExtensionsCallback& extensionsCallback) { + const ExtensionsCallback& extensionsCallback) { const BSONObj emptyObj; return CanonicalQuery::canonicalize(std::move(nss), query, @@ -199,7 +197,7 @@ StatusWith<std::unique_ptr<CanonicalQuery>> CanonicalQuery::canonicalize( // static StatusWith<std::unique_ptr<CanonicalQuery>> CanonicalQuery::canonicalize( - const QueryMessage& qm, const MatchExpressionParser::ExtensionsCallback& extensionsCallback) { + const QueryMessage& qm, const ExtensionsCallback& extensionsCallback) { // Make LiteParsedQuery. auto lpqStatus = LiteParsedQuery::fromLegacyQueryMessage(qm); if (!lpqStatus.isOK()) { @@ -211,7 +209,7 @@ StatusWith<std::unique_ptr<CanonicalQuery>> CanonicalQuery::canonicalize( // static StatusWith<std::unique_ptr<CanonicalQuery>> CanonicalQuery::canonicalize( - LiteParsedQuery* lpq, const MatchExpressionParser::ExtensionsCallback& extensionsCallback) { + LiteParsedQuery* lpq, const ExtensionsCallback& extensionsCallback) { std::unique_ptr<LiteParsedQuery> autoLpq(lpq); // Make MatchExpression. @@ -237,7 +235,7 @@ StatusWith<std::unique_ptr<CanonicalQuery>> CanonicalQuery::canonicalize( StatusWith<std::unique_ptr<CanonicalQuery>> CanonicalQuery::canonicalize( const CanonicalQuery& baseQuery, MatchExpression* root, - const MatchExpressionParser::ExtensionsCallback& extensionsCallback) { + const ExtensionsCallback& extensionsCallback) { // TODO: we should be passing the filter corresponding to 'root' to the LPQ rather than the base // query's filter, baseQuery.getParsed().getFilter(). BSONObj emptyObj; @@ -281,7 +279,7 @@ StatusWith<std::unique_ptr<CanonicalQuery>> CanonicalQuery::canonicalize( const BSONObj& maxObj, bool snapshot, bool explain, - const MatchExpressionParser::ExtensionsCallback& extensionsCallback) { + const ExtensionsCallback& extensionsCallback) { // Pass empty sort and projection. BSONObj emptyObj; @@ -312,7 +310,7 @@ StatusWith<std::unique_ptr<CanonicalQuery>> CanonicalQuery::canonicalize( } Status CanonicalQuery::init(LiteParsedQuery* lpq, - const MatchExpressionParser::ExtensionsCallback& extensionsCallback, + const ExtensionsCallback& extensionsCallback, MatchExpression* root) { _pq.reset(lpq); diff --git a/src/mongo/db/query/canonical_query.h b/src/mongo/db/query/canonical_query.h index 6025770b2b9..451b81e543e 100644 --- a/src/mongo/db/query/canonical_query.h +++ b/src/mongo/db/query/canonical_query.h @@ -48,8 +48,7 @@ public: */ static StatusWith<std::unique_ptr<CanonicalQuery>> canonicalize( const QueryMessage& qm, - const MatchExpressionParser::ExtensionsCallback& extensionsCallback = - MatchExpressionParser::ExtensionsCallback()); + const ExtensionsCallback& extensionsCallback = ExtensionsCallback()); /** * Takes ownership of 'lpq'. @@ -60,9 +59,7 @@ public: * Used for finds using the find command path. */ static StatusWith<std::unique_ptr<CanonicalQuery>> canonicalize( - LiteParsedQuery* lpq, - const MatchExpressionParser::ExtensionsCallback& extensionsCallback = - MatchExpressionParser::ExtensionsCallback()); + LiteParsedQuery* lpq, const ExtensionsCallback& extensionsCallback = ExtensionsCallback()); /** * For testing or for internal clients to use. @@ -78,37 +75,32 @@ public: static StatusWith<std::unique_ptr<CanonicalQuery>> canonicalize( const CanonicalQuery& baseQuery, MatchExpression* root, - const MatchExpressionParser::ExtensionsCallback& extensionsCallback = - MatchExpressionParser::ExtensionsCallback()); + const ExtensionsCallback& extensionsCallback = ExtensionsCallback()); static StatusWith<std::unique_ptr<CanonicalQuery>> canonicalize( NamespaceString nss, const BSONObj& query, - const MatchExpressionParser::ExtensionsCallback& extensionsCallback = - MatchExpressionParser::ExtensionsCallback()); + const ExtensionsCallback& extensionsCallback = ExtensionsCallback()); static StatusWith<std::unique_ptr<CanonicalQuery>> canonicalize( NamespaceString nss, const BSONObj& query, bool explain, - const MatchExpressionParser::ExtensionsCallback& extensionsCallback = - MatchExpressionParser::ExtensionsCallback()); + const ExtensionsCallback& extensionsCallback = ExtensionsCallback()); static StatusWith<std::unique_ptr<CanonicalQuery>> canonicalize( NamespaceString nss, const BSONObj& query, long long skip, long long limit, - const MatchExpressionParser::ExtensionsCallback& extensionsCallback = - MatchExpressionParser::ExtensionsCallback()); + const ExtensionsCallback& extensionsCallback = ExtensionsCallback()); static StatusWith<std::unique_ptr<CanonicalQuery>> canonicalize( NamespaceString nss, const BSONObj& query, const BSONObj& sort, const BSONObj& proj, - const MatchExpressionParser::ExtensionsCallback& extensionsCallback = - MatchExpressionParser::ExtensionsCallback()); + const ExtensionsCallback& extensionsCallback = ExtensionsCallback()); static StatusWith<std::unique_ptr<CanonicalQuery>> canonicalize( NamespaceString nss, @@ -117,8 +109,7 @@ public: const BSONObj& proj, long long skip, long long limit, - const MatchExpressionParser::ExtensionsCallback& extensionsCallback = - MatchExpressionParser::ExtensionsCallback()); + const ExtensionsCallback& extensionsCallback = ExtensionsCallback()); static StatusWith<std::unique_ptr<CanonicalQuery>> canonicalize( NamespaceString nss, @@ -128,8 +119,7 @@ public: long long skip, long long limit, const BSONObj& hint, - const MatchExpressionParser::ExtensionsCallback& extensionsCallback = - MatchExpressionParser::ExtensionsCallback()); + const ExtensionsCallback& extensionsCallback = ExtensionsCallback()); static StatusWith<std::unique_ptr<CanonicalQuery>> canonicalize( NamespaceString nss, @@ -143,8 +133,7 @@ public: const BSONObj& maxObj, bool snapshot, bool explain, - const MatchExpressionParser::ExtensionsCallback& extensionsCallback = - MatchExpressionParser::ExtensionsCallback()); + const ExtensionsCallback& extensionsCallback = ExtensionsCallback()); /** * Returns true if "query" describes an exact-match query on _id, possibly with @@ -216,7 +205,7 @@ private: * Takes ownership of 'root' and 'lpq'. */ Status init(LiteParsedQuery* lpq, - const MatchExpressionParser::ExtensionsCallback& extensionsCallback, + const ExtensionsCallback& extensionsCallback, MatchExpression* root); std::unique_ptr<LiteParsedQuery> _pq; diff --git a/src/mongo/db/query/get_executor.cpp b/src/mongo/db/query/get_executor.cpp index 497f1221e57..592976395ee 100644 --- a/src/mongo/db/query/get_executor.cpp +++ b/src/mongo/db/query/get_executor.cpp @@ -1159,7 +1159,7 @@ StatusWith<unique_ptr<PlanExecutor>> getExecutorCount(OperationContext* txn, unique_ptr<CanonicalQuery> cq; if (!request.getQuery().isEmpty() || !request.getHint().isEmpty()) { // If query or hint is not empty, canonicalize the query before working with collection. - typedef MatchExpressionParser::ExtensionsCallback ExtensionsCallback; + typedef ExtensionsCallback ExtensionsCallback; auto statusWithCQ = CanonicalQuery::canonicalize( request.getNs(), request.getQuery(), diff --git a/src/mongo/db/query/parsed_projection.cpp b/src/mongo/db/query/parsed_projection.cpp index b6e086be320..b977931613c 100644 --- a/src/mongo/db/query/parsed_projection.cpp +++ b/src/mongo/db/query/parsed_projection.cpp @@ -48,7 +48,7 @@ using std::string; Status ParsedProjection::make(const BSONObj& spec, const MatchExpression* const query, ParsedProjection** out, - const MatchExpressionParser::ExtensionsCallback& extensionsCallback) { + const ExtensionsCallback& extensionsCallback) { // Whether we're including or excluding fields. enum class IncludeExclude { kUninitialized, kInclude, kExclude }; IncludeExclude includeExclude = IncludeExclude::kUninitialized; diff --git a/src/mongo/db/query/parsed_projection.h b/src/mongo/db/query/parsed_projection.h index 2726e043ac3..06571199d89 100644 --- a/src/mongo/db/query/parsed_projection.h +++ b/src/mongo/db/query/parsed_projection.h @@ -48,8 +48,7 @@ public: static Status make(const BSONObj& spec, const MatchExpression* const query, ParsedProjection** out, - const MatchExpressionParser::ExtensionsCallback& extensionsCallback = - MatchExpressionParser::ExtensionsCallback()); + const ExtensionsCallback& extensionsCallback = ExtensionsCallback()); /** * Returns true if the projection requires match details from the query, diff --git a/src/mongo/dbtests/matchertests.cpp b/src/mongo/dbtests/matchertests.cpp index 2d009406e24..f700a6f1ba4 100644 --- a/src/mongo/dbtests/matchertests.cpp +++ b/src/mongo/dbtests/matchertests.cpp @@ -57,7 +57,7 @@ class Basic { public: void run() { BSONObj query = fromjson("{\"a\":\"b\"}"); - M m(query, MatchExpressionParser::ExtensionsCallback()); + M m(query, ExtensionsCallback()); ASSERT(m.matches(fromjson("{\"a\":\"b\"}"))); } }; @@ -67,7 +67,7 @@ class DoubleEqual { public: void run() { BSONObj query = fromjson("{\"a\":5}"); - M m(query, MatchExpressionParser::ExtensionsCallback()); + M m(query, ExtensionsCallback()); ASSERT(m.matches(fromjson("{\"a\":5}"))); } }; @@ -78,7 +78,7 @@ public: void run() { BSONObjBuilder query; query.append("a", 5); - M m(query.done(), MatchExpressionParser::ExtensionsCallback()); + M m(query.done(), ExtensionsCallback()); ASSERT(m.matches(fromjson("{\"a\":5}"))); } }; @@ -88,7 +88,7 @@ class MixedNumericGt { public: void run() { BSONObj query = fromjson("{\"a\":{\"$gt\":4}}"); - M m(query, MatchExpressionParser::ExtensionsCallback()); + M m(query, ExtensionsCallback()); BSONObjBuilder b; b.append("a", 5); ASSERT(m.matches(b.done())); @@ -103,7 +103,7 @@ public: ASSERT_EQUALS(4, query["a"].embeddedObject()["$in"].embeddedObject()["0"].number()); ASSERT_EQUALS(NumberInt, query["a"].embeddedObject()["$in"].embeddedObject()["0"].type()); - M m(query, MatchExpressionParser::ExtensionsCallback()); + M m(query, ExtensionsCallback()); { BSONObjBuilder b; @@ -130,7 +130,7 @@ template <typename M> class MixedNumericEmbedded { public: void run() { - M m(BSON("a" << BSON("x" << 1)), MatchExpressionParser::ExtensionsCallback()); + M m(BSON("a" << BSON("x" << 1)), ExtensionsCallback()); ASSERT(m.matches(BSON("a" << BSON("x" << 1)))); ASSERT(m.matches(BSON("a" << BSON("x" << 1.0)))); } @@ -140,7 +140,7 @@ template <typename M> class Size { public: void run() { - M m(fromjson("{a:{$size:4}}"), MatchExpressionParser::ExtensionsCallback()); + M m(fromjson("{a:{$size:4}}"), ExtensionsCallback()); ASSERT(m.matches(fromjson("{a:[1,2,3,4]}"))); ASSERT(!m.matches(fromjson("{a:[1,2,3]}"))); ASSERT(!m.matches(fromjson("{a:[1,2,3,'a','b']}"))); @@ -152,8 +152,7 @@ template <typename M> class WithinBox { public: void run() { - M m(fromjson("{loc:{$within:{$box:[{x: 4, y:4},[6,6]]}}}"), - MatchExpressionParser::ExtensionsCallback()); + M m(fromjson("{loc:{$within:{$box:[{x: 4, y:4},[6,6]]}}}"), ExtensionsCallback()); ASSERT(!m.matches(fromjson("{loc: [3,4]}"))); ASSERT(m.matches(fromjson("{loc: [4,4]}"))); ASSERT(m.matches(fromjson("{loc: [5,5]}"))); @@ -167,7 +166,7 @@ class WithinPolygon { public: void run() { M m(fromjson("{loc:{$within:{$polygon:[{x:0,y:0},[0,5],[5,5],[5,0]]}}}"), - MatchExpressionParser::ExtensionsCallback()); + ExtensionsCallback()); ASSERT(m.matches(fromjson("{loc: [3,4]}"))); ASSERT(m.matches(fromjson("{loc: [4,4]}"))); ASSERT(m.matches(fromjson("{loc: {x:5,y:5}}"))); @@ -180,8 +179,7 @@ template <typename M> class WithinCenter { public: void run() { - M m(fromjson("{loc:{$within:{$center:[{x:30,y:30},10]}}}"), - MatchExpressionParser::ExtensionsCallback()); + M m(fromjson("{loc:{$within:{$center:[{x:30,y:30},10]}}}"), ExtensionsCallback()); ASSERT(!m.matches(fromjson("{loc: [3,4]}"))); ASSERT(m.matches(fromjson("{loc: {x:30,y:30}}"))); ASSERT(m.matches(fromjson("{loc: [20,30]}"))); @@ -197,7 +195,7 @@ template <typename M> class ElemMatchKey { public: void run() { - M matcher(BSON("a.b" << 1), MatchExpressionParser::ExtensionsCallback()); + M matcher(BSON("a.b" << 1), ExtensionsCallback()); MatchDetails details; details.requestElemMatchKey(); ASSERT(!details.hasElemMatchKey()); @@ -228,7 +226,7 @@ template <typename M> class TimingBase { public: long dotime(const BSONObj& patt, const BSONObj& obj) { - M m(patt, MatchExpressionParser::ExtensionsCallback()); + M m(patt, ExtensionsCallback()); Timer t; for (int i = 0; i < 900000; i++) { if (!m.matches(obj)) { |