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_densify_test.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_densify_test.cpp')
| -rw-r--r-- | src/mongo/db/pipeline/document_source_densify_test.cpp | 327 |
1 files changed, 1 insertions, 326 deletions
diff --git a/src/mongo/db/pipeline/document_source_densify_test.cpp b/src/mongo/db/pipeline/document_source_densify_test.cpp index f83101b7736..c1a0218e9eb 100644 --- a/src/mongo/db/pipeline/document_source_densify_test.cpp +++ b/src/mongo/db/pipeline/document_source_densify_test.cpp @@ -49,7 +49,6 @@ using DensifyExplicitNumericTest = AggregationContextFixture; using DensifyPartitionNumericTest = AggregationContextFixture; using DensifyCloneTest = AggregationContextFixture; using DensifyStepTest = AggregationContextFixture; -using DensifyRedactionTest = AggregationContextFixture; Date_t makeDate(std::string dateStr) { auto statusDate = dateFromISOString(dateStr); @@ -849,161 +848,6 @@ TEST_F(DensifyExplicitNumericTest, CorrectlyDensifiesForNumericExplicitRangeStar ASSERT_FALSE(next.isAdvanced()); } -TEST_F(DensifyExplicitNumericTest, - CorrectlyDensifiesForPartionedRangeStartingBeforeBoundsRangeWithDocMatchingBoundsStart) { - auto densify = DocumentSourceInternalDensify( - getExpCtx(), - "b", - std::list<FieldPath>({"a"}), - RangeStatement(Value(1), ExplicitBounds(Value(4), Value(8)), boost::none)); - auto source = DocumentSourceMock::createForTest( - {"{a: 1, b: 2}", "{a: 1, b: 4}", "{a: 1, b: 6}"}, getExpCtx()); - densify.setSource(source.get()); - - auto next = densify.getNext(); - ASSERT(next.isAdvanced()); - ASSERT_EQUALS(2, next.getDocument().getField("b").getDouble()); - - next = densify.getNext(); - ASSERT(next.isAdvanced()); - ASSERT_EQUALS(4, next.getDocument().getField("b").getDouble()); - - next = densify.getNext(); - ASSERT(next.isAdvanced()); - ASSERT_EQUALS(5, next.getDocument().getField("b").getDouble()); - - next = densify.getNext(); - ASSERT(next.isAdvanced()); - ASSERT_EQUALS(6, next.getDocument().getField("b").getDouble()); - - next = densify.getNext(); - ASSERT(next.isAdvanced()); - ASSERT_EQUALS(7, next.getDocument().getField("b").getDouble()); - - next = densify.getNext(); - ASSERT_FALSE(next.isAdvanced()); - - next = densify.getNext(); - ASSERT_FALSE(next.isAdvanced()); -} - -TEST_F(DensifyExplicitNumericTest, CorrectlyDensifiesForPartionedRangeAcrossTwoPartitions) { - auto densify = DocumentSourceInternalDensify( - getExpCtx(), - "b", - std::list<FieldPath>({"a"}), - RangeStatement(Value(1), ExplicitBounds(Value(0), Value(10)), boost::none)); - auto source = DocumentSourceMock::createForTest( - {"{a: 1, b: 2}", "{a: 2, b: 5}", "{a: 1, b: 7}", "{a: 2, b: 9}"}, getExpCtx()); - densify.setSource(source.get()); - - auto next = densify.getNext(); - ASSERT(next.isAdvanced()); - ASSERT_EQUALS(1, next.getDocument().getField("a").getDouble()); - ASSERT_EQUALS(0, next.getDocument().getField("b").getDouble()); - - next = densify.getNext(); - ASSERT(next.isAdvanced()); - ASSERT_EQUALS(1, next.getDocument().getField("a").getDouble()); - ASSERT_EQUALS(1, next.getDocument().getField("b").getDouble()); - - next = densify.getNext(); - ASSERT(next.isAdvanced()); - ASSERT_EQUALS(1, next.getDocument().getField("a").getDouble()); - ASSERT_EQUALS(2, next.getDocument().getField("b").getDouble()); - - next = densify.getNext(); - ASSERT(next.isAdvanced()); - ASSERT_EQUALS(2, next.getDocument().getField("a").getDouble()); - ASSERT_EQUALS(0, next.getDocument().getField("b").getDouble()); - - next = densify.getNext(); - ASSERT(next.isAdvanced()); - ASSERT_EQUALS(2, next.getDocument().getField("a").getDouble()); - ASSERT_EQUALS(1, next.getDocument().getField("b").getDouble()); - - next = densify.getNext(); - ASSERT(next.isAdvanced()); - ASSERT_EQUALS(2, next.getDocument().getField("a").getDouble()); - ASSERT_EQUALS(2, next.getDocument().getField("b").getDouble()); - - next = densify.getNext(); - ASSERT(next.isAdvanced()); - ASSERT_EQUALS(2, next.getDocument().getField("a").getDouble()); - ASSERT_EQUALS(3, next.getDocument().getField("b").getDouble()); - - next = densify.getNext(); - ASSERT(next.isAdvanced()); - ASSERT_EQUALS(2, next.getDocument().getField("a").getDouble()); - ASSERT_EQUALS(4, next.getDocument().getField("b").getDouble()); - - next = densify.getNext(); - ASSERT(next.isAdvanced()); - ASSERT_EQUALS(2, next.getDocument().getField("a").getDouble()); - ASSERT_EQUALS(5, next.getDocument().getField("b").getDouble()); - - next = densify.getNext(); - ASSERT(next.isAdvanced()); - ASSERT_EQUALS(1, next.getDocument().getField("a").getDouble()); - ASSERT_EQUALS(3, next.getDocument().getField("b").getDouble()); - - next = densify.getNext(); - ASSERT(next.isAdvanced()); - ASSERT_EQUALS(1, next.getDocument().getField("a").getDouble()); - ASSERT_EQUALS(4, next.getDocument().getField("b").getDouble()); - - next = densify.getNext(); - ASSERT(next.isAdvanced()); - ASSERT_EQUALS(1, next.getDocument().getField("a").getDouble()); - ASSERT_EQUALS(5, next.getDocument().getField("b").getDouble()); - - next = densify.getNext(); - ASSERT(next.isAdvanced()); - ASSERT_EQUALS(1, next.getDocument().getField("a").getDouble()); - ASSERT_EQUALS(6, next.getDocument().getField("b").getDouble()); - - next = densify.getNext(); - ASSERT(next.isAdvanced()); - ASSERT_EQUALS(1, next.getDocument().getField("a").getDouble()); - ASSERT_EQUALS(7, next.getDocument().getField("b").getDouble()); - - next = densify.getNext(); - ASSERT(next.isAdvanced()); - ASSERT_EQUALS(2, next.getDocument().getField("a").getDouble()); - ASSERT_EQUALS(6, next.getDocument().getField("b").getDouble()); - - next = densify.getNext(); - ASSERT(next.isAdvanced()); - ASSERT_EQUALS(2, next.getDocument().getField("a").getDouble()); - ASSERT_EQUALS(7, next.getDocument().getField("b").getDouble()); - - next = densify.getNext(); - ASSERT(next.isAdvanced()); - ASSERT_EQUALS(2, next.getDocument().getField("a").getDouble()); - ASSERT_EQUALS(8, next.getDocument().getField("b").getDouble()); - - next = densify.getNext(); - ASSERT(next.isAdvanced()); - ASSERT_EQUALS(2, next.getDocument().getField("a").getDouble()); - ASSERT_EQUALS(9, next.getDocument().getField("b").getDouble()); - - next = densify.getNext(); - ASSERT(next.isAdvanced()); - ASSERT_EQUALS(1, next.getDocument().getField("a").getDouble()); - ASSERT_EQUALS(8, next.getDocument().getField("b").getDouble()); - - next = densify.getNext(); - ASSERT(next.isAdvanced()); - ASSERT_EQUALS(1, next.getDocument().getField("a").getDouble()); - ASSERT_EQUALS(9, next.getDocument().getField("b").getDouble()); - - next = densify.getNext(); - ASSERT_FALSE(next.isAdvanced()); - - next = densify.getNext(); - ASSERT_FALSE(next.isAdvanced()); -} - TEST_F(DensifyExplicitNumericTest, CorrectlyDensifiesForNumericExplicitRangeOnlyInsideRange) { auto densify = DocumentSourceInternalDensify( getExpCtx(), @@ -1378,7 +1222,7 @@ TEST_F(DensifyPartitionNumericTest, DensifiesOnImmediateEOFExplicitRange) { ASSERT_FALSE(next.isAdvanced()); } -TEST_F(DensifyCloneTest, InternalDensifyCanBeCloned) { +TEST_F(DensifyCloneTest, InternalDesnifyCanBeCloned) { std::list<boost::intrusive_ptr<DocumentSource>> sources; sources.push_back(make_intrusive<DocumentSourceInternalDensify>( @@ -1439,174 +1283,5 @@ TEST(DensifyStepTest, InternalDensifyIsOffStepForDaysWithLargeDateStep) { ASSERT_FALSE(val.isOnStepRelativeTo(base, range)); } - -TEST_F(DensifyRedactionTest, RedactionDateBounds) { - auto spec = fromjson(R"({ - $densify: { - field: "a", - range: { - step: 1, - unit: "hour", - bounds: [ - {$date: "2023-04-23T00:00:00.000Z"}, - {$date: "2023-04-23T08:00:00.000Z"} - ] - } - } - })"); - - auto docSource = - DocumentSourceInternalDensify::createFromBson(spec.firstElement(), getExpCtx()); - ASSERT_BSONOBJ_EQ_AUTO( // NOLINT - R"({ - "$_internalDensify": { - "field": "HASH<a>", - "partitionByFields": [], - "range": { - "step": "?number", - "bounds": [ - "?date", - "?date" - ], - "unit": "hour" - } - } - })", - redact(*docSource)); -} - -TEST_F(DensifyRedactionTest, RedactionFullBoundsWithPartitionFields) { - auto spec = fromjson(R"({ - $densify: { - field: "foo", - partitionByFields: ["a", "b", "c.d"], - range: { - bounds: "full", - step: 100 - } - } - })"); - auto docSource = - DocumentSourceInternalDensify::createFromBson(spec.firstElement(), getExpCtx()); - ASSERT_BSONOBJ_EQ_AUTO( // NOLINT - R"({ - "$_internalDensify": { - "field": "HASH<foo>", - "partitionByFields": [ - "HASH<a>", - "HASH<b>", - "HASH<c>.HASH<d>" - ], - "range": { - "step": "?number", - "bounds": "full" - } - } - })", - redact(*docSource)); -} - -TEST_F(DensifyRedactionTest, RedactionPartitionBounds) { - auto spec = fromjson(R"({ - $densify: { - field: "x", - partitionByFields: ["foo"], - range: { - bounds: "partition", - step: 50, - unit: "second" - } - } - })"); - auto docSource = - DocumentSourceInternalDensify::createFromBson(spec.firstElement(), getExpCtx()); - ASSERT_BSONOBJ_EQ_AUTO( // NOLINT - R"({ - "$_internalDensify": { - "field": "HASH<x>", - "partitionByFields": [ - "HASH<foo>" - ], - "range": { - "step": "?number", - "bounds": "partition", - "unit": "second" - } - } - })", - redact(*docSource)); -} - -void assertRangeTimeUnitSerialization(const boost::intrusive_ptr<ExpressionContext>& expCtx, - BSONObj inputStage, - BSONObj expectedStage, - const SerializationOptions& opts) { - auto parsedStage = - DocumentSourceInternalDensify::createFromBson(inputStage.firstElement(), expCtx); - std::vector<Value> serialization; - parsedStage->serializeToArray(serialization, opts); - - auto serializedStage = serialization[0].getDocument().toBson(); - ASSERT_BSONOBJ_EQ(expectedStage, serializedStage); -} - -TEST_F(DensifyRedactionTest, RangeTimeUnitSerializationRepresentative) { - assertRangeTimeUnitSerialization( - getExpCtx(), - fromjson(R"({ - $densify: { - field: "x", - partitionByFields: ["foo"], - range: { - bounds: "partition", - step: 50, - unit: "second" - } - } - })"), - fromjson(R"({ - $_internalDensify: { - field: "x", - partitionByFields: [ - "foo" - ], - range: { - step: 1, - bounds: "partition", - unit: "second" - } - } - })"), - SerializationOptions::kRepresentativeQueryShapeSerializeOptions); -} - -TEST_F(DensifyRedactionTest, RangeTimeUnitSerializationDebug) { - assertRangeTimeUnitSerialization(getExpCtx(), - fromjson( - R"({ - $densify: { - field: "x", - partitionByFields: ["foo"], - range: { - bounds: "partition", - step: 50, - unit: "second" - } - } - })"), - fromjson( - R"({ - $_internalDensify: { - field: "x", - partitionByFields: ["foo"], - range: { - step: "?number", - bounds: "partition", - unit: "second" - } - } - })"), - SerializationOptions::kDebugQueryShapeSerializeOptions); -} } // namespace } // namespace mongo |
