Search in sources :

Example 41 with StepField

use of org.pentaho.metaverse.api.StepField in project pentaho-metaverse by pentaho.

the class TransExecutorStepAnalyzerTest method testGetUsedFields.

@Test
public void testGetUsedFields() throws Exception {
    IMetaverseNode outNode = mock(IMetaverseNode.class);
    StepNodes inputs = new StepNodes();
    inputs.addNode("previousStep", "one", outNode);
    inputs.addNode("previousStep", "two", outNode);
    doReturn(inputs).when(spyAnalyzer).getInputs();
    Set<StepField> usedFields = spyAnalyzer.getUsedFields(meta);
    assertEquals(inputs.getFieldNames(), usedFields);
}
Also used : IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) StepField(org.pentaho.metaverse.api.StepField) StepNodes(org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes) Test(org.junit.Test)

Example 42 with StepField

use of org.pentaho.metaverse.api.StepField in project pentaho-metaverse by pentaho.

the class TransExecutorStepAnalyzerTest method testIsPassthrough.

@Test
public void testIsPassthrough() throws Exception {
    StepField stepField = new StepField("previousStep", "one");
    assertFalse(spyAnalyzer.isPassthrough(stepField));
}
Also used : StepField(org.pentaho.metaverse.api.StepField) Test(org.junit.Test)

Example 43 with StepField

use of org.pentaho.metaverse.api.StepField 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 44 with StepField

use of org.pentaho.metaverse.api.StepField 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 45 with StepField

use of org.pentaho.metaverse.api.StepField in project pentaho-metaverse by pentaho.

the class ExternalResourceStepAnalyzerTest method setUp.

@Before
public void setUp() throws Exception {
    analyzer = spy(new ExternalResourceStepAnalyzer<BaseStepMeta>() {

        @Override
        public Set<Class<? extends BaseStepMeta>> getSupportedSteps() {
            return null;
        }

        @Override
        protected Set<StepField> getUsedFields(BaseStepMeta meta) {
            Set<StepField> stepFields = new HashSet<>();
            stepFields.add(new StepField("prevStep", "filename"));
            return stepFields;
        }

        @Override
        public IMetaverseNode createResourceNode(IExternalResourceInfo resource) throws MetaverseException {
            return resourceNode;
        }

        @Override
        public String getResourceInputNodeType() {
            return "INPUT_TYPE";
        }

        @Override
        public String getResourceOutputNodeType() {
            return "OUTPUT_TYPE";
        }

        @Override
        public boolean isOutput() {
            return false;
        }

        @Override
        public boolean isInput() {
            return true;
        }
    });
    when(analyzer.getMetaverseBuilder()).thenReturn(builder);
    analyzer.descriptor = descriptor;
    analyzer.parentTransMeta = parentTransMeta;
    analyzer.parentStepMeta = parentStepMeta;
    analyzer.setMetaverseObjectFactory(new MetaverseObjectFactory());
}
Also used : IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) MetaverseObjectFactory(org.pentaho.metaverse.api.MetaverseObjectFactory) StepField(org.pentaho.metaverse.api.StepField) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) HashSet(java.util.HashSet) Before(org.junit.Before)

Aggregations

StepField (org.pentaho.metaverse.api.StepField)53 Test (org.junit.Test)33 HashSet (java.util.HashSet)23 StepNodes (org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes)11 IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)10 ComponentDerivationRecord (org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord)10 Matchers.anyString (org.mockito.Matchers.anyString)6 Before (org.junit.Before)4 SelectMetadataChange (org.pentaho.di.trans.steps.selectvalues.SelectMetadataChange)4 Set (java.util.Set)3 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)3 MetaverseObjectFactory (org.pentaho.metaverse.api.MetaverseObjectFactory)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)2 IAnalysisContext (org.pentaho.metaverse.api.IAnalysisContext)2 IExternalResourceInfo (org.pentaho.metaverse.api.model.IExternalResourceInfo)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 Graph (com.tinkerpop.blueprints.Graph)1 Vertex (com.tinkerpop.blueprints.Vertex)1