diff options
| author | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-18 17:02:53 -0300 |
|---|---|---|
| committer | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-18 17:02:53 -0300 |
| commit | 959575a5ca598bf5f37fb5cebe7ed1d80d3d71f7 (patch) | |
| tree | acc8d60aedb12b70048e676e8a7349deb0010db8 /src/mongo/db/pipeline/document_source_bucket_auto_test.cpp | |
| parent | 76588293975fc059cf076779e4283e6ffaf8afff (diff) | |
New upstream version 6.0.20upstream
Diffstat (limited to 'src/mongo/db/pipeline/document_source_bucket_auto_test.cpp')
| -rw-r--r-- | src/mongo/db/pipeline/document_source_bucket_auto_test.cpp | 109 |
1 files changed, 107 insertions, 2 deletions
diff --git a/src/mongo/db/pipeline/document_source_bucket_auto_test.cpp b/src/mongo/db/pipeline/document_source_bucket_auto_test.cpp index 8e0be33e786..4bc3cb0e11a 100644 --- a/src/mongo/db/pipeline/document_source_bucket_auto_test.cpp +++ b/src/mongo/db/pipeline/document_source_bucket_auto_test.cpp @@ -89,8 +89,9 @@ public: assertBucketAutoType(bucketAutoStage); vector<Value> explainedStages; - bucketAutoStage->serializeToArray(explainedStages, - ExplainOptions::Verbosity::kQueryPlanner); + bucketAutoStage->serializeToArray( + explainedStages, + SerializationOptions{boost::make_optional(ExplainOptions::Verbosity::kQueryPlanner)}); ASSERT_EQUALS(explainedStages.size(), 1UL); Value expectedExplain = Value(expectedObj); @@ -868,5 +869,109 @@ TEST_F(BucketAutoTests, ShouldFailOnNegativeNumbersWhenGranularitySpecified) { AssertionException, 40260); } + +TEST_F(BucketAutoTests, RedactionWithoutOutputField) { + auto spec = fromjson(R"({ + $bucketAuto: { + groupBy: '$_id', + buckets: 5, + granularity: "R5" + } + })"); + auto docSource = DocumentSourceBucketAuto::createFromBson(spec.firstElement(), getExpCtx()); + + ASSERT_BSONOBJ_EQ_AUTO( // NOLINT + R"({ + "$bucketAuto": { + "groupBy": "$HASH<_id>", + "buckets": "?number", + "granularity": "?string", + "output": { + "HASH<count>": { + "$sum": "?number" + } + } + } + })", + redact(*docSource)); +} + +TEST_F(BucketAutoTests, RedactionWithOutputField) { + auto spec = fromjson(R"({ + $bucketAuto: { + groupBy: '$year', + buckets: 3, + output: { + count: { $sum: 1 }, + years: { $push: '$year' } + } + }})"); + auto docSource = DocumentSourceBucketAuto::createFromBson(spec.firstElement(), getExpCtx()); + + ASSERT_BSONOBJ_EQ_AUTO( // NOLINT + R"({ + "$bucketAuto": { + "groupBy": "$HASH<year>", + "buckets": "?number", + "output": { + "HASH<count>": { + "$sum": "?number" + }, + "HASH<years>": { + "$push": "$HASH<year>" + } + } + } + })", + redact(*docSource)); +} + +TEST_F(BucketAutoTests, QueryShapeReParseSerializedStage) { + auto expCtx = getExpCtx(); + auto spec = fromjson(R"({ + $bucketAuto: { + groupBy: '$year', + buckets: 3, + granularity: "E192", + output: { + count: { $sum: 1 }, + years: { $push: '$year' } + } + }})"); + + auto docSource = DocumentSourceBucketAuto::createFromBson(spec.firstElement(), expCtx); + auto opts = SerializationOptions{LiteralSerializationPolicy::kToRepresentativeParseableValue}; + std::vector<Value> serialized; + docSource->serializeToArray(serialized, opts); + auto serializedDocSource = serialized[0].getDocument().toBson(); + ASSERT_BSONOBJ_EQ_AUTO( // NOLINT + R"({ + "$bucketAuto": { + "groupBy": "$year", + "buckets": 1, + "granularity": "R5", + "output": { + "count": { + "$sum": { + "$const":1 + } + }, + "years": { + "$push": "$year" + } + } + } + })", + serializedDocSource); + auto docSourceFromQueryShape = + DocumentSourceBucketAuto::createFromBson(serializedDocSource.firstElement(), expCtx); + + vector<Value> newSerialization; + docSourceFromQueryShape->serializeToArray(newSerialization, opts); + auto newSerializedDocSource = newSerialization[0].getDocument().toBson(); + ASSERT_BSONOBJ_EQ(serializedDocSource, newSerializedDocSource); +} + + } // namespace } // namespace mongo |
