@@ -3276,7 +3276,81 @@ TEST(RNTupleMerger, MergeSecondEmptySchema)
32763276 auto res = merger.Merge (sourcePtrs, opts);
32773277 EXPECT_TRUE (bool (res));
32783278 }
3279- // In Union mode we expect the output ntuple to the same fields as the first
3279+ // In Union mode we expect the output ntuple to have the same fields as the first
3280+ {
3281+ auto ntuple1 = RNTupleReader::Open (" ntuple" , fileGuard1.GetPath ());
3282+ auto ntupleOut = RNTupleReader::Open (" ntuple" , fileGuardOut.GetPath ());
3283+ ASSERT_EQ (ntupleOut->GetNEntries (), ntuple1->GetNEntries ());
3284+ ASSERT_EQ (ntupleOut->GetDescriptor ().GetNFields (), ntuple1->GetDescriptor ().GetNFields ());
3285+
3286+ auto viewI = ntupleOut->GetView <int >(" int" );
3287+ auto viewF = ntupleOut->GetView <float >(" flt" );
3288+ for (auto idx : ntupleOut->GetEntryRange ()) {
3289+ EXPECT_EQ (viewI (idx), idx);
3290+ EXPECT_FLOAT_EQ (viewF (idx), idx);
3291+ }
3292+ }
3293+
3294+ {
3295+ auto destination = std::make_unique<RPageSinkFile>(" ntuple" , fileGuardOut.GetPath (), RNTupleWriteOptions ());
3296+ opts.fMergingMode = ENTupleMergingMode::kStrict ;
3297+ RNTupleMerger merger{std::move (destination)};
3298+ auto res = merger.Merge (sourcePtrs, opts);
3299+ EXPECT_FALSE (bool (res));
3300+ }
3301+ }
3302+ }
3303+
3304+ TEST (RNTupleMerger, MergeSecondEmptySchema2)
3305+ {
3306+ // Try merging two ntuples, the second of which has an empty schema and no entries
3307+ FileRaii fileGuard1 (" test_ntuple_merge_secondempty2_1.root" );
3308+ {
3309+ auto model = RNTupleModel::Create ();
3310+ auto pi = model->MakeField <int >(" int" );
3311+ auto pf = model->MakeField <float >(" flt" );
3312+ auto ntuple = RNTupleWriter::Recreate (std::move (model), " ntuple" , fileGuard1.GetPath ());
3313+ for (size_t i = 0 ; i < 10 ; ++i) {
3314+ *pi = i;
3315+ *pf = i;
3316+ ntuple->Fill ();
3317+ }
3318+ }
3319+
3320+ FileRaii fileGuard2 (" test_ntuple_merge_secondempty2_2.root" );
3321+ {
3322+ auto model = RNTupleModel::Create ();
3323+ auto ntuple = RNTupleWriter::Recreate (std::move (model), " ntuple" , fileGuard2.GetPath ());
3324+ }
3325+
3326+ // Now merge the inputs
3327+ FileRaii fileGuardOut (" test_ntuple_merge_secondempty2_out.root" );
3328+ {
3329+ // Gather the input sources
3330+ std::vector<std::unique_ptr<RPageSource>> sources;
3331+ sources.push_back (RPageSource::Create (" ntuple" , fileGuard1.GetPath (), RNTupleReadOptions ()));
3332+ sources.push_back (RPageSource::Create (" ntuple" , fileGuard2.GetPath (), RNTupleReadOptions ()));
3333+ std::vector<RPageSource *> sourcePtrs;
3334+ for (const auto &s : sources) {
3335+ sourcePtrs.push_back (s.get ());
3336+ }
3337+
3338+ RNTupleMergeOptions opts;
3339+ {
3340+ auto destination = std::make_unique<RPageSinkFile>(" ntuple" , fileGuardOut.GetPath (), RNTupleWriteOptions ());
3341+ opts.fMergingMode = ENTupleMergingMode::kFilter ;
3342+ RNTupleMerger merger{std::move (destination)};
3343+ auto res = merger.Merge (sourcePtrs, opts);
3344+ EXPECT_FALSE (bool (res));
3345+ }
3346+ {
3347+ auto destination = std::make_unique<RPageSinkFile>(" ntuple" , fileGuardOut.GetPath (), RNTupleWriteOptions ());
3348+ opts.fMergingMode = ENTupleMergingMode::kUnion ;
3349+ RNTupleMerger merger{std::move (destination)};
3350+ auto res = merger.Merge (sourcePtrs, opts);
3351+ EXPECT_TRUE (bool (res));
3352+ }
3353+ // In Union mode we expect the output ntuple to have the same fields as the first
32803354 {
32813355 auto ntuple1 = RNTupleReader::Open (" ntuple" , fileGuard1.GetPath ());
32823356 auto ntupleOut = RNTupleReader::Open (" ntuple" , fileGuardOut.GetPath ());
0 commit comments