diff options
Diffstat (limited to 'src/mongo/db')
10 files changed, 50 insertions, 44 deletions
diff --git a/src/mongo/db/pipeline/document_source_replace_root.cpp b/src/mongo/db/pipeline/document_source_replace_root.cpp index b5def20495e..089ff2d9c98 100644 --- a/src/mongo/db/pipeline/document_source_replace_root.cpp +++ b/src/mongo/db/pipeline/document_source_replace_root.cpp @@ -80,7 +80,7 @@ public: _newRoot->optimize(); } - Document serialize(boost::optional<ExplainOptions::Verbosity> explain) const final { + Document serializeStageOptions(boost::optional<ExplainOptions::Verbosity> explain) const final { return Document{{"newRoot", _newRoot->serialize(static_cast<bool>(explain))}}; } diff --git a/src/mongo/db/pipeline/document_source_single_document_transformation.cpp b/src/mongo/db/pipeline/document_source_single_document_transformation.cpp index df363f8fde2..e425699e80a 100644 --- a/src/mongo/db/pipeline/document_source_single_document_transformation.cpp +++ b/src/mongo/db/pipeline/document_source_single_document_transformation.cpp @@ -76,7 +76,7 @@ void DocumentSourceSingleDocumentTransformation::doDispose() { Value DocumentSourceSingleDocumentTransformation::serialize( boost::optional<ExplainOptions::Verbosity> explain) const { - return Value(Document{{getSourceName(), _parsedTransform->serialize(explain)}}); + return Value(Document{{getSourceName(), _parsedTransform->serializeStageOptions(explain)}}); } Pipeline::SourceContainer::iterator DocumentSourceSingleDocumentTransformation::doOptimizeAt( diff --git a/src/mongo/db/pipeline/document_source_single_document_transformation.h b/src/mongo/db/pipeline/document_source_single_document_transformation.h index 108a13aa161..ee2141a2c8d 100644 --- a/src/mongo/db/pipeline/document_source_single_document_transformation.h +++ b/src/mongo/db/pipeline/document_source_single_document_transformation.h @@ -62,11 +62,17 @@ public: virtual Document applyTransformation(const Document& input) = 0; virtual TransformerType getType() const = 0; virtual void optimize() = 0; - virtual Document serialize(boost::optional<ExplainOptions::Verbosity> explain) const = 0; virtual DocumentSource::GetDepsReturn addDependencies(DepsTracker* deps) const = 0; virtual GetModPathsReturn getModifiedPaths() const = 0; /** + * Returns the document describing this stage, not including the stage name. For example, + * should return just {_id: 0, x: 1} for the stage parsed from {$project: {_id: 0, x: 1}}. + */ + virtual Document serializeStageOptions( + boost::optional<ExplainOptions::Verbosity> explain) const = 0; + + /** * Returns true if this transformer is an inclusion projection and is a subset of * 'proj', which must be a valid projection specification. For example, if this * TransformerInterface represents the inclusion projection diff --git a/src/mongo/db/pipeline/parsed_add_fields.h b/src/mongo/db/pipeline/parsed_add_fields.h index e0d60822ba3..f5e53284357 100644 --- a/src/mongo/db/pipeline/parsed_add_fields.h +++ b/src/mongo/db/pipeline/parsed_add_fields.h @@ -71,7 +71,7 @@ public: */ void parse(const BSONObj& spec) final; - Document serialize(boost::optional<ExplainOptions::Verbosity> explain) const final { + Document serializeStageOptions(boost::optional<ExplainOptions::Verbosity> explain) const final { MutableDocument output; _root->serialize(&output, explain); return output.freeze(); diff --git a/src/mongo/db/pipeline/parsed_add_fields_test.cpp b/src/mongo/db/pipeline/parsed_add_fields_test.cpp index 9a39b54ae8a..289e8eb1f33 100644 --- a/src/mongo/db/pipeline/parsed_add_fields_test.cpp +++ b/src/mongo/db/pipeline/parsed_add_fields_test.cpp @@ -175,13 +175,13 @@ TEST(ParsedAddFieldsSerialize, SerializesToCorrectForm) { fromjson("{a: {$add: [\"$a\", {$const: 2}]}, b: {d: {$const: 3}}, x: {y: {$const: 4}}}")); // Should be the same if we're serializing for explain or for internal use. - ASSERT_DOCUMENT_EQ(expectedSerialization, addition.serialize(boost::none)); + ASSERT_DOCUMENT_EQ(expectedSerialization, addition.serializeStageOptions(boost::none)); ASSERT_DOCUMENT_EQ(expectedSerialization, - addition.serialize(ExplainOptions::Verbosity::kQueryPlanner)); + addition.serializeStageOptions(ExplainOptions::Verbosity::kQueryPlanner)); ASSERT_DOCUMENT_EQ(expectedSerialization, - addition.serialize(ExplainOptions::Verbosity::kExecStats)); + addition.serializeStageOptions(ExplainOptions::Verbosity::kExecStats)); ASSERT_DOCUMENT_EQ(expectedSerialization, - addition.serialize(ExplainOptions::Verbosity::kExecAllPlans)); + addition.serializeStageOptions(ExplainOptions::Verbosity::kExecAllPlans)); } // Verify that serialize treats the _id field as any other field: including when explicity included. @@ -194,13 +194,13 @@ TEST(ParsedAddFieldsSerialize, AddsIdToSerializeWhenExplicitlyIncluded) { auto expectedSerialization = Document(fromjson("{_id: {$const: false}}")); // Should be the same if we're serializing for explain or for internal use. - ASSERT_DOCUMENT_EQ(expectedSerialization, addition.serialize(boost::none)); + ASSERT_DOCUMENT_EQ(expectedSerialization, addition.serializeStageOptions(boost::none)); ASSERT_DOCUMENT_EQ(expectedSerialization, - addition.serialize(ExplainOptions::Verbosity::kQueryPlanner)); + addition.serializeStageOptions(ExplainOptions::Verbosity::kQueryPlanner)); ASSERT_DOCUMENT_EQ(expectedSerialization, - addition.serialize(ExplainOptions::Verbosity::kExecStats)); + addition.serializeStageOptions(ExplainOptions::Verbosity::kExecStats)); ASSERT_DOCUMENT_EQ(expectedSerialization, - addition.serialize(ExplainOptions::Verbosity::kExecAllPlans)); + addition.serializeStageOptions(ExplainOptions::Verbosity::kExecAllPlans)); } // Verify that serialize treats the _id field as any other field: excluded when not explicitly @@ -216,13 +216,13 @@ TEST(ParsedAddFieldsSerialize, OmitsIdFromSerializeWhenNotIncluded) { auto expectedSerialization = Document(fromjson("{a: {$const: true}}")); // Should be the same if we're serializing for explain or for internal use. - ASSERT_DOCUMENT_EQ(expectedSerialization, addition.serialize(boost::none)); + ASSERT_DOCUMENT_EQ(expectedSerialization, addition.serializeStageOptions(boost::none)); ASSERT_DOCUMENT_EQ(expectedSerialization, - addition.serialize(ExplainOptions::Verbosity::kQueryPlanner)); + addition.serializeStageOptions(ExplainOptions::Verbosity::kQueryPlanner)); ASSERT_DOCUMENT_EQ(expectedSerialization, - addition.serialize(ExplainOptions::Verbosity::kExecStats)); + addition.serializeStageOptions(ExplainOptions::Verbosity::kExecStats)); ASSERT_DOCUMENT_EQ(expectedSerialization, - addition.serialize(ExplainOptions::Verbosity::kExecAllPlans)); + addition.serializeStageOptions(ExplainOptions::Verbosity::kExecAllPlans)); } // Verify that the $addFields stage optimizes expressions into simpler forms when possible. @@ -234,13 +234,13 @@ TEST(ParsedAddFieldsOptimize, OptimizesTopLevelExpressions) { auto expectedSerialization = Document{{"a", Document{{"$const", 3}}}}; // Should be the same if we're serializing for explain or for internal use. - ASSERT_DOCUMENT_EQ(expectedSerialization, addition.serialize(boost::none)); + ASSERT_DOCUMENT_EQ(expectedSerialization, addition.serializeStageOptions(boost::none)); ASSERT_DOCUMENT_EQ(expectedSerialization, - addition.serialize(ExplainOptions::Verbosity::kQueryPlanner)); + addition.serializeStageOptions(ExplainOptions::Verbosity::kQueryPlanner)); ASSERT_DOCUMENT_EQ(expectedSerialization, - addition.serialize(ExplainOptions::Verbosity::kExecStats)); + addition.serializeStageOptions(ExplainOptions::Verbosity::kExecStats)); ASSERT_DOCUMENT_EQ(expectedSerialization, - addition.serialize(ExplainOptions::Verbosity::kExecAllPlans)); + addition.serializeStageOptions(ExplainOptions::Verbosity::kExecAllPlans)); } // Verify that the $addFields stage optimizes expressions even when they are nested. @@ -252,13 +252,13 @@ TEST(ParsedAddFieldsOptimize, ShouldOptimizeNestedExpressions) { auto expectedSerialization = Document{{"a", Document{{"b", Document{{"$const", 3}}}}}}; // Should be the same if we're serializing for explain or for internal use. - ASSERT_DOCUMENT_EQ(expectedSerialization, addition.serialize(boost::none)); + ASSERT_DOCUMENT_EQ(expectedSerialization, addition.serializeStageOptions(boost::none)); ASSERT_DOCUMENT_EQ(expectedSerialization, - addition.serialize(ExplainOptions::Verbosity::kQueryPlanner)); + addition.serializeStageOptions(ExplainOptions::Verbosity::kQueryPlanner)); ASSERT_DOCUMENT_EQ(expectedSerialization, - addition.serialize(ExplainOptions::Verbosity::kExecStats)); + addition.serializeStageOptions(ExplainOptions::Verbosity::kExecStats)); ASSERT_DOCUMENT_EQ(expectedSerialization, - addition.serialize(ExplainOptions::Verbosity::kExecAllPlans)); + addition.serializeStageOptions(ExplainOptions::Verbosity::kExecAllPlans)); } // diff --git a/src/mongo/db/pipeline/parsed_exclusion_projection.cpp b/src/mongo/db/pipeline/parsed_exclusion_projection.cpp index b4d52ef77ed..7eca645c314 100644 --- a/src/mongo/db/pipeline/parsed_exclusion_projection.cpp +++ b/src/mongo/db/pipeline/parsed_exclusion_projection.cpp @@ -135,7 +135,7 @@ void ExclusionNode::addModifiedPaths(std::set<std::string>* modifiedPaths) const // ParsedExclusionProjection. // -Document ParsedExclusionProjection::serialize( +Document ParsedExclusionProjection::serializeStageOptions( boost::optional<ExplainOptions::Verbosity> explain) const { return _root->serialize(); } diff --git a/src/mongo/db/pipeline/parsed_exclusion_projection.h b/src/mongo/db/pipeline/parsed_exclusion_projection.h index de371df0ccd..3de597910bc 100644 --- a/src/mongo/db/pipeline/parsed_exclusion_projection.h +++ b/src/mongo/db/pipeline/parsed_exclusion_projection.h @@ -104,7 +104,7 @@ public: return TransformerType::kExclusionProjection; } - Document serialize(boost::optional<ExplainOptions::Verbosity> explain) const final; + Document serializeStageOptions(boost::optional<ExplainOptions::Verbosity> explain) const final; /** * Parses the projection specification given by 'spec', populating internal data structures. diff --git a/src/mongo/db/pipeline/parsed_exclusion_projection_test.cpp b/src/mongo/db/pipeline/parsed_exclusion_projection_test.cpp index a79950a13b3..348044018e9 100644 --- a/src/mongo/db/pipeline/parsed_exclusion_projection_test.cpp +++ b/src/mongo/db/pipeline/parsed_exclusion_projection_test.cpp @@ -87,7 +87,7 @@ TEST(ExclusionProjection, ShouldSerializeToEquivalentProjection) { // Converts numbers to bools, converts dotted paths to nested documents. Note order of excluded // fields is subject to change. - auto serialization = exclusion.serialize(boost::none); + auto serialization = exclusion.serializeStageOptions(boost::none); ASSERT_EQ(serialization.size(), 4UL); ASSERT_VALUE_EQ(serialization["a"], Value(false)); ASSERT_VALUE_EQ(serialization["_id"], Value(false)); diff --git a/src/mongo/db/pipeline/parsed_inclusion_projection.h b/src/mongo/db/pipeline/parsed_inclusion_projection.h index c42acc75e85..e93aa0fe736 100644 --- a/src/mongo/db/pipeline/parsed_inclusion_projection.h +++ b/src/mongo/db/pipeline/parsed_inclusion_projection.h @@ -199,7 +199,7 @@ public: /** * Serialize the projection. */ - Document serialize(boost::optional<ExplainOptions::Verbosity> explain) const final { + Document serializeStageOptions(boost::optional<ExplainOptions::Verbosity> explain) const final { MutableDocument output; if (_idExcluded) { output.addField("_id", Value(false)); diff --git a/src/mongo/db/pipeline/parsed_inclusion_projection_test.cpp b/src/mongo/db/pipeline/parsed_inclusion_projection_test.cpp index 4c1395504cd..ef77bb03943 100644 --- a/src/mongo/db/pipeline/parsed_inclusion_projection_test.cpp +++ b/src/mongo/db/pipeline/parsed_inclusion_projection_test.cpp @@ -138,13 +138,13 @@ TEST(InclusionProjection, ShouldSerializeToEquivalentProjection) { "{_id: true, a: {$add: [\"$a\", {$const: 2}]}, b: {d: true}, x: {y: {$const: 4}}}")); // Should be the same if we're serializing for explain or for internal use. - ASSERT_DOCUMENT_EQ(expectedSerialization, inclusion.serialize(boost::none)); + ASSERT_DOCUMENT_EQ(expectedSerialization, inclusion.serializeStageOptions(boost::none)); ASSERT_DOCUMENT_EQ(expectedSerialization, - inclusion.serialize(ExplainOptions::Verbosity::kQueryPlanner)); + inclusion.serializeStageOptions(ExplainOptions::Verbosity::kQueryPlanner)); ASSERT_DOCUMENT_EQ(expectedSerialization, - inclusion.serialize(ExplainOptions::Verbosity::kExecStats)); + inclusion.serializeStageOptions(ExplainOptions::Verbosity::kExecStats)); ASSERT_DOCUMENT_EQ(expectedSerialization, - inclusion.serialize(ExplainOptions::Verbosity::kExecAllPlans)); + inclusion.serializeStageOptions(ExplainOptions::Verbosity::kExecAllPlans)); } TEST(InclusionProjection, ShouldSerializeExplicitExclusionOfId) { @@ -156,13 +156,13 @@ TEST(InclusionProjection, ShouldSerializeExplicitExclusionOfId) { auto expectedSerialization = Document{{"_id", false}, {"a", true}}; // Should be the same if we're serializing for explain or for internal use. - ASSERT_DOCUMENT_EQ(expectedSerialization, inclusion.serialize(boost::none)); + ASSERT_DOCUMENT_EQ(expectedSerialization, inclusion.serializeStageOptions(boost::none)); ASSERT_DOCUMENT_EQ(expectedSerialization, - inclusion.serialize(ExplainOptions::Verbosity::kQueryPlanner)); + inclusion.serializeStageOptions(ExplainOptions::Verbosity::kQueryPlanner)); ASSERT_DOCUMENT_EQ(expectedSerialization, - inclusion.serialize(ExplainOptions::Verbosity::kExecStats)); + inclusion.serializeStageOptions(ExplainOptions::Verbosity::kExecStats)); ASSERT_DOCUMENT_EQ(expectedSerialization, - inclusion.serialize(ExplainOptions::Verbosity::kExecAllPlans)); + inclusion.serializeStageOptions(ExplainOptions::Verbosity::kExecAllPlans)); } @@ -176,13 +176,13 @@ TEST(InclusionProjection, ShouldOptimizeTopLevelExpressions) { auto expectedSerialization = Document{{"_id", true}, {"a", Document{{"$const", 3}}}}; // Should be the same if we're serializing for explain or for internal use. - ASSERT_DOCUMENT_EQ(expectedSerialization, inclusion.serialize(boost::none)); + ASSERT_DOCUMENT_EQ(expectedSerialization, inclusion.serializeStageOptions(boost::none)); ASSERT_DOCUMENT_EQ(expectedSerialization, - inclusion.serialize(ExplainOptions::Verbosity::kQueryPlanner)); + inclusion.serializeStageOptions(ExplainOptions::Verbosity::kQueryPlanner)); ASSERT_DOCUMENT_EQ(expectedSerialization, - inclusion.serialize(ExplainOptions::Verbosity::kExecStats)); + inclusion.serializeStageOptions(ExplainOptions::Verbosity::kExecStats)); ASSERT_DOCUMENT_EQ(expectedSerialization, - inclusion.serialize(ExplainOptions::Verbosity::kExecAllPlans)); + inclusion.serializeStageOptions(ExplainOptions::Verbosity::kExecAllPlans)); } TEST(InclusionProjection, ShouldOptimizeNestedExpressions) { @@ -196,13 +196,13 @@ TEST(InclusionProjection, ShouldOptimizeNestedExpressions) { Document{{"_id", true}, {"a", Document{{"b", Document{{"$const", 3}}}}}}; // Should be the same if we're serializing for explain or for internal use. - ASSERT_DOCUMENT_EQ(expectedSerialization, inclusion.serialize(boost::none)); + ASSERT_DOCUMENT_EQ(expectedSerialization, inclusion.serializeStageOptions(boost::none)); ASSERT_DOCUMENT_EQ(expectedSerialization, - inclusion.serialize(ExplainOptions::Verbosity::kQueryPlanner)); + inclusion.serializeStageOptions(ExplainOptions::Verbosity::kQueryPlanner)); ASSERT_DOCUMENT_EQ(expectedSerialization, - inclusion.serialize(ExplainOptions::Verbosity::kExecStats)); + inclusion.serializeStageOptions(ExplainOptions::Verbosity::kExecStats)); ASSERT_DOCUMENT_EQ(expectedSerialization, - inclusion.serialize(ExplainOptions::Verbosity::kExecAllPlans)); + inclusion.serializeStageOptions(ExplainOptions::Verbosity::kExecAllPlans)); } TEST(InclusionProjection, ShouldReportThatAllExceptIncludedFieldsAreModified) { |