Search in sources :

Example 21 with ValueMeta

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

the class ExternalResourceStepAnalyzerTest method testGetInputRowMetaInterfaces_isInputAndIncomingNodes.

@Test
public void testGetInputRowMetaInterfaces_isInputAndIncomingNodes() throws Exception {
    Map<String, RowMetaInterface> inputs = new HashMap<>();
    RowMetaInterface inputRmi = mock(RowMetaInterface.class);
    List<ValueMetaInterface> vmis = new ArrayList<>();
    ValueMetaInterface vmi = new ValueMeta("filename");
    vmis.add(vmi);
    when(inputRmi.getValueMetaList()).thenReturn(vmis);
    inputs.put("test", inputRmi);
    doReturn(inputs).when(analyzer).getInputFields(meta);
    when(parentTransMeta.getPrevStepNames(parentStepMeta)).thenReturn(null);
    RowMetaInterface rowMetaInterface = new RowMeta();
    rowMetaInterface.addValueMeta(vmi);
    ValueMetaInterface vmi2 = new ValueMeta("otherField");
    rowMetaInterface.addValueMeta(vmi2);
    doReturn(rowMetaInterface).when(analyzer).getOutputFields(meta);
    doReturn(true).when(analyzer).isInput();
    Map<String, RowMetaInterface> rowMetaInterfaces = analyzer.getInputRowMetaInterfaces(meta);
    assertNotNull(rowMetaInterfaces);
    assertEquals(2, rowMetaInterfaces.size());
    RowMetaInterface metaInterface = rowMetaInterfaces.get(ExternalResourceStepAnalyzer.RESOURCE);
    // the row meta interface should only have 1 value meta in it, and it should NOT be filename
    assertEquals(1, metaInterface.size());
    assertEquals("otherField", metaInterface.getFieldNames()[0]);
}
Also used : HashMap(java.util.HashMap) RowMeta(org.pentaho.di.core.row.RowMeta) ArrayList(java.util.ArrayList) 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 22 with ValueMeta

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

the class StepAnalyzerTest method testProcessOutputs.

@Test
public void testProcessOutputs() throws Exception {
    Map<String, RowMetaInterface> outputRmis = new HashMap<>();
    RowMetaInterface rowMetaInterface = mock(RowMetaInterface.class);
    outputRmis.put("nextStep", rowMetaInterface);
    List<ValueMetaInterface> vmis = new ArrayList<>();
    vmis.add(new ValueMeta("full name"));
    vmis.add(new ValueMeta("address"));
    vmis.add(new ValueMeta("email"));
    vmis.add(new ValueMeta("date of birth"));
    vmis.add(new ValueMeta("ID"));
    vmis.add(new ValueMeta("occupation"));
    doReturn(outputRmis).when(analyzer).getOutputRowMetaInterfaces(baseStepMeta);
    when(rowMetaInterface.getValueMetaList()).thenReturn(vmis);
    doReturn(fieldNode).when(analyzer).createOutputFieldNode(any(IAnalysisContext.class), any(ValueMetaInterface.class), eq("nextStep"), eq(DictionaryConst.NODE_TYPE_TRANS_FIELD));
    StepNodes stepNodes = analyzer.processOutputs(baseStepMeta);
    assertEquals(1, stepNodes.getStepNames().size());
    assertEquals(vmis.size(), stepNodes.getFieldNames().size());
    for (ValueMetaInterface vmi : vmis) {
        // make sure we added one node for each ValueMetaInterface
        verify(analyzer).createOutputFieldNode(any(IAnalysisContext.class), eq(vmi), eq("nextStep"), eq(DictionaryConst.NODE_TYPE_TRANS_FIELD));
    }
    verify(builder, times(vmis.size())).addLink(rootNode, DictionaryConst.LINK_OUTPUTS, fieldNode);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) IAnalysisContext(org.pentaho.metaverse.api.IAnalysisContext) Matchers.anyString(org.mockito.Matchers.anyString) ValueMeta(org.pentaho.di.core.row.ValueMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 23 with ValueMeta

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

the class StepAnalyzerTest method testProcessInputs.

@Test
public void testProcessInputs() throws Exception {
    String[] prevStepNames = new String[] { "prevStep", "prevStep2" };
    when(parentTransMeta.getPrevStepNames(parentStepMeta)).thenReturn(prevStepNames);
    Map<String, RowMetaInterface> inputRmis = new HashMap<>();
    RowMetaInterface rowMetaInterface = mock(RowMetaInterface.class);
    RowMetaInterface rowMetaInterface2 = mock(RowMetaInterface.class);
    inputRmis.put("prevStep", rowMetaInterface);
    inputRmis.put("prevStep2", rowMetaInterface2);
    String[] inputFields1 = new String[] { "name", "address", "email", "age" };
    String[] inputFields2 = new String[] { "employeeNumber", "occupation" };
    when(rowMetaInterface.getFieldNames()).thenReturn(inputFields1);
    when(rowMetaInterface2.getFieldNames()).thenReturn(inputFields2);
    final List<ValueMetaInterface> vmis = new ArrayList<>();
    for (String s : inputFields1) {
        vmis.add(new ValueMeta(s));
    }
    final List<ValueMetaInterface> vmis2 = new ArrayList<>();
    for (String s : inputFields2) {
        vmis2.add(new ValueMeta(s));
    }
    when(rowMetaInterface.getValueMetaList()).thenReturn(vmis);
    when(rowMetaInterface2.getValueMetaList()).thenReturn(vmis2);
    IMetaverseNode inputNode = mock(IMetaverseNode.class);
    doReturn(inputRmis).when(analyzer).getInputRowMetaInterfaces(baseStepMeta);
    doReturn(inputNode).when(analyzer).createInputFieldNode(any(IAnalysisContext.class), any(ValueMetaInterface.class), anyString(), anyString());
    StepNodes stepNodes = analyzer.processInputs(baseStepMeta);
    assertNotNull(stepNodes);
    verify(builder, times(6)).addLink(any(IMetaverseNode.class), eq(DictionaryConst.LINK_INPUTS), eq(rootNode));
}
Also used : HashMap(java.util.HashMap) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) ArrayList(java.util.ArrayList) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) IAnalysisContext(org.pentaho.metaverse.api.IAnalysisContext) Matchers.anyString(org.mockito.Matchers.anyString) ValueMeta(org.pentaho.di.core.row.ValueMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 24 with ValueMeta

use of org.pentaho.di.core.row.ValueMeta 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 25 with ValueMeta

use of org.pentaho.di.core.row.ValueMeta in project pdi-dataservice-server-plugin by pentaho.

the class ValueMetaResolver method tryConversionWithMask.

private Object tryConversionWithMask(ValueMetaInterface valueMeta, int originalType, Object value, String mask) throws PushDownOptimizationException {
    ValueMeta originalTypeMeta = new ValueMeta(null, originalType);
    originalTypeMeta.setConversionMask(mask);
    try {
        return valueMeta.convertData(originalTypeMeta, value);
    } catch (KettleValueException e) {
        throw new PushDownOptimizationException("Failed to convert type", e);
    }
}
Also used : KettleValueException(org.pentaho.di.core.exception.KettleValueException) ValueMeta(org.pentaho.di.core.row.ValueMeta)

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