Search in sources :

Example 1 with StreamFieldNode

use of org.pentaho.metaverse.frames.StreamFieldNode in project pentaho-metaverse by pentaho.

the class MetaverseValidationIT method testSelectValuesStep.

@Test
public void testSelectValuesStep() throws Exception {
    // this tests a specific select values step. the one in trans "Populate Table From File"
    SelectValuesTransStepNode selectValues = root.getSelectValuesStepNode();
    assertNotNull(selectValues);
    int countUses = getIterableSize(selectValues.getStreamFieldNodesUses());
    int countOutputs = getIterableSize(selectValues.getOutputStreamFields());
    int countInputs = getIterableSize(selectValues.getInputStreamFields());
    assertEquals(9, countUses);
    SelectValuesMeta meta = (SelectValuesMeta) getStepMeta(selectValues);
    assertEquals(getExpectedOutputFieldCount(meta), countOutputs);
    assertEquals(9, countInputs);
    assertEquals("Select values", selectValues.getStepType());
    for (StreamFieldNode node : selectValues.getOutputStreamFields()) {
        // check for operations
        if (node.getOperations() != null) {
            Operations ops = MetaverseUtil.convertOperationsStringToMap(node.getOperations());
            assertNotNull(ops);
            List<IOperation> metadataOps = ops.get(ChangeType.METADATA);
            assertNotNull(metadataOps);
            assertTrue(metadataOps.size() > 0);
            // there should not be any data operations on nodes touched by this step
            assertNull(ops.get(ChangeType.DATA));
        }
        // check the created node is derived from something
        Iterable<StreamFieldNode> deriveNodes = node.getFieldNodesThatDeriveMe();
        for (StreamFieldNode deriveNode : deriveNodes) {
            assertNotNull(deriveNode);
        }
    }
}
Also used : IOperation(org.pentaho.metaverse.api.model.IOperation) SelectValuesMeta(org.pentaho.di.trans.steps.selectvalues.SelectValuesMeta) StreamFieldNode(org.pentaho.metaverse.frames.StreamFieldNode) Operations(org.pentaho.metaverse.api.model.Operations) SelectValuesTransStepNode(org.pentaho.metaverse.frames.SelectValuesTransStepNode) Test(org.junit.Test)

Example 2 with StreamFieldNode

use of org.pentaho.metaverse.frames.StreamFieldNode in project pentaho-metaverse by pentaho.

the class MetaverseValidationIT method testTableOutputStepNode.

@Test
public void testTableOutputStepNode() throws Exception {
    // this tests a specific step in a specific transform
    TableOutputStepNode node = root.getTableOutputStepNode();
    // check the table that it writes to
    TableOutputMeta meta = (TableOutputMeta) getStepMeta(node);
    String tableName = meta.getTableName();
    String schema = meta.getSchemaName();
    boolean truncateTable = meta.truncateTable();
    DatabaseTableNode databaseTableNode = node.getDatabaseTable();
    assertEquals(tableName, databaseTableNode.getName());
    assertEquals(schema, node.getSchema());
    assertEquals(truncateTable, node.isTruncateTable());
    Iterable<StreamFieldNode> inputs = node.getInputStreamFields();
    Iterable<StreamFieldNode> outputs = node.getOutputStreamFields();
    assertEquals(getIterableSize(inputs) + meta.getFieldDatabase().length, getIterableSize(outputs));
    for (StreamFieldNode input : inputs) {
        assertEquals(input.getName(), input.getFieldPopulatedByMe().getName());
    }
    DatasourceNode datasource = node.getDatasource(meta.getDatabaseMeta().getName());
    assertEquals(meta.getDatabaseMeta().getHostname(), datasource.getHost());
    assertEquals(meta.getDatabaseMeta().getDatabasePortNumberString(), datasource.getPort());
    assertEquals(meta.getDatabaseMeta().getUsername(), datasource.getUserName());
    assertEquals(meta.getDatabaseMeta().getDatabaseName(), datasource.getDatabaseName());
    assertEquals(DictionaryConst.NODE_TYPE_DATASOURCE, datasource.getType());
    assertEquals(meta.getTableName(), databaseTableNode.getName());
    assertEquals(DictionaryConst.NODE_TYPE_DATA_TABLE, databaseTableNode.getType());
}
Also used : MongoDbDatasourceNode(org.pentaho.metaverse.frames.MongoDbDatasourceNode) DatasourceNode(org.pentaho.metaverse.frames.DatasourceNode) DatabaseTableNode(org.pentaho.metaverse.frames.DatabaseTableNode) TableOutputMeta(org.pentaho.di.trans.steps.tableoutput.TableOutputMeta) StreamFieldNode(org.pentaho.metaverse.frames.StreamFieldNode) TableOutputStepNode(org.pentaho.metaverse.frames.TableOutputStepNode) Test(org.junit.Test)

