Skip to content

Commit ce0f0af

Browse files
committed
[ntuple] Refine name conflict resolution
The fields from the auxiliary processor get added to the model of the primary processor wrapped in an untyped collection with the name of the auxiliary processor. Therefore, instead of checking that the primary and auxiliary processors don't share the same name, we should check that the primary processor doesn't already have a field with the name of the auxiliary processor.
1 parent 7ad64bc commit ce0f0af

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

tree/ntuple/src/RNTupleProcessor.cxx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,6 @@ ROOT::Experimental::RNTupleProcessor::CreateJoin(RNTupleOpenSpec primaryNTuple,
9696
throw RException(R__FAIL("join fields must be unique"));
9797
}
9898

99-
// Ensure no name clash exists between the primary and auxiliary ntuple.
100-
if ((!processorName.empty() && processorName == auxNTuple.fNTupleName) ||
101-
(primaryNTuple.fNTupleName == auxNTuple.fNTupleName)) {
102-
throw ROOT::RException(R__FAIL("joining RNTuples with the same name is not allowed"));
103-
}
104-
10599
std::unique_ptr<RNTupleProcessor> primaryProcessor;
106100
if (primaryModel)
107101
primaryProcessor = Create(primaryNTuple, primaryModel->Clone(), processorName);
@@ -369,6 +363,17 @@ ROOT::Experimental::RNTupleJoinProcessor::RNTupleJoinProcessor(std::unique_ptr<R
369363
auxModel = fAuxiliaryProcessor->GetModel().Clone();
370364
}
371365

366+
// If the primaryProcessor has a field with the name of the auxProcessor (either as a "proper" field or because the
367+
// primary processor itself is a join where its auxProcessor bears the same name as the current auxProcessor), there
368+
// will be name conflicts, so error out.
369+
if (primaryModel->GetFieldNames().find(fAuxiliaryProcessor->GetProcessorName()) !=
370+
primaryModel->GetFieldNames().end()) {
371+
throw RException(R__FAIL("a field or nested auxiliary processor named \"" +
372+
fAuxiliaryProcessor->GetProcessorName() +
373+
"\" is already present in the model of the primary processor; rename the auxiliary "
374+
"processor to avoid conflicts"));
375+
}
376+
372377
SetModel(std::move(primaryModel), std::move(auxModel));
373378

374379
fModel->Freeze();

tree/ntuple/test/ntuple_processor.cxx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,3 +384,18 @@ TEST_F(RNTupleProcessorTest, JoinedJoinComposedAuxiliary)
384384
EXPECT_THAT(err.what(), testing::HasSubstr("auxiliary RNTupleJoinProcessors are currently not supported"));
385385
}
386386
}
387+
388+
TEST_F(RNTupleProcessorTest, JoinedJoinComposedSameName)
389+
{
390+
auto primaryProc =
391+
RNTupleProcessor::CreateJoin({fNTupleNames[0], fFileNames[0]}, {fNTupleNames[1], fFileNames[1]}, {});
392+
393+
try {
394+
auto auxProc = RNTupleProcessor::Create({fNTupleNames[2], fFileNames[2]});
395+
auto proc = RNTupleProcessor::CreateJoin(std::move(primaryProc), std::move(auxProc), {"i"});
396+
} catch (const ROOT::RException &err) {
397+
EXPECT_THAT(err.what(), testing::HasSubstr("a field or nested auxiliary processor named \"ntuple_aux\" "
398+
"is already present in the model of the primary processor; rename "
399+
"the auxiliary processor to avoid conflicts"));
400+
}
401+
}

tree/ntuple/test/ntuple_processor_join.cxx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,6 @@ class RNTupleJoinProcessorTest : public testing::Test {
8585

8686
TEST_F(RNTupleJoinProcessorTest, Aligned)
8787
{
88-
try {
89-
auto proc = RNTupleProcessor::CreateJoin({fNTupleNames[0], fFileNames[0]}, {fNTupleNames[0], fFileNames[0]}, {});
90-
FAIL() << "ntuples with the same name cannot be joined horizontally";
91-
} catch (const ROOT::RException &err) {
92-
EXPECT_THAT(err.what(), testing::HasSubstr("joining RNTuples with the same name is not allowed"));
93-
}
94-
9588
auto proc = RNTupleProcessor::CreateJoin({fNTupleNames[1], fFileNames[1]}, {fNTupleNames[2], fFileNames[2]}, {});
9689

9790
int nEntries = 0;

0 commit comments

Comments
 (0)