Get and set roles from a reference data set

New Altair Community Member
Updated by Jocelyn
I have a data set with various features that have been excluded by marking them with a role (they were not removed because they can be useful for reference even if they should be excluded from most operators). Now, I would like to apply the same roles to another data set that has the same columns (on which no roles have been set)
In Python, I was able to do this to achieve my objective:
def rm_main(data,refdata): <br>
data.rm_metadata = refdata.rm_metadata <br>
return data, refdata
However, this can be slow for large data sets because the whole dataset is passed back and forth between Python and RapidMiner, which is not necessary in cases where the only thing I want to do is manipulate the columns metadata.
Is there a native way to do something similar with RapidMiner operators (or with an extension that adds such an operator)?
Otherwise, would the Groovy scripting operator be usable for this? I tried experimenting with it but could not find something that works.
Example (not functional, all attributes are seen to have a "null" role):
ExampleSet inputData = input[0]; <br>
ExampleSet referenceData = input[1]; <br>
ExampleSetMetaData inputMetaData = operator.getInputPorts().getPortByIndex(0).getMetaData();
ExampleSetMetaData referenceMetaData = operator.getInputPorts().getPortByIndex(1).getMetaData(); <br>
for (Attribute attribute: referenceData.getAttributes()) { <br>
AttributeMetaData referenceAttributeMetaData = referenceMetaData.getAttributeByName(attribute.getName())
String referenceRole = referenceAttributeMetaData.getRole() <br>
LogService.root.log(Level.INFO, "Role for " + attribute.getName() + ": " + referenceRole); <br>
}