Example 3 with StreamFieldNode

use of org.pentaho.metaverse.frames.StreamFieldNode in project pentaho-metaverse by pentaho.

the class MetaverseValidationIT method testNumberRangeStepNode_newField.

@Test
public void testNumberRangeStepNode_newField() throws Exception {
    TransformationStepNode numberRangeStepNode = root.getStepNode("number_range", "Number range");
    assertEquals(1, getIterableSize(numberRangeStepNode.getStreamFieldNodesUses()));
    StreamFieldNode usesNode = null;
    for (StreamFieldNode node : numberRangeStepNode.getStreamFieldNodesUses()) {
        usesNode = node;
        break;
    }
    NumberRangeMeta meta = (NumberRangeMeta) getStepMeta(numberRangeStepNode);
    assertEquals(meta.getInputField(), usesNode.getName());
    assertNull(usesNode.getOperations());
    Iterable<StreamFieldNode> outFields = numberRangeStepNode.getOutputStreamFields();
    int countOutputs = getIterableSize(outFields);
    assertEquals(2, countOutputs);
    for (StreamFieldNode outField : outFields) {
        assertNotNull(outField.getKettleType());
        if (outField.getName().equals(meta.getOutputField())) {
            Iterable<StreamFieldNode> fieldNodesThatDeriveMe = outField.getFieldNodesThatDeriveMe();
            assertNotNull(fieldNodesThatDeriveMe);
            int derivesCount = getIterableSize(outField.getFieldNodesThatDeriveMe());
            assertEquals(1, derivesCount);
            for (FieldNode derives : outField.getFieldNodesThatDeriveMe()) {
                assertEquals(usesNode.getName(), derives.getName());
                assertEquals(usesNode.getType(), derives.getType());
            }
            Operations ops = MetaverseUtil.convertOperationsStringToMap(outField.getOperations());
            List<IOperation> dataOps = ops.get(ChangeType.DATA);
            assertNotNull(dataOps);
            assertEquals(3, dataOps.size());
            for (IOperation dataOp : dataOps) {
                assertEquals(Operation.MAPPING_CATEGORY, dataOp.getCategory());
                assertEquals(DictionaryConst.PROPERTY_TRANSFORMS, dataOp.getName());
                assertTrue(dataOp.toString().contains(meta.getInputField()));
            }
            // there should not be any metadata operations
            assertNull(ops.get(ChangeType.METADATA));
        }
    }
}
Also used : IOperation(org.pentaho.metaverse.api.model.IOperation) FieldNode(org.pentaho.metaverse.frames.FieldNode) StreamFieldNode(org.pentaho.metaverse.frames.StreamFieldNode) TransformationStepNode(org.pentaho.metaverse.frames.TransformationStepNode) NumberRangeMeta(org.pentaho.di.trans.steps.numberrange.NumberRangeMeta) StreamFieldNode(org.pentaho.metaverse.frames.StreamFieldNode) Operations(org.pentaho.metaverse.api.model.Operations) Test(org.junit.Test)

Example 4 with StreamFieldNode

use of org.pentaho.metaverse.frames.StreamFieldNode in project pentaho-metaverse by pentaho.

the class MetaverseValidationIT method testTextFileOutputStepNode.

