TEST_F(InternalUnpackBucketSplitMatchOnMetaAndRename,
       OptimizeDoesNotErrorOnFailedSplitOfMetaMatch) {
    auto unpack = fromjson(
        "{$_internalUnpackBucket: { exclude: [], timeField: 'foo', metaField: 'myMeta', "
        "bucketMaxSpanSeconds: 3600}}");
    auto match = fromjson(
        "{$match: {$and: [{x: {$lte: 1}}, {$or: [{'myMeta.a': "
        "{$gt: 1}}, {y: {$lt: 1}}]}]}}");
    auto pipeline = Pipeline::parse(makeVector(unpack, match), getExpCtx());
    ASSERT_EQ(2u, pipeline->getSources().size());

    pipeline->optimizePipeline();

    // We should fail to split the match because of the $or clause. We should still be able to
    // map the predicate on 'x' to a predicate on the control field.
    auto serialized = pipeline->serializeToBson();
    ASSERT_EQ(3u, serialized.size());
    ASSERT_BSONOBJ_EQ(fromjson("{$match: {$and: [{'control.min.x': {$_internalExprLte: 1}}]}}"),
                      serialized[0]);
    ASSERT_BSONOBJ_EQ(unpack, serialized[1]);
    ASSERT_BSONOBJ_EQ(match, serialized[2]);
}
TEST_F(InternalUnpackBucketSplitMatchOnMetaAndRename,
       OptimizeDoesNotErrorOnFailedSplitOfMetaMatch) {
    auto unpack = fromjson(
        "{$_internalUnpackBucket: { exclude: [], timeField: 'foo', metaField: 'myMeta', "
        "bucketMaxSpanSeconds: 3600}}");
    auto match = fromjson(
        "{$match: {$and: [{x: {$lte: 1}}, {$or: [{'myMeta.a': "
        "{$gt: 1}}, {y: {$lt: 1}}]}]}}");
    auto pipeline = Pipeline::parse(makeVector(unpack, match), getExpCtx());
    ASSERT_EQ(2u, pipeline->getSources().size());

    pipeline->optimizePipeline();

     
     
    auto serialized = pipeline->serializeToBson();
    ASSERT_EQ(3u, serialized.size());
    ASSERT_BSONOBJ_EQ(fromjson("{$match: {$and: [{'control.min.x': {$_internalExprLte: 1}}]}}"),
                      serialized[0]);
    ASSERT_BSONOBJ_EQ(unpack, serialized[1]);
    ASSERT_BSONOBJ_EQ(match, serialized[2]);
}