Search in sources :

Example 16 with ComponentDerivationRecord

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));
}
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)

Example 17 with ComponentDerivationRecord

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

Example 18 with ComponentDerivationRecord

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

Example 19 with ComponentDerivationRecord

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;
}
Also used : NumberRangeRule(org.pentaho.di.trans.steps.numberrange.NumberRangeRule) ComponentDerivationRecord(org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord) Operation(org.pentaho.metaverse.api.model.Operation) HashSet(java.util.HashSet)

Example 20 with ComponentDerivationRecord

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

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