summaryrefslogtreecommitdiff
path: root/src/mongo/db/query
diff options
context:
space:
mode:
authorMax Hirschhorn <max.hirschhorn@mongodb.com>2016-06-03 13:26:35 -0400
committerMax Hirschhorn <max.hirschhorn@mongodb.com>2016-06-03 13:26:35 -0400
commitcecbe424d32cbb475d9b0384d29b98a9fba9c89f (patch)
tree0ce2632b078fee8865f15a56cf07c684a8260c21 /src/mongo/db/query
parent8900002b731358b0beedadb2ceb4e3156de402b6 (diff)
downloadmongo-cecbe424d32cbb475d9b0384d29b98a9fba9c89f.tar.gz
SERVER-23114 Move functions involving dotted paths to separate library.
The ability to specify a dotted path (e.g. "a.b") to traverse through embedded objects and array elements isn't defined in the BSON specification and so it doesn't belong in our BSON library. The following functions have been defined within a 'dotted_path_support' namespace and accept an additional BSONObj as their first argument to replace the associated method on the BSONObj class. - extractElementAtPath() is functionally equivalent to BSONObj::getFieldDotted(). - extractElementAtPathOrArrayAlongPath() is functionally equivalent to BSONObj::getFieldDottedOrArray(). - extractAllElementsAlongPath() is functionally equivalent to BSONObj::getFieldsDotted(). - extractElementsBasedOnTemplate() is functionally equivalent to BSONObj::extractFields(). - compareObjectsAccordingToSort() is functionally equivalent to BSONObj::woSortOrder().
Diffstat (limited to 'src/mongo/db/query')
-rw-r--r--src/mongo/db/query/SConscript1
-rw-r--r--src/mongo/db/query/planner_access.cpp7
-rw-r--r--src/mongo/db/query/planner_analysis.cpp5
-rw-r--r--src/mongo/db/query/query_planner.cpp7
4 files changed, 15 insertions, 5 deletions
diff --git a/src/mongo/db/query/SConscript b/src/mongo/db/query/SConscript
index c588986617a..676f27d3cd5 100644
--- a/src/mongo/db/query/SConscript
+++ b/src/mongo/db/query/SConscript
@@ -29,6 +29,7 @@ env.Library(
],
LIBDEPS=[
"$BUILD_DIR/mongo/base",
+ "$BUILD_DIR/mongo/db/bson/dotted_path_support",
"$BUILD_DIR/mongo/db/index/expression_params",
"$BUILD_DIR/mongo/db/index_names",
"$BUILD_DIR/mongo/db/matcher/expression_algo",
diff --git a/src/mongo/db/query/planner_access.cpp b/src/mongo/db/query/planner_access.cpp
index c3172d5387d..349a25b99f7 100644
--- a/src/mongo/db/query/planner_access.cpp
+++ b/src/mongo/db/query/planner_access.cpp
@@ -36,6 +36,7 @@
#include <vector>
#include "mongo/base/owned_pointer_vector.h"
+#include "mongo/db/bson/dotted_path_support.h"
#include "mongo/db/matcher/expression_array.h"
#include "mongo/db/matcher/expression_geo.h"
#include "mongo/db/matcher/expression_text.h"
@@ -52,6 +53,8 @@ namespace {
using namespace mongo;
+namespace dps = ::mongo::dotted_path_support;
+
/**
* Text node functors.
*/
@@ -125,7 +128,7 @@ QuerySolutionNode* QueryPlannerAccess::makeCollectionScan(const CanonicalQuery&
// If the hint is {$natural: +-1} this changes the direction of the collection scan.
if (!query.getParsed().getHint().isEmpty()) {
- BSONElement natural = query.getParsed().getHint().getFieldDotted("$natural");
+ BSONElement natural = dps::extractElementAtPath(query.getParsed().getHint(), "$natural");
if (!natural.eoo()) {
csn->direction = natural.numberInt() >= 0 ? 1 : -1;
}
@@ -135,7 +138,7 @@ QuerySolutionNode* QueryPlannerAccess::makeCollectionScan(const CanonicalQuery&
// direction if both are specified.
const BSONObj& sortObj = query.getParsed().getSort();
if (!sortObj.isEmpty()) {
- BSONElement natural = sortObj.getFieldDotted("$natural");
+ BSONElement natural = dps::extractElementAtPath(sortObj, "$natural");
if (!natural.eoo()) {
csn->direction = natural.numberInt() >= 0 ? 1 : -1;
}
diff --git a/src/mongo/db/query/planner_analysis.cpp b/src/mongo/db/query/planner_analysis.cpp
index 1a507d16ef2..e7ab375b03c 100644
--- a/src/mongo/db/query/planner_analysis.cpp
+++ b/src/mongo/db/query/planner_analysis.cpp
@@ -33,6 +33,7 @@
#include <set>
#include <vector>
+#include "mongo/db/bson/dotted_path_support.h"
#include "mongo/db/index/expression_params.h"
#include "mongo/db/index/s2_common.h"
#include "mongo/db/jsobj.h"
@@ -48,6 +49,8 @@ using std::endl;
using std::string;
using std::vector;
+namespace dps = ::mongo::dotted_path_support;
+
//
// Helpers for bounds explosion AKA quick-and-dirty SERVER-1205.
//
@@ -472,7 +475,7 @@ QuerySolutionNode* QueryPlannerAnalysis::analyzeSort(const CanonicalQuery& query
// If the sort is $natural, we ignore it, assuming that the caller has detected that and
// outputted a collscan to satisfy the desired order.
- BSONElement natural = sortObj.getFieldDotted("$natural");
+ BSONElement natural = dps::extractElementAtPath(sortObj, "$natural");
if (!natural.eoo()) {
return solnRoot;
}
diff --git a/src/mongo/db/query/query_planner.cpp b/src/mongo/db/query/query_planner.cpp
index 2b76ac930f9..49905949142 100644
--- a/src/mongo/db/query/query_planner.cpp
+++ b/src/mongo/db/query/query_planner.cpp
@@ -35,6 +35,7 @@
#include <vector>
#include "mongo/client/dbclientinterface.h" // For QueryOption_foobar
+#include "mongo/db/bson/dotted_path_support.h"
#include "mongo/db/matcher/expression_algo.h"
#include "mongo/db/matcher/expression_geo.h"
#include "mongo/db/matcher/expression_text.h"
@@ -53,6 +54,8 @@ namespace mongo {
using std::unique_ptr;
using std::numeric_limits;
+namespace dps = ::mongo::dotted_path_support;
+
// Copied verbatim from db/index.h
static bool isIdIndex(const BSONObj& pattern) {
BSONObjIterator i(pattern);
@@ -460,8 +463,8 @@ Status QueryPlanner::plan(const CanonicalQuery& query,
if (!query.getParsed().getHint().isEmpty() || !query.getParsed().getSort().isEmpty()) {
BSONObj hintObj = query.getParsed().getHint();
BSONObj sortObj = query.getParsed().getSort();
- BSONElement naturalHint = hintObj.getFieldDotted("$natural");
- BSONElement naturalSort = sortObj.getFieldDotted("$natural");
+ BSONElement naturalHint = dps::extractElementAtPath(hintObj, "$natural");
+ BSONElement naturalSort = dps::extractElementAtPath(sortObj, "$natural");
// A hint overrides a $natural sort. This means that we don't force a table
// scan if there is a $natural sort with a non-$natural hint.