diff options
| author | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-11 15:07:35 -0300 |
|---|---|---|
| committer | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-11 15:07:35 -0300 |
| commit | 4cb8841196d0625dfa3825aa326f071cd27c7b8b (patch) | |
| tree | 1682a647d4463397c119183369ae6f750d5fdcff /src/mongo/db/pipeline/document_source_match.cpp | |
| parent | aa03c6362cbaa767638e6eed9b031d86dd2643d1 (diff) | |
| parent | 8f0827553e09872941945a093b647a4211a9db7f (diff) | |
Update upstream source from tag 'upstream/6.0.0'master
Update to upstream version '6.0.0'
with Debian dir 5604a80ec1c96ca76f25f40d78e6ef855abec322
Diffstat (limited to 'src/mongo/db/pipeline/document_source_match.cpp')
| -rw-r--r-- | src/mongo/db/pipeline/document_source_match.cpp | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/src/mongo/db/pipeline/document_source_match.cpp b/src/mongo/db/pipeline/document_source_match.cpp index 36b39f3820c..10346eb6a46 100644 --- a/src/mongo/db/pipeline/document_source_match.cpp +++ b/src/mongo/db/pipeline/document_source_match.cpp @@ -67,10 +67,11 @@ const char* DocumentSourceMatch::getSourceName() const { return kStageName.rawData(); } -Value DocumentSourceMatch::serialize(const SerializationOptions& opts) const { - if (opts.verbosity || opts.transformIdentifiers || - opts.literalPolicy != LiteralSerializationPolicy::kUnchanged) { - return Value(DOC(getSourceName() << Document(_expression->serialize(opts)))); +Value DocumentSourceMatch::serialize(boost::optional<ExplainOptions::Verbosity> explain) const { + if (explain) { + BSONObjBuilder builder; + _expression->serialize(&builder); + return Value(DOC(getSourceName() << Document(builder.obj()))); } return Value(DOC(getSourceName() << Document(getQuery()))); } @@ -92,12 +93,11 @@ DocumentSource::GetNextResult DocumentSourceMatch::doGetNext() { auto nextInput = pSource->getNext(); for (; nextInput.isAdvanced(); nextInput = pSource->getNext()) { // MatchExpression only takes BSON documents, so we have to make one. As an optimization, - // only serialize the fields we need to do the match. Specify BSONObj::LargeSizeTrait so - // that matching against a large document mid-pipeline does not throw a BSON max-size error. + // only serialize the fields we need to do the match. BSONObj toMatch = _dependencies.needWholeDocument - ? nextInput.getDocument().toBson<BSONObj::LargeSizeTrait>() - : document_path_support::documentToBsonWithPaths<BSONObj::LargeSizeTrait>( - nextInput.getDocument(), _dependencies.fields); + ? nextInput.getDocument().toBson() + : document_path_support::documentToBsonWithPaths(nextInput.getDocument(), + _dependencies.fields); if (_expression->matchesBSON(toMatch)) { return nextInput; @@ -410,13 +410,13 @@ void DocumentSourceMatch::joinMatchWith(intrusive_ptr<DocumentSourceMatch> other } pair<intrusive_ptr<DocumentSourceMatch>, intrusive_ptr<DocumentSourceMatch>> -DocumentSourceMatch::splitSourceBy(const OrderedPathSet& fields, +DocumentSourceMatch::splitSourceBy(const std::set<std::string>& fields, const StringMap<std::string>& renames) && { return std::move(*this).splitSourceByFunc(fields, renames, expression::isIndependentOf); } pair<intrusive_ptr<DocumentSourceMatch>, intrusive_ptr<DocumentSourceMatch>> -DocumentSourceMatch::splitSourceByFunc(const OrderedPathSet& fields, +DocumentSourceMatch::splitSourceByFunc(const std::set<std::string>& fields, const StringMap<std::string>& renames, expression::ShouldSplitExprFunc func) && { pair<unique_ptr<MatchExpression>, unique_ptr<MatchExpression>> newExpr( @@ -448,11 +448,15 @@ DocumentSourceMatch::splitSourceByFunc(const OrderedPathSet& fields, // the corresponding BSONObj may not exist. Therefore, we take each of these expressions, // serialize them, and then re-parse them, constructing new BSON that is owned by the // DocumentSourceMatch. - auto firstMatch = DocumentSourceMatch::create(newExpr.first->serialize(), pExpCtx); + BSONObjBuilder firstBob; + newExpr.first->serialize(&firstBob); + auto firstMatch = DocumentSourceMatch::create(firstBob.obj(), pExpCtx); intrusive_ptr<DocumentSourceMatch> secondMatch; if (newExpr.second) { - secondMatch = DocumentSourceMatch::create(newExpr.second->serialize(), pExpCtx); + BSONObjBuilder secondBob; + newExpr.second->serialize(&secondBob); + secondMatch = DocumentSourceMatch::create(secondBob.obj(), pExpCtx); } return {std::move(firstMatch), std::move(secondMatch)}; @@ -485,7 +489,9 @@ boost::intrusive_ptr<DocumentSourceMatch> DocumentSourceMatch::descendMatchOnPat } }); - return new DocumentSourceMatch(matchExpr->serialize(), expCtx); + BSONObjBuilder query; + matchExpr->serialize(&query); + return new DocumentSourceMatch(query.obj(), expCtx); } std::pair<boost::intrusive_ptr<DocumentSourceMatch>, boost::intrusive_ptr<DocumentSourceMatch>> @@ -493,7 +499,7 @@ DocumentSourceMatch::splitMatchByModifiedFields( const boost::intrusive_ptr<DocumentSourceMatch>& match, const DocumentSource::GetModPathsReturn& modifiedPathsRet) { // Attempt to move some or all of this $match before this stage. - OrderedPathSet modifiedPaths; + std::set<std::string> modifiedPaths; switch (modifiedPathsRet.type) { case DocumentSource::GetModPathsReturn::Type::kNotSupported: // We don't know what paths this stage might modify, so refrain from swapping. |
