Search in sources :

Example 1 with IComponentDescriptor

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

the class TransExecutorStepAnalyzer method linkResultFieldToSubTrans.

/**
 * Checks to see if the sub trans has any RowToResult steps in it.
 * If so, it will link the fields it outputs to the fields created by this step and are sent to the
 * "target step for output rows".
 *
 * @param streamFieldNode stream field node sent to the step defined as "target step for output rows"
 * @param subTransMeta TransMeta of the transformation to be executed by the TransExecutor step
 * @param subTransNode IMetaverseNode representing the sub-transformation to be executed
 * @param descriptor Descriptor to use as a basis for any nodes created
 */
protected void linkResultFieldToSubTrans(IMetaverseNode streamFieldNode, TransMeta subTransMeta, IMetaverseNode subTransNode, IComponentDescriptor descriptor) {
    List<StepMeta> steps = subTransMeta.getSteps();
    if (!CollectionUtils.isEmpty(steps)) {
        for (StepMeta step : steps) {
            if (step.getStepMetaInterface() instanceof RowsToResultMeta) {
                RowsToResultMeta rtrm = (RowsToResultMeta) step.getStepMetaInterface();
                // Create a new descriptor for the RowsToResult step.
                IComponentDescriptor stepDescriptor = new MetaverseComponentDescriptor(step.getName(), DictionaryConst.NODE_TYPE_TRANS_STEP, subTransNode, descriptor.getContext());
                // Create a new node for the step, to be used as the parent of the the field we want to link to
                IMetaverseNode subTransStepNode = createNodeFromDescriptor(stepDescriptor);
                try {
                    RowMetaInterface rowMetaInterface = rtrm.getParentStepMeta().getParentTransMeta().getStepFields(step);
                    for (int i = 0; i < rowMetaInterface.getFieldNames().length; i++) {
                        String field = rowMetaInterface.getFieldNames()[i];
                        if (streamFieldNode.getName().equals(field)) {
                            // Create the descriptor for the trans field that is derived from the incoming result field
                            IComponentDescriptor stepFieldDescriptor = new MetaverseComponentDescriptor(field, DictionaryConst.NODE_TYPE_TRANS_FIELD, subTransStepNode, descriptor.getContext());
                            // Create the node
                            // IMetaverseNode subTransField = createNodeFromDescriptor( stepFieldDescriptor );
                            IMetaverseNode subTransField = createFieldNode(stepFieldDescriptor, rowMetaInterface.getValueMeta(i), StepAnalyzer.NONE, false);
                            // Add the link
                            metaverseBuilder.addLink(subTransField, DictionaryConst.LINK_DERIVES, streamFieldNode);
                            // no need to keep looking for a match on field name, we just handled it.
                            continue;
                        }
                    }
                } catch (KettleStepException e) {
                    log.warn("Could not get step fields of RowsToResult step in sub transformation - " + subTransMeta.getName(), e);
                }
            }
        }
    }
}
Also used : IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) KettleStepException(org.pentaho.di.core.exception.KettleStepException) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) RowsToResultMeta(org.pentaho.di.trans.steps.rowstoresult.RowsToResultMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) MetaverseComponentDescriptor(org.pentaho.metaverse.api.MetaverseComponentDescriptor)

Example 2 with IComponentDescriptor

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

the class TransExecutorStepAnalyzer method linkUsedFieldToSubTrans.

/**
 * Checks to see if the sub trans has any RowFromResult steps in it.
 * If so, it will link the original field node to the fields created in the RowFromResult step in the sub trans
 *
 * @param originalFieldNode incoming stream field node to the TransExecutorStep
 * @param subTransMeta TransMeta of the transformation to be executed by the TransExecutor step
 * @param subTransNode IMetaverseNode representing the sub-transformation to be executed
 * @param descriptor Descriptor to use as a basis
 */
protected void linkUsedFieldToSubTrans(IMetaverseNode originalFieldNode, TransMeta subTransMeta, IMetaverseNode subTransNode, IComponentDescriptor descriptor) {
    List<StepMeta> steps = subTransMeta.getSteps();
    if (!CollectionUtils.isEmpty(steps)) {
        for (StepMeta step : steps) {
            if (step.getStepMetaInterface() instanceof RowsFromResultMeta) {
                RowsFromResultMeta rfrm = (RowsFromResultMeta) step.getStepMetaInterface();
                // Create a new descriptor for the RowsFromResult step.
                IComponentDescriptor stepDescriptor = new MetaverseComponentDescriptor(StepAnalyzer.NONE, DictionaryConst.NODE_TYPE_TRANS_STEP, subTransNode, descriptor.getContext());
                // Create a new node for the step, to be used as the parent of the the field we want to link to
                IMetaverseNode subTransStepNode = createNodeFromDescriptor(stepDescriptor);
                try {
                    RowMetaInterface rowMetaInterface = rfrm.getParentStepMeta().getParentTransMeta().getStepFields(step);
                    for (int i = 0; i < rowMetaInterface.getFieldNames().length; i++) {
                        String field = rowMetaInterface.getFieldNames()[i];
                        if (originalFieldNode.getName().equals(field)) {
                            // Create the descriptor for the trans field that is derived from the incoming result field
                            IComponentDescriptor stepFieldDescriptor = new MetaverseComponentDescriptor(field, DictionaryConst.NODE_TYPE_TRANS_FIELD, subTransStepNode, descriptor.getContext());
                            // Create the node
                            IMetaverseNode subTransField = createFieldNode(stepFieldDescriptor, rowMetaInterface.getValueMeta(i), step.getName(), false);
                            // Add the link
                            metaverseBuilder.addLink(originalFieldNode, DictionaryConst.LINK_DERIVES, subTransField);
                            // no need to keep looking for a match on field name, we just handled it.
                            continue;
                        }
                    }
                } catch (KettleStepException e) {
                    log.warn("Could not get step fields of RowsFromResult step in sub transformation - " + subTransMeta.getName(), e);
                }
            }
        }
    }
}
Also used : IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) KettleStepException(org.pentaho.di.core.exception.KettleStepException) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) RowsFromResultMeta(org.pentaho.di.trans.steps.rowsfromresult.RowsFromResultMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) MetaverseComponentDescriptor(org.pentaho.metaverse.api.MetaverseComponentDescriptor)

