Search in sources :

Example 36 with ComponentDerivationRecord

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);
}
Also used : IFieldLineageMetadataProvider(org.pentaho.metaverse.api.analyzer.kettle.step.IFieldLineageMetadataProvider) ComponentDerivationRecord(org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 37 with ComponentDerivationRecord

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;
}
Also used : StepField(org.pentaho.metaverse.api.StepField) ComponentDerivationRecord(org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord) HashSet(java.util.HashSet)

Example 38 with ComponentDerivationRecord

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;
}
Also used : StepField(org.pentaho.metaverse.api.StepField) ComponentDerivationRecord(org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord)

Example 39 with ComponentDerivationRecord

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());
    }
}
Also used : StepField(org.pentaho.metaverse.api.StepField) ComponentDerivationRecord(org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord) Test(org.junit.Test)

Example 40 with ComponentDerivationRecord

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));
}
Also used : IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) StepField(org.pentaho.metaverse.api.StepField) ComponentDerivationRecord(org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord) IAnalysisContext(org.pentaho.metaverse.api.IAnalysisContext) Matchers.anyString(org.mockito.Matchers.anyString) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Aggregations

ComponentDerivationRecord (org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord)43 Test (org.junit.Test)23 HashSet (java.util.HashSet)21 StepField (org.pentaho.metaverse.api.StepField)11 Operation (org.pentaho.metaverse.api.model.Operation)11 Matchers.anyString (org.mockito.Matchers.anyString)5 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)5 IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)5 IOperation (org.pentaho.metaverse.api.model.IOperation)3 Operations (org.pentaho.metaverse.api.model.Operations)3 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)2 SelectMetadataChange (org.pentaho.di.trans.steps.selectvalues.SelectMetadataChange)2 IAnalysisContext (org.pentaho.metaverse.api.IAnalysisContext)2 IFieldLineageMetadataProvider (org.pentaho.metaverse.api.analyzer.kettle.step.IFieldLineageMetadataProvider)2 StepNodes (org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes)2 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 Condition (org.pentaho.di.core.Condition)1 CalculatorMetaFunction (org.pentaho.di.trans.steps.calculator.CalculatorMetaFunction)1 NumberRangeRule (org.pentaho.di.trans.steps.numberrange.NumberRangeRule)1