Search in sources :

Example 1 with IMetaverseNode

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

the class JobExecutorStepAnalyzer method customAnalyze.

@Override
protected void customAnalyze(JobExecutorMeta meta, IMetaverseNode node) throws MetaverseAnalyzerException {
    String jobPath = meta.getFileName();
    JobMeta subJobMeta = null;
    Repository repo = parentTransMeta.getRepository();
    switch(meta.getSpecificationMethod()) {
        case FILENAME:
            jobPath = parentTransMeta.environmentSubstitute(meta.getFileName());
            try {
                String normalized = KettleAnalyzerUtil.normalizeFilePath(jobPath);
                subJobMeta = getSubJobMeta(parentTransMeta, normalized);
                jobPath = normalized;
            } catch (Exception e) {
                throw new MetaverseAnalyzerException("Sub transformation can not be found - " + jobPath, e);
            }
            break;
        case REPOSITORY_BY_NAME:
            if (repo != null) {
                String dir = parentTransMeta.environmentSubstitute(meta.getDirectoryPath());
                String file = parentTransMeta.environmentSubstitute(meta.getJobName());
                try {
                    RepositoryDirectoryInterface rdi = repo.findDirectory(dir);
                    subJobMeta = repo.loadJob(file, rdi, null, null);
                    String filename = subJobMeta.getFilename() == null ? subJobMeta.toString() : subJobMeta.getFilename();
                    jobPath = filename + "." + subJobMeta.getDefaultExtension();
                } catch (KettleException e) {
                    throw new MetaverseAnalyzerException("Sub transformation can not be found in repository - " + file, e);
                }
            } else {
                throw new MetaverseAnalyzerException("Not connected to a repository, can't get the transformation");
            }
            break;
        case REPOSITORY_BY_REFERENCE:
            if (repo != null) {
                try {
                    subJobMeta = repo.loadJob(meta.getJobObjectId(), null);
                    String filename = subJobMeta.getFilename() == null ? subJobMeta.toString() : subJobMeta.getFilename();
                    jobPath = filename + "." + subJobMeta.getDefaultExtension();
                } catch (KettleException e) {
                    throw new MetaverseAnalyzerException("Sub transformation can not be found by reference - " + meta.getJobObjectId(), e);
                }
            } else {
                throw new MetaverseAnalyzerException("Not connected to a repository, can't get the transformation");
            }
            break;
    }
    // analyze the sub trans?
    IComponentDescriptor ds = new MetaverseComponentDescriptor(subJobMeta.getName(), DictionaryConst.NODE_TYPE_JOB, descriptor.getNamespace().getParentNamespace());
    IMetaverseNode jobNode = createNodeFromDescriptor(ds);
    jobNode.setProperty(DictionaryConst.PROPERTY_NAMESPACE, ds.getNamespaceId());
    jobNode.setProperty(DictionaryConst.PROPERTY_PATH, jobPath);
    jobNode.setLogicalIdGenerator(DictionaryConst.LOGICAL_ID_GENERATOR_DOCUMENT);
    metaverseBuilder.addLink(node, DictionaryConst.LINK_EXECUTES, jobNode);
    connectToSubJobOutputFields(meta, subJobMeta, jobNode, descriptor);
    node.setProperty(JOB_TO_EXECUTE, jobPath);
    if (StringUtils.isNotEmpty(meta.getExecutionResultTargetStep())) {
        node.setProperty(EXECUTION_RESULTS_TARGET, meta.getExecutionResultTargetStep());
    }
    if (StringUtils.isNotEmpty(meta.getResultFilesTargetStep())) {
        node.setProperty(RESULT_FILES_TARGET, meta.getResultFilesTargetStep());
    }
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) KettleException(org.pentaho.di.core.exception.KettleException) JobMeta(org.pentaho.di.job.JobMeta) Repository(org.pentaho.di.repository.Repository) IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) MetaverseAnalyzerException(org.pentaho.metaverse.api.MetaverseAnalyzerException) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) KettleException(org.pentaho.di.core.exception.KettleException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettleMissingPluginsException(org.pentaho.di.core.exception.KettleMissingPluginsException) FileNotFoundException(java.io.FileNotFoundException) MetaverseAnalyzerException(org.pentaho.metaverse.api.MetaverseAnalyzerException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) MetaverseComponentDescriptor(org.pentaho.metaverse.api.MetaverseComponentDescriptor)

Example 2 with IMetaverseNode

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

the class JobExecutorStepAnalyzer method connectToSubJobOutputFields.

protected void connectToSubJobOutputFields(JobExecutorMeta meta, JobMeta subJobMeta, IMetaverseNode subTransNode, IComponentDescriptor descriptor) {
    if (meta.getResultRowsTargetStep() != null) {
        String outputStep = meta.getResultRowsTargetStep();
        for (int i = 0; i < meta.getResultRowsField().length; i++) {
            String fieldName = meta.getResultRowsField()[i];
            IMetaverseNode outNode = getOutputs().findNode(outputStep, fieldName);
        // TODO
        /* if ( outNode != null ) {
          // add link, if needed, from sub tran result fields to the node just created
           linkResultFieldToSubTrans( outNode, subJobMeta, subTransNode, descriptor );
        }*/
        }
    }
}
Also used : IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode)

Example 3 with IMetaverseNode

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

the class MergeJoinStepAnalyzer method customAnalyze.

