Search in sources :

Example 41 with ComponentDerivationRecord

use of org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord in project pentaho-metaverse by pentaho.

the class StepAnalyzerTest method testGetChanges_noPassthroughs.

@Test
public void testGetChanges_noPassthroughs() 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);
    doReturn(changeRecords).when(analyzer).getChangeRecords(baseStepMeta);
    doReturn(null).when(analyzer).getPassthroughChanges();
    Set<ComponentDerivationRecord> changes = analyzer.getChanges();
    assertTrue(CollectionUtils.isNotEmpty(changes));
    assertEquals(3, changes.size());
}
Also used : ComponentDerivationRecord(org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 42 with ComponentDerivationRecord

use of org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord in project pentaho-metaverse by pentaho.

the class StepAnalyzerTest method testAnalyze.

@Test
public void testAnalyze() throws Exception {
    when(baseStepMeta.getParentStepMeta()).thenReturn(parentStepMeta);
    when(parentStepMeta.getCopies()).thenReturn(2);
    analyzer.setMetaverseBuilder(builder);
    doNothing().when(analyzer).validateState(descriptor, baseStepMeta);
    doReturn(null).when(analyzer).processInputs(baseStepMeta);
    doReturn(null).when(analyzer).processOutputs(baseStepMeta);
    Set<StepField> usedFields = new HashSet<>();
    usedFields.add(new StepField("inputStep", "name"));
    doReturn(usedFields).when(analyzer).getUsedFields(baseStepMeta);
    doNothing().when(analyzer).processUsedFields(usedFields);
    Set<ComponentDerivationRecord> changeRecords = new HashSet<>();
    changeRecords.add(mock(ComponentDerivationRecord.class));
    changeRecords.add(mock(ComponentDerivationRecord.class));
    doReturn(changeRecords).when(analyzer).getChanges();
    doNothing().when(analyzer).mapChange(any(ComponentDerivationRecord.class));
    MetaverseTransientNode node = new MetaverseTransientNode("hello");
    doNothing().when(analyzer).customAnalyze(baseStepMeta, node);
    when(parentStepMeta.getStepID()).thenReturn("step id");
    doReturn(node).when(analyzer).createNodeFromDescriptor(descriptor);
    IMetaverseNode analyzedNode = analyzer.analyze(descriptor, baseStepMeta);
    assertNotNull(analyzedNode.getProperty("stepType"));
    assertEquals(2, analyzedNode.getProperty("copies"));
    assertEquals(analyzer.getClass().getSimpleName(), analyzedNode.getProperty("_analyzer"));
    verify(builder).addNode(analyzedNode);
    verify(analyzer).processInputs(baseStepMeta);
    verify(analyzer).processOutputs(baseStepMeta);
    verify(analyzer).getUsedFields(baseStepMeta);
    verify(analyzer).processUsedFields(usedFields);
    verify(analyzer).getChanges();
    verify(analyzer, times(changeRecords.size())).mapChange(any(ComponentDerivationRecord.class));
    verify(analyzer).customAnalyze(baseStepMeta, analyzedNode);
}
Also used : IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) StepField(org.pentaho.metaverse.api.StepField) MetaverseTransientNode(org.pentaho.dictionary.MetaverseTransientNode) ComponentDerivationRecord(org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 43 with ComponentDerivationRecord

use of org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord in project pentaho-kettle by pentaho.

the class GetXMLDataStepAnalyzer method getChangeRecords.

@Override
public Set<ComponentDerivationRecord> getChangeRecords(GetXMLDataMeta meta) throws MetaverseAnalyzerException {
    Set<ComponentDerivationRecord> changes = new HashSet<>();
    boolean isInFields = meta.isInFields();
    boolean isAFile = meta.getIsAFile();
    boolean isAUrl = meta.isReadUrl();
    // if we are getting xml from a field, we need to add the "derives" links from the xml to the output fields
    if (isInFields && !isAFile && !isAUrl) {
        GetXMLDataField[] fields = baseStepMeta.getInputFields();
        if (getInputs() != null) {
            Set<StepField> inputFields = getInputs().getFieldNames();
            for (StepField inputField : inputFields) {
                if (inputField.getFieldName().equals(meta.getXMLField())) {
                    // link this to all of the outputs that come from the xml
                    for (GetXMLDataField field : fields) {
                        ComponentDerivationRecord change = new ComponentDerivationRecord(meta.getXMLField(), field.getName());
                        changes.add(change);
                    }
                    break;
                }
            }
        }
    }
    return changes;
}
Also used : StepField(org.pentaho.metaverse.api.StepField) ComponentDerivationRecord(org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord) HashSet(java.util.HashSet)

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