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]);
}
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);
}
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));
}
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);
}
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);
}
}
Aggregations