use of org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord in project pentaho-metaverse by pentaho.
the class AbstractStepMetaJsonSerializerTest method testWriteFieldTransforms.
@Test
public void testWriteFieldTransforms() throws Exception {
Set<ComponentDerivationRecord> changeRecords = new HashSet<ComponentDerivationRecord>();
ComponentDerivationRecord change1 = mock(ComponentDerivationRecord.class);
ComponentDerivationRecord change2 = mock(ComponentDerivationRecord.class);
when(change1.hasDelta()).thenReturn(true);
when(change2.hasDelta()).thenReturn(false);
changeRecords.add(change1);
changeRecords.add(change2);
IFieldLineageMetadataProvider mapper = mock(IFieldLineageMetadataProvider.class);
AbstractStepMetaJsonSerializer spy = spy(serializer);
when(spy.getFieldLineageMetadataProvider(spyMeta)).thenReturn(mapper);
when(mapper.getChangeRecords(spyMeta)).thenReturn(changeRecords);
spy.writeFieldTransforms(spyMeta, json, provider);
verify(json).writeObject(change1);
verify(json, never()).writeObject(change2);
}
use of org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord in project pentaho-metaverse by pentaho.
the class StepAnalyzer method getPassthroughChanges.
/**
* Get ComponentDerivationRecords for each of the fields considered to be a passthrough
*
* @return
*/
protected Set<ComponentDerivationRecord> getPassthroughChanges() {
Set<ComponentDerivationRecord> passthroughs = new HashSet<>();
if (getInputs() != null) {
Set<StepField> incomingFieldNames = getInputs().getFieldNames();
for (StepField incomingFieldName : incomingFieldNames) {
if (isPassthrough(incomingFieldName)) {
ComponentDerivationRecord change = new ComponentDerivationRecord(incomingFieldName.getFieldName(), incomingFieldName.getFieldName());
change.setOriginalEntityStepName(incomingFieldName.getStepName());
passthroughs.add(change);
}
}
}
return passthroughs;
}
use of org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord in project pentaho-metaverse by pentaho.
the class StepAnalyzer method analyze.
@Override
public IMetaverseNode analyze(IComponentDescriptor descriptor, T meta) throws MetaverseAnalyzerException {
setDescriptor(descriptor);
baseStepMeta = meta;
validateState(descriptor, meta);
// Add yourself
rootNode = createNodeFromDescriptor(descriptor);
String stepType = null;
try {
stepType = PluginRegistry.getInstance().findPluginWithId(StepPluginType.class, parentStepMeta.getStepID()).getName();
} catch (Throwable t) {
stepType = parentStepMeta.getStepID();
}
rootNode.setProperty("pluginId", parentStepMeta.getStepID());
rootNode.setProperty("stepType", stepType);
rootNode.setProperty("copies", meta.getParentStepMeta().getCopies());
rootNode.setProperty("_analyzer", this.getClass().getSimpleName());
metaverseBuilder.addNode(rootNode);
inputs = processInputs(meta);
outputs = processOutputs(meta);
Set<StepField> usedFields = getUsedFields(meta);
if (CollectionUtils.isNotEmpty(usedFields)) {
processUsedFields(usedFields);
}
Set<ComponentDerivationRecord> changes = getChanges();
for (ComponentDerivationRecord change : changes) {
mapChange(change);
}
customAnalyze(meta, rootNode);
return rootNode;
}
use of org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord in project pentaho-metaverse by pentaho.
the class StepAnalyzerTest method testGetPassthroughChanges.
@Test
public void testGetPassthroughChanges() throws Exception {
doReturn(inputs).when(analyzer).getInputs();
// assume all inputs are passthroughs
doReturn(true).when(analyzer).isPassthrough(any(StepField.class));
Set<ComponentDerivationRecord> passthroughChanges = analyzer.getPassthroughChanges();
assertTrue(CollectionUtils.isNotEmpty(passthroughChanges));
assertEquals(inputs.getFieldNames().size(), passthroughChanges.size());
for (ComponentDerivationRecord passthroughChange : passthroughChanges) {
// make sure the from field equals the to field
assertEquals(passthroughChange.getChangedEntityName(), passthroughChange.getOriginalEntityName());
}
}
use of org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord in project pentaho-metaverse by pentaho.
the class StepAnalyzerTest method testMapChange_changedFieldIsTransient.
@Test
public void testMapChange_changedFieldIsTransient() 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("nextStep", "address");
StepField changed = new StepField(null, "zip");
ComponentDerivationRecord cdr = new ComponentDerivationRecord(original, changed);
analyzer.mapChange(cdr);
verify(builder).addLink(rootNode, "transient", transientNode);
verify(analyzer).linkChangeNodes(any(IMetaverseNode.class), eq(transientNode));
}
Aggregations