Example 3 with IComponentDescriptor

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

the class StepAnalyzerTest method testGetInputFieldsWithException.

@Test
public void testGetInputFieldsWithException() {
    analyzer = new StepAnalyzer() {

        @Override
        public void validateState(IComponentDescriptor descriptor, BaseStepMeta object) throws MetaverseAnalyzerException {
            throw new MetaverseAnalyzerException("expected exception");
        }

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

        @Override
        protected Set getUsedFields(BaseStepMeta meta) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        protected void customAnalyze(BaseStepMeta meta, IMetaverseNode rootNode) throws MetaverseAnalyzerException {
        // TODO Auto-generated method stub
        }
    };
    assertNull(analyzer.getInputFields(null));
}
Also used : IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) HashSet(java.util.HashSet) Set(java.util.Set) MetaverseAnalyzerException(org.pentaho.metaverse.api.MetaverseAnalyzerException) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) Test(org.junit.Test)

Example 4 with IComponentDescriptor

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

the class StepAnalyzerTest method testCreateFieldNode.

@Test
public void testCreateFieldNode() throws Exception {
    IComponentDescriptor fieldDescriptor = mock(IComponentDescriptor.class);
    ValueMetaInterface fieldMeta = new ValueMeta("address");
    MetaverseTransientNode node = new MetaverseTransientNode("hello");
    doReturn(node).when(analyzer).createNodeFromDescriptor(fieldDescriptor);
    IMetaverseNode fieldNode = analyzer.createFieldNode(fieldDescriptor, fieldMeta, "nextStep", true);
    assertNotNull(fieldNode);
    assertNotNull(fieldNode.getProperty(DictionaryConst.PROPERTY_KETTLE_TYPE));
    assertEquals("nextStep", fieldNode.getProperty(DictionaryConst.PROPERTY_TARGET_STEP));
    // make sure it got added to the graph
    verify(builder).addNode(node);
}
Also used : IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) MetaverseTransientNode(org.pentaho.dictionary.MetaverseTransientNode) ValueMeta(org.pentaho.di.core.row.ValueMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 5 with IComponentDescriptor

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

the class BaseKettleMetaverseComponentTest method testCreateNodeFromDescriptor.

@Test
public void testCreateNodeFromDescriptor() throws Exception {
    String namespaceId = "{namespace: 'my namespace', name: 'my name', type: 'my type'}";
    ILogicalIdGenerator idGenerator = DictionaryConst.LOGICAL_ID_GENERATOR_DEFAULT;
    IComponentDescriptor descriptor = mock(IComponentDescriptor.class);
    INamespace ns = mock(INamespace.class);
    when(descriptor.getParentNamespace()).thenReturn(mock(INamespace.class));
    when(descriptor.getNamespace()).thenReturn(ns);
    when(ns.getNamespaceId()).thenReturn(namespaceId);
    component.metaverseObjectFactory = spy(new MetaverseObjectFactory());
    IMetaverseNode node = component.createNodeFromDescriptor(descriptor, idGenerator);
    assertNotNull(node);
    assertTrue(node.getLogicalId().contains(namespaceId));
}
Also used : IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) ILogicalIdGenerator(org.pentaho.metaverse.api.ILogicalIdGenerator) INamespace(org.pentaho.metaverse.api.INamespace) MetaverseObjectFactory(org.pentaho.metaverse.api.MetaverseObjectFactory) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

IComponentDescriptor (org.pentaho.metaverse.api.IComponentDescriptor)27 IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)22 MetaverseComponentDescriptor (org.pentaho.metaverse.api.MetaverseComponentDescriptor)16 Test (org.junit.Test)10 MetaverseAnalyzerException (org.pentaho.metaverse.api.MetaverseAnalyzerException)9 INamespace (org.pentaho.metaverse.api.INamespace)8 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)6 KettleStepException (org.pentaho.di.core.exception.KettleStepException)5 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)5 JobMeta (org.pentaho.di.job.JobMeta)5 StepMeta (org.pentaho.di.trans.step.StepMeta)5 Namespace (org.pentaho.metaverse.api.Namespace)5 KettleException (org.pentaho.di.core.exception.KettleException)4 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)4 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)4 TransMeta (org.pentaho.di.trans.TransMeta)4 IDocument (org.pentaho.metaverse.api.IDocument)4 FileNotFoundException (java.io.FileNotFoundException)3 KettleMissingPluginsException (org.pentaho.di.core.exception.KettleMissingPluginsException)3 ValueMeta (org.pentaho.di.core.row.ValueMeta)3