use of org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord in project pentaho-metaverse by pentaho.
the class StepAnalyzerTest method testMapChange_originalFieldIsTransient.
@Test
public void testMapChange_originalFieldIsTransient() throws Exception {
doReturn(outputs).when(analyzer).getOutputs();
doReturn(inputs).when(analyzer).getInputs();
IMetaverseNode transientNode = mock(IMetaverseNode.class);
String shouldBeNull = null;
doReturn(transientNode).when(analyzer).createOutputFieldNode(any(IAnalysisContext.class), any(ValueMetaInterface.class), eq(shouldBeNull), eq(DictionaryConst.NODE_TYPE_TRANS_FIELD));
// zip is not in the inputs or outputs, it must have been a temporary fields used internally by step.
StepField original = new StepField(null, "zip");
StepField changed = new StepField("nextStep", "address");
ComponentDerivationRecord cdr = new ComponentDerivationRecord(original, changed);
analyzer.mapChange(cdr);
verify(builder).addLink(rootNode, DictionaryConst.LINK_TRANSIENT, transientNode);
verify(builder).addLink(rootNode, DictionaryConst.LINK_USES, transientNode);
verify(analyzer).linkChangeNodes(eq(transientNode), any(IMetaverseNode.class));
}
use of org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord in project pentaho-metaverse by pentaho.
the class StepAnalyzerTest method testGetChanges_noChangeRecords.
@Test
public void testGetChanges_noChangeRecords() throws Exception {
ComponentDerivationRecord passthrough1 = mock(ComponentDerivationRecord.class);
ComponentDerivationRecord passthrough2 = mock(ComponentDerivationRecord.class);
Set<ComponentDerivationRecord> passthroughs = new HashSet<>();
passthroughs.add(passthrough1);
passthroughs.add(passthrough2);
doReturn(null).when(analyzer).getChangeRecords(baseStepMeta);
doReturn(passthroughs).when(analyzer).getPassthroughChanges();
Set<ComponentDerivationRecord> changes = analyzer.getChanges();
assertTrue(CollectionUtils.isNotEmpty(changes));
assertEquals(2, changes.size());
}
use of org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord in project pentaho-metaverse by pentaho.
the class StepAnalyzerTest method testGetChanges.
@Test
public void testGetChanges() throws Exception {
ComponentDerivationRecord change1 = mock(ComponentDerivationRecord.class);
ComponentDerivationRecord change2 = mock(ComponentDerivationRecord.class);
ComponentDerivationRecord change3 = mock(ComponentDerivationRecord.class);
Set<ComponentDerivationRecord> changeRecords = new HashSet<>();
changeRecords.add(change1);
changeRecords.add(change2);
changeRecords.add(change3);
ComponentDerivationRecord passthrough1 = mock(ComponentDerivationRecord.class);
ComponentDerivationRecord passthrough2 = mock(ComponentDerivationRecord.class);
Set<ComponentDerivationRecord> passthroughs = new HashSet<>();
passthroughs.add(passthrough1);
passthroughs.add(passthrough2);
doReturn(changeRecords).when(analyzer).getChangeRecords(baseStepMeta);
doReturn(passthroughs).when(analyzer).getPassthroughChanges();
Set<ComponentDerivationRecord> changes = analyzer.getChanges();
assertTrue(CollectionUtils.isNotEmpty(changes));
assertEquals(5, changes.size());
}
use of org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord in project pentaho-metaverse by pentaho.
the class NumberRangeStepAnalyzer method getChangeRecords.
@Override
public Set<ComponentDerivationRecord> getChangeRecords(final NumberRangeMeta meta) throws MetaverseAnalyzerException {
Set<ComponentDerivationRecord> changeRecords = new HashSet<>();
ComponentDerivationRecord changeRecord = new ComponentDerivationRecord(meta.getInputField(), meta.getOutputField(), ChangeType.DATA);
List<NumberRangeRule> rules = meta.getRules();
if (rules != null) {
for (NumberRangeRule rule : rules) {
changeRecord.addOperation(new Operation(Operation.MAPPING_CATEGORY, ChangeType.DATA, DictionaryConst.PROPERTY_TRANSFORMS, rule.getLowerBound() + " <= " + meta.getInputField() + " <= " + rule.getUpperBound() + " -> " + rule.getValue()));
}
}
changeRecords.add(changeRecord);
return changeRecords;
}
use of org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord in project pentaho-metaverse by pentaho.
the class StreamLookupStepAnalyzer method getChangeRecords.
/**
* Identify the name collision renames and add change records for them.
* <p/>
* example: join fields in both input steps named COUNTRY. the second (right) field gets renamed with a suffix
* on the way out of the step. You end up with COUNTRY (from the left) & COUNTRY_1 (from the right)
*
* @param meta
* @return
* @throws MetaverseAnalyzerException
*/
@Override
public Set<ComponentDerivationRecord> getChangeRecords(StreamLookupMeta meta) throws MetaverseAnalyzerException {
Set<ComponentDerivationRecord> changeRecords = new HashSet<>();
String[] names = meta.getValue();
String[] newFields = meta.getValueName();
for (int i = 0; i < names.length; i++) {
String name = names[i];
String newFieldName = newFields[i];
if (newFieldNameExistsInMainInputStream(newFieldName)) {
// the new field name is going to be renamed with the _N naming convention to make it unique
RowMetaInterface outputFields = getOutputFields(meta);
for (int renameIdx = 1; renameIdx <= valueNames.length; renameIdx++) {
ValueMetaInterface outField = outputFields.searchValueMeta(newFieldName + "_" + renameIdx);
if (outField == null) {
newFieldName = newFieldName + "_" + renameIdx;
break;
}
}
}
ComponentDerivationRecord renameFieldRecord = new ComponentDerivationRecord(name, newFieldName, ChangeType.METADATA);
renameFieldRecord.addOperation(Operation.getRenameOperation());
changeRecords.add(renameFieldRecord);
}
return changeRecords;
}
Aggregations