TEST_F(InternalUnpackBucketSplitMatchOnMetaAndRename,
       DoesNotSplitsWhenDependentPartOfMatchIsOnMetaField) {
    auto unpack = DocumentSourceInternalUnpackBucket::createFromBsonInternal(
        fromjson("{$_internalUnpackBucket: { exclude: [], timeField: 'foo', metaField: 'meta', "
                 "bucketMaxSpanSeconds: 3600}}")
            .firstElement(),
        getExpCtx());
    auto matchToSplit = DocumentSourceMatch::create(
        fromjson("{$or: [{'meta.a': {$gt: 1}}, {metaXYZ: {$lt: 1}}]}"), getExpCtx());

    auto [metaOnlyMatch, remainingMatch] =
        dynamic_cast<DocumentSourceInternalUnpackBucket*>(unpack.get())
            ->splitMatchOnMetaAndRename(matchToSplit.get());

    // Can't split when the part of the match that is on the metaField is dependent on the rest.
    // Even though 'metaXYZ' is prefixed by 'meta', it's not a subfield. The presence of a top-level
    // $or means this match cannot be correctly split into two matches.
    ASSERT_FALSE(metaOnlyMatch);
    ASSERT_TRUE(remainingMatch);
    ASSERT_BSONOBJ_EQ(matchToSplit->getQuery(), remainingMatch->getQuery());
}
TEST_F(InternalUnpackBucketSplitMatchOnMetaAndRename,
       DoesNotSplitsWhenDependentPartOfMatchIsOnMetaField) {
    auto unpack = DocumentSourceInternalUnpackBucket::createFromBsonInternal(
        fromjson("{$_internalUnpackBucket: { exclude: [], timeField: 'foo', metaField: 'meta', "
                 "bucketMaxSpanSeconds: 3600}}")
            .firstElement(),
        getExpCtx());
    auto matchToSplit = DocumentSourceMatch::create(
        fromjson("{$or: [{'meta.a': {$gt: 1}}, {metaXYZ: {$lt: 1}}]}"), getExpCtx());

    auto [metaOnlyMatch, remainingMatch] =
        dynamic_cast<DocumentSourceInternalUnpackBucket*>(unpack.get())
            ->splitMatchOnMetaAndRename(matchToSplit.get());

     
     
     
    ASSERT_FALSE(metaOnlyMatch);
    ASSERT_TRUE(remainingMatch);
    ASSERT_BSONOBJ_EQ(matchToSplit->getQuery(), remainingMatch->getQuery());
}