@Test
public void testTextFileOutputStepNode() throws Exception {
    TextFileOutputStepNode textFileOutputStepNode = root.getTextFileOutputStepNode("textFileOutput", "Text file output");
    TextFileOutputMeta meta = (TextFileOutputMeta) getStepMeta(textFileOutputStepNode);
    TransMeta tm = meta.getParentStepMeta().getParentTransMeta();
    String[] fileNames = meta.getFiles(tm);
    RowMetaInterface incomingFields = tm.getPrevStepFields(meta.getParentStepMeta());
    int outputFields = getExpectedOutputFieldCount(meta);
    assertNotNull(textFileOutputStepNode);
    Iterable<StreamFieldNode> outFields = textFileOutputStepNode.getOutputStreamFields();
    int outFieldCount = getIterableSize(outFields);
    // should have output stream nodes as well as file nodes
    assertEquals(outputFields + meta.getOutputFields().length, outFieldCount);
    int fileFieldCount = 0;
    for (StreamFieldNode outField : outFields) {
        if (DictionaryConst.NODE_TYPE_FILE_FIELD.equals(outField.getType())) {
            ValueMetaInterface vmi = incomingFields.searchValueMeta(outField.getName());
            assertEquals(vmi.getName(), outField.getFieldPopulatesMe().getName());
            fileFieldCount++;
        }
    }
    assertEquals(fileFieldCount, outFieldCount / 2);
}
Also used : TextFileOutputMeta(org.pentaho.di.trans.steps.textfileoutput.TextFileOutputMeta) TransMeta(org.pentaho.di.trans.TransMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) StreamFieldNode(org.pentaho.metaverse.frames.StreamFieldNode) TextFileOutputStepNode(org.pentaho.metaverse.frames.TextFileOutputStepNode) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 5 with StreamFieldNode

use of org.pentaho.metaverse.frames.StreamFieldNode in project pentaho-metaverse by pentaho.

the class MetaverseValidationIT method testStringOperationsStepNode.

@Test
public void testStringOperationsStepNode() throws Exception {
    TransformationStepNode node = root.getStepNode("string_operations", "String operations");
    // Make sure we have the right number of links used
    assertEquals(4, getIterableSize(node.getInputStreamFields()));
    assertEquals(4, getIterableSize(node.getStreamFieldNodesUses()));
    assertEquals(5, getIterableSize(node.getOutputStreamFields()));
    for (StreamFieldNode sfn : node.getOutputStreamFields()) {
        // "Last Name" is a special case for this test, it is passthrough
        if (sfn.getName().equals("Last Name")) {
            assertTrue(Const.isEmpty(sfn.getOperations()));
        } else {
            assertFalse(Const.isEmpty(sfn.getOperations()));
        }
    }
}
Also used : TransformationStepNode(org.pentaho.metaverse.frames.TransformationStepNode) StreamFieldNode(org.pentaho.metaverse.frames.StreamFieldNode) Test(org.junit.Test)

Aggregations

StreamFieldNode (org.pentaho.metaverse.frames.StreamFieldNode)39 Test (org.junit.Test)34 FramedMetaverseNode (org.pentaho.metaverse.frames.FramedMetaverseNode)14 FieldNode (org.pentaho.metaverse.frames.FieldNode)9 TransformationStepNode (org.pentaho.metaverse.frames.TransformationStepNode)9 Operations (org.pentaho.metaverse.api.model.Operations)7 TransMeta (org.pentaho.di.trans.TransMeta)6 IOperation (org.pentaho.metaverse.api.model.IOperation)5 HashSet (java.util.HashSet)4 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)4 CsvFileInputStepNode (org.pentaho.metaverse.frames.CsvFileInputStepNode)4 FixedFileInputStepNode (org.pentaho.metaverse.frames.FixedFileInputStepNode)4 FileInputStream (java.io.FileInputStream)3 ArrayList (java.util.ArrayList)3 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)3 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)3 StepMeta (org.pentaho.di.trans.step.StepMeta)3 FileInputStepNode (org.pentaho.metaverse.frames.FileInputStepNode)3 FieldSplitterMeta (org.pentaho.di.trans.steps.fieldsplitter.FieldSplitterMeta)2 HTTPMeta (org.pentaho.di.trans.steps.http.HTTPMeta)2