Search in sources :

Example 16 with ValueMeta

use of org.pentaho.di.core.row.ValueMeta in project pentaho-metaverse by pentaho.

the class TableOutputStepAnalyzer method getOutputRowMetaInterfaces.

@Override
protected Map<String, RowMetaInterface> getOutputRowMetaInterfaces(TableOutputMeta meta) {
    String[] nextStepNames = parentTransMeta.getNextStepNames(parentStepMeta);
    Map<String, RowMetaInterface> outputRows = new HashMap<>();
    RowMetaInterface outputFields = getOutputFields(meta);
    if (outputFields != null && ArrayUtils.isEmpty(nextStepNames)) {
        nextStepNames = new String[] { NONE };
    }
    for (String stepName : nextStepNames) {
        outputRows.put(stepName, outputFields);
    }
    RowMetaInterface tableFields = new RowMeta();
    Set<String> outFields = getOutputResourceFields(meta);
    for (String outField : outFields) {
        ValueMetaInterface vmi = new ValueMeta(outField);
        tableFields.addValueMeta(vmi);
    }
    outputRows.put(RESOURCE, tableFields);
    return outputRows;
}
Also used : HashMap(java.util.HashMap) RowMeta(org.pentaho.di.core.row.RowMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMeta(org.pentaho.di.core.row.ValueMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 17 with ValueMeta

use of org.pentaho.di.core.row.ValueMeta in project pentaho-metaverse by pentaho.

the class MongoDbInputStepAnalyzerTest method testCreateOutputFieldNode.

@Test
public void testCreateOutputFieldNode() throws Exception {
    IAnalysisContext context = mock(IAnalysisContext.class);
    ValueMetaInterface vmi = new ValueMeta("field1");
    MongoField mongoField1 = new MongoField();
    mongoField1.m_fieldName = "field1";
    mongoField1.m_fieldPath = "$.field1";
    mongoField1.m_arrayIndexInfo = "range";
    mongoField1.m_occurenceFraction = "occurence";
    mongoField1.m_indexedVals = Arrays.asList(new String[] { "one", "two" });
    mongoField1.m_disparateTypes = true;
    mongoField1.m_kettleType = "ValueMetaString";
    mongoField1.m_outputIndex = 0;
    List<MongoField> mongoFields = Arrays.asList(mongoField1);
    when(meta.getMongoFields()).thenReturn(mongoFields);
    doReturn("thisStepName").when(analyzer).getStepName();
    when(node.getLogicalId()).thenReturn("logical id");
    IMetaverseNode node = analyzer.createOutputFieldNode(context, vmi, ExternalResourceStepAnalyzer.RESOURCE, DictionaryConst.NODE_TYPE_TRANS_FIELD);
    assertNotNull(node);
    assertEquals("field1", node.getName());
    assertEquals(mongoField1.m_fieldPath, node.getProperty(MongoDbInputStepAnalyzer.JSON_PATH));
    assertEquals(mongoField1.m_arrayIndexInfo, node.getProperty(MongoDbInputStepAnalyzer.MINMAX_RANGE));
    assertEquals(mongoField1.m_occurenceFraction, node.getProperty(MongoDbInputStepAnalyzer.OCCUR_RATIO));
    assertEquals(mongoField1.m_indexedVals, node.getProperty(MongoDbInputStepAnalyzer.INDEXED_VALS));
    assertEquals(mongoField1.m_disparateTypes, node.getProperty(MongoDbInputStepAnalyzer.DISPARATE_TYPES));
}
Also used : IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) IAnalysisContext(org.pentaho.metaverse.api.IAnalysisContext) ValueMeta(org.pentaho.di.core.row.ValueMeta) MongoField(org.pentaho.mongo.wrapper.field.MongoField) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 18 with ValueMeta

use of org.pentaho.di.core.row.ValueMeta in project pentaho-metaverse by pentaho.

the class StepAnalyzer method mapChange.

/**
 * Add the required "derives" links to the metaverse for a ComponentDerivationRecord
 *
 * @param change
 */
protected void mapChange(ComponentDerivationRecord change) {
    if (change != null) {
        List<IMetaverseNode> inputNodes = new ArrayList<>();
        List<IMetaverseNode> outputNodes = new ArrayList<>();
        if (StringUtils.isNotEmpty(change.getOriginalEntityStepName())) {
            inputNodes.add(getInputs().findNode(change.getOriginalField()));
        } else {
            inputNodes.addAll(getInputs().findNodes(change.getOriginalEntityName()));
        }
        if (StringUtils.isNotEmpty(change.getChangedEntityStepName())) {
            outputNodes.add(getOutputs().findNode(change.getChangedField()));
        } else {
            outputNodes.addAll(getOutputs().findNodes(change.getChangedEntityName()));
        }
        if (CollectionUtils.isEmpty(inputNodes)) {
            // see if it's one of the output nodes
            inputNodes = getOutputs().findNodes(change.getOriginalEntityName());
            // if we still don't have it, we need a transient node created
            if (CollectionUtils.isEmpty(inputNodes)) {
                // create a transient node for it
                ValueMetaInterface tmp = new ValueMeta(change.getOriginalEntityName());
                IMetaverseNode fieldNode = createOutputFieldNode(getDescriptor().getContext(), tmp, null, getTransientNodeType());
                // Add link to show that this step created this as a transient field
                getMetaverseBuilder().addLink(rootNode, DictionaryConst.LINK_TRANSIENT, fieldNode);
                getMetaverseBuilder().addLink(rootNode, DictionaryConst.LINK_USES, fieldNode);
                inputNodes.add(fieldNode);
            }
        }
        if (CollectionUtils.isEmpty(outputNodes)) {
            // create a transient node for it
            ValueMetaInterface tmp = new ValueMeta(change.getChangedEntityName());
            IMetaverseNode fieldNode = createOutputFieldNode(getDescriptor().getContext(), tmp, null, getTransientNodeType());
            // Add link to show that this step created this as a transient field
            getMetaverseBuilder().addLink(rootNode, DictionaryConst.LINK_TRANSIENT, fieldNode);
            getMetaverseBuilder().addLink(rootNode, DictionaryConst.LINK_USES, fieldNode);
            outputNodes.add(fieldNode);
        }
        // no input step was defined, link all field name matches together, regardless of origin step
        for (IMetaverseNode inputNode : inputNodes) {
            for (IMetaverseNode outputNode : outputNodes) {
                if (change.getOperations().size() > 0) {
                    outputNode.setProperty(DictionaryConst.PROPERTY_OPERATIONS, change.toString());
                }
                linkChangeNodes(inputNode, outputNode);
            }
        }
    }
}
Also used : IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) ArrayList(java.util.ArrayList) ValueMeta(org.pentaho.di.core.row.ValueMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 19 with ValueMeta

use of org.pentaho.di.core.row.ValueMeta in project pentaho-metaverse by pentaho.

the class ExternalResourceStepAnalyzerTest method testGetInputFieldsToIgnore.

@Test
public void testGetInputFieldsToIgnore() {
    doReturn(true).when(analyzer).isInput();
    // setup input fields
    RowMetaInterface inputFieldRowMeta = mock(RowMetaInterface.class);
    List<ValueMetaInterface> inputFields = new ArrayList<>();
    inputFields.add(new ValueMeta("in_field_1"));
    Map<String, RowMetaInterface> inputFieldRowMetaMap = new HashMap<>();
    inputFieldRowMetaMap.put(ExternalResourceStepAnalyzer.RESOURCE, inputFieldRowMeta);
    when(inputFieldRowMeta.getValueMetaList()).thenReturn(inputFields);
    // setup output fields
    List<ValueMetaInterface> outputFields = new ArrayList<>();
    outputFields.addAll(inputFields);
    outputFields.add(new ValueMeta("file_field_1"));
    outputFields.add(new ValueMeta("additional_field"));
    outputFields.add(new ValueMeta("file_field_2"));
    RowMetaInterface outputFieldsRowMeta = mock(RowMetaInterface.class);
    when(outputFieldsRowMeta.getValueMetaList()).thenReturn(outputFields);
    // setup step "resource" fields
    final BaseFileField[] resourceFields = new BaseFileField[2];
    resourceFields[0] = new BaseFileField("file_field_1", 0, 0);
    resourceFields[1] = new BaseFileField("file_field_2", 0, 0);
    doReturn(resourceFields).when(fileMeta).getInputFields();
    Set<String> fieldsToIgnore = analyzer.getInputFieldsToIgnore(fileMeta, inputFieldRowMetaMap, outputFieldsRowMeta);
    assertEquals(2, fieldsToIgnore.size());
    assertTrue(fieldsToIgnore.contains("in_field_1"));
    assertTrue(fieldsToIgnore.contains("additional_field"));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BaseFileField(org.pentaho.di.trans.steps.file.BaseFileField) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMeta(org.pentaho.di.core.row.ValueMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 20 with ValueMeta

use of org.pentaho.di.core.row.ValueMeta in project pentaho-metaverse by pentaho.

the class ExternalResourceStepAnalyzerTest method testCreateInputFieldNode_resource.

@Test
public void testCreateInputFieldNode_resource() throws Exception {
    IAnalysisContext context = mock(IAnalysisContext.class);
    doReturn("thisStepName").when(analyzer).getStepName();
    analyzer.rootNode = node;
    when(node.getLogicalId()).thenReturn("logical id");
    ValueMetaInterface vmi = new ValueMeta("name", 1);
    IMetaverseNode inputFieldNode = analyzer.createInputFieldNode(context, vmi, ExternalResourceStepAnalyzer.RESOURCE, DictionaryConst.NODE_TYPE_TRANS_FIELD);
    assertNotNull(inputFieldNode);
    assertNotNull(inputFieldNode.getProperty(DictionaryConst.PROPERTY_KETTLE_TYPE));
    assertEquals("thisStepName", inputFieldNode.getProperty(DictionaryConst.PROPERTY_TARGET_STEP));
    assertEquals("INPUT_TYPE", inputFieldNode.getType());
    // the input node should be added by this step
    verify(builder).addNode(inputFieldNode);
}
Also used : IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) IAnalysisContext(org.pentaho.metaverse.api.IAnalysisContext) ValueMeta(org.pentaho.di.core.row.ValueMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Aggregations

ValueMeta (org.pentaho.di.core.row.ValueMeta)47 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)39 Test (org.junit.Test)18 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)14 IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)13 RowMeta (org.pentaho.di.core.row.RowMeta)12 IAnalysisContext (org.pentaho.metaverse.api.IAnalysisContext)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)6 KettleValueException (org.pentaho.di.core.exception.KettleValueException)5 MetaverseTransientNode (org.pentaho.dictionary.MetaverseTransientNode)5 IComponentDescriptor (org.pentaho.metaverse.api.IComponentDescriptor)5 KettleException (org.pentaho.di.core.exception.KettleException)4 KettleStepException (org.pentaho.di.core.exception.KettleStepException)4 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)3 Matchers.anyString (org.mockito.Matchers.anyString)2 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)2 BatchUpdateException (java.sql.BatchUpdateException)1 Blob (java.sql.Blob)1 ResultSet (java.sql.ResultSet)1