@Override
protected void customAnalyze(MergeJoinMeta mergeJoinMeta, IMetaverseNode node) throws MetaverseAnalyzerException {
    // create links for the merging of the input streams on field(s)
    String[] keyFields1 = mergeJoinMeta.getKeyFields1();
    String[] keyFields2 = mergeJoinMeta.getKeyFields2();
    String joinType = mergeJoinMeta.getJoinType();
    String[] prevStepNames = parentTransMeta.getPrevStepNames(getStepName());
    node.setProperty(DictionaryConst.PROPERTY_JOIN_TYPE, joinType);
    node.setProperty(DictionaryConst.PROPERTY_JOIN_FIELDS_LEFT, Arrays.asList(keyFields1));
    node.setProperty(DictionaryConst.PROPERTY_JOIN_FIELDS_RIGHT, Arrays.asList(keyFields2));
    boolean isInner = MergeJoinMeta.join_types[0].equals(joinType);
    boolean isLeftOuter = MergeJoinMeta.join_types[1].equals(joinType);
    boolean isRightOuter = MergeJoinMeta.join_types[2].equals(joinType);
    boolean isFullOuter = MergeJoinMeta.join_types[3].equals(joinType);
    for (int i = 0; i < keyFields1.length; i++) {
        IMetaverseNode leftNode = getInputs().findNode(prevStepNames[0], keyFields1[i]);
        IMetaverseNode rightNode = getInputs().findNode(prevStepNames[1], keyFields2[i]);
        // handle links for join types between fields
        if ((isInner || isLeftOuter || isFullOuter) && leftNode != null && rightNode != null) {
            metaverseBuilder.addLink(leftNode, DictionaryConst.LINK_JOINS, rightNode);
        }
        if ((isInner || isRightOuter || isFullOuter) && leftNode != null && rightNode != null) {
            metaverseBuilder.addLink(rightNode, DictionaryConst.LINK_JOINS, leftNode);
        }
    }
}
Also used : IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode)

Example 4 with IMetaverseNode

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

the class MongoDbInputStepAnalyzer method createTableNode.

@Override
protected IMetaverseNode createTableNode(IExternalResourceInfo resource) throws MetaverseAnalyzerException {
    MongoDbResourceInfo resourceInfo = (MongoDbResourceInfo) resource;
    // create a node for the collection
    MetaverseComponentDescriptor componentDescriptor = new MetaverseComponentDescriptor(resourceInfo.getCollection(), DictionaryConst.NODE_TYPE_MONGODB_COLLECTION, getConnectionNode(), getDescriptor().getContext());
    // set the namespace to be the id of the connection node.
    IMetaverseNode node = createNodeFromDescriptor(componentDescriptor);
    node.setProperty(DictionaryConst.PROPERTY_NAMESPACE, componentDescriptor.getNamespace().getNamespaceId());
    node.setProperty(COLLECTION, resourceInfo.getCollection());
    node.setLogicalIdGenerator(DictionaryConst.LOGICAL_ID_GENERATOR_DEFAULT);
    return node;
}
Also used : IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) MongoDbResourceInfo(org.pentaho.metaverse.impl.model.MongoDbResourceInfo) MetaverseComponentDescriptor(org.pentaho.metaverse.api.MetaverseComponentDescriptor)

Example 5 with IMetaverseNode

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

the class RowsFromResultStepAnalyzer method processInputs.

@Override
protected StepNodes processInputs(RowsFromResultMeta meta) {
    StepNodes inputs = new StepNodes();
    // get all input steps
    String[] fieldNames = meta.getFieldname();
    for (int j = 0; j < fieldNames.length; j++) {
        String fieldName = fieldNames[j];
        RowMetaInterface rmi = null;
        try {
            rmi = parentTransMeta.getStepFields(parentStepMeta);
            int type = rmi.getValueMeta(j).getType();
            ValueMetaInterface vmi = rmi.getValueMeta(j);
            // IMetaverseNode prevFieldNode = createInputFieldNode( StepAnalyzer.NONE, fieldName, type );
            IMetaverseNode prevFieldNode = createInputFieldNode(descriptor.getContext(), vmi, StepAnalyzer.NONE, getInputNodeType());
            getMetaverseBuilder().addLink(prevFieldNode, DictionaryConst.LINK_INPUTS, rootNode);
            inputs.addNode(StepAnalyzer.NONE, fieldName, prevFieldNode);
        } catch (KettleStepException e) {
        // eat it
        }
    }
    return inputs;
}
Also used : KettleStepException(org.pentaho.di.core.exception.KettleStepException) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) StepNodes(org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Aggregations

IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)131 Test (org.junit.Test)77 IComponentDescriptor (org.pentaho.metaverse.api.IComponentDescriptor)30 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)23 MetaverseComponentDescriptor (org.pentaho.metaverse.api.MetaverseComponentDescriptor)16 ValueMeta (org.pentaho.di.core.row.ValueMeta)13 IExternalResourceInfo (org.pentaho.metaverse.api.model.IExternalResourceInfo)12 IAnalysisContext (org.pentaho.metaverse.api.IAnalysisContext)11 MetaverseAnalyzerException (org.pentaho.metaverse.api.MetaverseAnalyzerException)11 Vertex (com.tinkerpop.blueprints.Vertex)10 ArrayList (java.util.ArrayList)10 INamespace (org.pentaho.metaverse.api.INamespace)10 TransMeta (org.pentaho.di.trans.TransMeta)9 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)9 MetaverseTransientNode (org.pentaho.dictionary.MetaverseTransientNode)9 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)8 Namespace (org.pentaho.metaverse.api.Namespace)8 StepField (org.pentaho.metaverse.api.StepField)8 HashMap (java.util.HashMap)7 Matchers.anyString (org.mockito.Matchers.anyString)7