summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTess Avitabile <tess.avitabile@mongodb.com>2016-04-21 11:51:07 -0400
committerTess Avitabile <tess.avitabile@mongodb.com>2016-04-25 13:21:48 -0400
commit318c6da287732842463d6bd4eea565125dc22ab2 (patch)
tree11115311c216c32ac08fcc8c1bc6e649f87491bd
parent6b6a5e247c5eab54a270978a4c2e8564224b5bbb (diff)
downloadmongo-318c6da287732842463d6bd4eea565125dc22ab2.tar.gz
SERVER-23473 Add collation parameter to the mapReduce command
-rw-r--r--src/mongo/db/commands/mr.cpp10
-rw-r--r--src/mongo/db/commands/mr.h1
-rw-r--r--src/mongo/db/commands/mr_test.cpp39
3 files changed, 50 insertions, 0 deletions
diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp
index 155525578ee..b0898b1064a 100644
--- a/src/mongo/db/commands/mr.cpp
+++ b/src/mongo/db/commands/mr.cpp
@@ -336,6 +336,16 @@ Config::Config(const string& _dbname, const BSONObj& cmdObj) {
else
uassert(13609, "sort has to be blank or an Object", !s.trueValue());
+ BSONElement collationElt = cmdObj["collation"];
+ if (collationElt.type() == Object)
+ collation = collationElt.embeddedObjectUserCheck();
+ else
+ uassert(40082,
+ str::stream()
+ << "mapReduce 'collation' parameter must be of type Object but found type: "
+ << typeName(collationElt.type()),
+ collationElt.eoo());
+
if (cmdObj["limit"].isNumber())
limit = cmdObj["limit"].numberLong();
else
diff --git a/src/mongo/db/commands/mr.h b/src/mongo/db/commands/mr.h
index 3d967438179..3237e6f7238 100644
--- a/src/mongo/db/commands/mr.h
+++ b/src/mongo/db/commands/mr.h
@@ -206,6 +206,7 @@ public:
BSONObj filter;
BSONObj sort;
+ BSONObj collation;
long long limit;
// functions
diff --git a/src/mongo/db/commands/mr_test.cpp b/src/mongo/db/commands/mr_test.cpp
index 93e90851257..d58ca5326f2 100644
--- a/src/mongo/db/commands/mr_test.cpp
+++ b/src/mongo/db/commands/mr_test.cpp
@@ -208,4 +208,43 @@ TEST(ConfigOutputOptionsTest, parseOutputOptions) {
mr::Config::INMEMORY);
}
+TEST(ConfigTest, ParseCollation) {
+ std::string dbname = "myDB";
+ BSONObj collation = BSON("locale"
+ << "en_US");
+ BSONObjBuilder bob;
+ bob.append("mapReduce", "myCollection");
+ bob.appendCode("map", "function() { emit(0, 1); }");
+ bob.appendCode("reduce", "function(k, v) { return {count: 0}; }");
+ bob.append("out", "outCollection");
+ bob.append("collation", collation);
+ BSONObj cmdObj = bob.obj();
+ mr::Config config(dbname, cmdObj);
+ ASSERT_EQUALS(config.collation, collation);
+}
+
+TEST(ConfigTest, ParseNoCollation) {
+ std::string dbname = "myDB";
+ BSONObjBuilder bob;
+ bob.append("mapReduce", "myCollection");
+ bob.appendCode("map", "function() { emit(0, 1); }");
+ bob.appendCode("reduce", "function(k, v) { return {count: 0}; }");
+ bob.append("out", "outCollection");
+ BSONObj cmdObj = bob.obj();
+ mr::Config config(dbname, cmdObj);
+ ASSERT_EQUALS(config.collation, BSONObj());
+}
+
+TEST(ConfigTest, CollationNotAnObjectFailsToParse) {
+ std::string dbname = "myDB";
+ BSONObjBuilder bob;
+ bob.append("mapReduce", "myCollection");
+ bob.appendCode("map", "function() { emit(0, 1); }");
+ bob.appendCode("reduce", "function(k, v) { return {count: 0}; }");
+ bob.append("out", "outCollection");
+ bob.append("collation", "en_US");
+ BSONObj cmdObj = bob.obj();
+ ASSERT_THROWS(mr::Config(dbname, cmdObj), UserException);
+}
+
} // namespace