summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Storch <david.storch@10gen.com>2017-05-12 16:49:37 -0400
committerDavid Storch <david.storch@10gen.com>2017-05-19 16:14:15 -0400
commit2aaa0eafa5f1c6e1c43c1f42fcf7975722c3fbfe (patch)
tree072ab094da50b2c2c2a7fae0ec709b82315940ab /src
parent344de09ffc51bbc7786269917ebd1b417b940a7a (diff)
downloadmongo-2aaa0eafa5f1c6e1c43c1f42fcf7975722c3fbfe.tar.gz
SERVER-27115 Allow $type on a renamed field to swap before the rename.
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/matcher/expression_algo.cpp6
-rw-r--r--src/mongo/db/matcher/expression_algo_test.cpp12
-rw-r--r--src/mongo/db/pipeline/pipeline_test.cpp6
3 files changed, 15 insertions, 9 deletions
diff --git a/src/mongo/db/matcher/expression_algo.cpp b/src/mongo/db/matcher/expression_algo.cpp
index 693ef9f55e9..a648d1a4b28 100644
--- a/src/mongo/db/matcher/expression_algo.cpp
+++ b/src/mongo/db/matcher/expression_algo.cpp
@@ -275,7 +275,7 @@ unique_ptr<MatchExpression> createNorOfNodes(std::vector<unique_ptr<MatchExpress
}
void applyRenamesToExpression(MatchExpression* expr, const StringMap<std::string>& renames) {
- if (expr->isArray() || expr->matchType() == MatchExpression::TYPE_OPERATOR) {
+ if (expr->isArray()) {
return;
}
@@ -419,8 +419,8 @@ bool isIndependentOf(const MatchExpression& expr, const std::set<std::string>& p
return true;
}
- // Certain kinds of match expressions are never considered independent.
- if (expr.isArray() || expr.matchType() == MatchExpression::TYPE_OPERATOR) {
+ // Array match expressions are never considered independent.
+ if (expr.isArray()) {
return false;
}
diff --git a/src/mongo/db/matcher/expression_algo_test.cpp b/src/mongo/db/matcher/expression_algo_test.cpp
index 14678945b4f..e02e41c27cc 100644
--- a/src/mongo/db/matcher/expression_algo_test.cpp
+++ b/src/mongo/db/matcher/expression_algo_test.cpp
@@ -1064,7 +1064,7 @@ TEST(SplitMatchExpression, ShouldNotMoveElemMatchValueAcrossRename) {
ASSERT_BSONOBJ_EQ(secondBob.obj(), fromjson("{a: {$elemMatch: {$eq: 3}}}"));
}
-TEST(SplitMatchExpression, ShouldNotMoveTypeAcrossRename) {
+TEST(SplitMatchExpression, ShouldMoveTypeAcrossRename) {
BSONObj matchPredicate = fromjson("{a: {$type: 16}}");
const CollatorInterface* collator = nullptr;
auto matcher = MatchExpressionParser::parse(matchPredicate, ExtensionsCallbackNoop(), collator);
@@ -1074,12 +1074,12 @@ TEST(SplitMatchExpression, ShouldNotMoveTypeAcrossRename) {
std::pair<unique_ptr<MatchExpression>, unique_ptr<MatchExpression>> splitExpr =
expression::splitMatchExpressionBy(std::move(matcher.getValue()), {}, renames);
- ASSERT_FALSE(splitExpr.first.get());
+ ASSERT_TRUE(splitExpr.first.get());
+ BSONObjBuilder firstBob;
+ splitExpr.first->serialize(&firstBob);
+ ASSERT_BSONOBJ_EQ(firstBob.obj(), fromjson("{c: {$type: 16}}"));
- ASSERT_TRUE(splitExpr.second.get());
- BSONObjBuilder secondBob;
- splitExpr.second->serialize(&secondBob);
- ASSERT_BSONOBJ_EQ(secondBob.obj(), fromjson("{a: {$type: 16}}"));
+ ASSERT_FALSE(splitExpr.second.get());
}
TEST(SplitMatchExpression, ShouldNotMoveSizeAcrossRename) {
diff --git a/src/mongo/db/pipeline/pipeline_test.cpp b/src/mongo/db/pipeline/pipeline_test.cpp
index 68dfeb35bad..e38263b9785 100644
--- a/src/mongo/db/pipeline/pipeline_test.cpp
+++ b/src/mongo/db/pipeline/pipeline_test.cpp
@@ -837,6 +837,12 @@ TEST(PipelineOptimizationTest, MatchCannotMoveAcrossProjectRenameOfDottedPath) {
assertPipelineOptimizesTo(inputPipe, outputPipe);
}
+TEST(PipelineOptimizationTest, MatchWithTypeShouldMoveAcrossRename) {
+ string inputPipe = "[{$addFields: {a: '$b'}}, {$match: {a: {$type: 4}}}]";
+ string outputPipe = "[{$match: {b: {$type: 4}}}, {$addFields: {a: '$b'}}]";
+ assertPipelineOptimizesTo(inputPipe, outputPipe);
+}
+
} // namespace Local
namespace Sharded {