Search in sources :

Example 1 with Operations

use of org.pentaho.metaverse.api.model.Operations 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 2 with Operations

use of org.pentaho.metaverse.api.model.Operations in project pentaho-metaverse by pentaho.

the class MetaverseValidationIT method testCalculatorStepNode.

@Test
public void testCalculatorStepNode() throws Exception {
    CalculatorStepNode node = root.getCalculatorStepNode();
    Set<String> usedFields = new HashSet<String>();
    CalculatorMeta calculatorMeta = (CalculatorMeta) getStepMeta(node);
    for (CalculatorMetaFunction calculatorMetaFunction : calculatorMeta.getCalculation()) {
        String fieldName = calculatorMetaFunction.getFieldA();
        if (!StringUtils.isEmpty(fieldName)) {
            usedFields.add(fieldName);
        }
        fieldName = calculatorMetaFunction.getFieldB();
        if (!StringUtils.isEmpty(fieldName)) {
            usedFields.add(fieldName);
        }
        fieldName = calculatorMetaFunction.getFieldC();
        if (!StringUtils.isEmpty(fieldName)) {
            usedFields.add(fieldName);
        }
    }
    int expectedUsedFieldCount = usedFields.size();
    // Make sure we have the right number of links used, created and deleted.
    List<String> nodeUses = new ArrayList<String>();
    for (StreamFieldNode sfn : node.getStreamFieldNodesUses()) {
        nodeUses.add(sfn.getName());
    }
    StreamFieldNode area = null;
    StreamFieldNode kelvin = null;
    StreamFieldNode celsius = null;
    List<String> nodeOutputs = new ArrayList<String>();
    for (StreamFieldNode sfn : node.getOutputStreamFields()) {
        nodeOutputs.add(sfn.getName());
        Operations ops = MetaverseUtil.convertOperationsStringToMap(sfn.getOperations());
        if (sfn.getName().equals("area")) {
            area = sfn;
            assertNotNull(ops.get(ChangeType.DATA));
            assertEquals(Operation.CALC_CATEGORY, ops.get(ChangeType.DATA).get(0).getCategory());
        } else if (sfn.getName().equals("celsius")) {
            celsius = sfn;
            assertNotNull(ops);
            assertNotNull(ops.get(ChangeType.DATA));
            assertEquals(Operation.CALC_CATEGORY, ops.get(ChangeType.DATA).get(0).getCategory());
        } else if (sfn.getName().equals("kelvin")) {
            kelvin = sfn;
            assertNotNull(ops);
            assertNotNull(ops.get(ChangeType.DATA));
            assertEquals(Operation.CALC_CATEGORY, ops.get(ChangeType.DATA).get(0).getCategory());
        }
    }
    assertEquals(2, getIterableSize(area.getFieldNodesThatDeriveMe()));
    String[] fieldsThatDerive = new String[2];
    fieldsThatDerive = new String[2];
    int i = 0;
    for (StreamFieldNode sfn : celsius.getFieldNodesThatDeriveMe()) {
        fieldsThatDerive[i++] = sfn.getName();
    }
    assertTrue(Arrays.asList(fieldsThatDerive).contains("tempCelsius"));
    assertTrue(Arrays.asList(fieldsThatDerive).contains("tempRatio"));
    fieldsThatDerive = new String[2];
    i = 0;
    for (StreamFieldNode sfn : kelvin.getFieldNodesThatDeriveMe()) {
        fieldsThatDerive[i++] = sfn.getName();
    }
    assertTrue(Arrays.asList(fieldsThatDerive).contains("tempKelvin"));
    assertTrue(Arrays.asList(fieldsThatDerive).contains("tempRatio"));
    assertEquals(expectedUsedFieldCount, nodeUses.size());
    assertEquals(getExpectedOutputFieldCount(calculatorMeta), nodeOutputs.size());
}
Also used : CalculatorStepNode(org.pentaho.metaverse.frames.CalculatorStepNode) ArrayList(java.util.ArrayList) CalculatorMeta(org.pentaho.di.trans.steps.calculator.CalculatorMeta) StreamFieldNode(org.pentaho.metaverse.frames.StreamFieldNode) CalculatorMetaFunction(org.pentaho.di.trans.steps.calculator.CalculatorMetaFunction) Operations(org.pentaho.metaverse.api.model.Operations) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with Operations

use of org.pentaho.metaverse.api.model.Operations in project pentaho-metaverse by pentaho.

the class MetaverseValidationIT method testValueMapperStepNode_newField.

@Test
public void testValueMapperStepNode_newField() throws Exception {
    TransformationStepNode valueMapperStepNode = root.getStepNode("value_mapper", "Value Mapper - new field");
    assertEquals(1, getIterableSize(valueMapperStepNode.getStreamFieldNodesUses()));
    StreamFieldNode usesNode = valueMapperStepNode.getStreamFieldNodesUses().iterator().next();
    ValueMapperMeta meta = (ValueMapperMeta) getStepMeta(valueMapperStepNode);
    assertEquals(meta.getFieldToUse(), usesNode.getName());
    assertNull(usesNode.getOperations());
    Iterable<StreamFieldNode> inFields = valueMapperStepNode.getInputStreamFields();
    int countInputs = getIterableSize(inFields);
    Iterable<StreamFieldNode> outFields = valueMapperStepNode.getOutputStreamFields();
    int countOutputs = getIterableSize(outFields);
    assertEquals(countInputs + 1, countOutputs);
    for (StreamFieldNode outField : outFields) {
        assertNotNull(outField.getKettleType());
        if (outField.getName().equals(meta.getTargetField())) {
            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(1, dataOps.size());
            for (IOperation dataOp : dataOps) {
                assertEquals(Operation.MAPPING_CATEGORY, dataOp.getCategory());
                assertEquals(DictionaryConst.PROPERTY_TRANSFORMS, dataOp.getName());
            }
            // 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) StreamFieldNode(org.pentaho.metaverse.frames.StreamFieldNode) Operations(org.pentaho.metaverse.api.model.Operations) ValueMapperMeta(org.pentaho.di.trans.steps.valuemapper.ValueMapperMeta) Test(org.junit.Test)

Example 4 with Operations

use of org.pentaho.metaverse.api.model.Operations in project pentaho-metaverse by pentaho.

the class MetaverseValidationIT method testValueMapperStepNode_overwrite.

@Test
public void testValueMapperStepNode_overwrite() throws Exception {
    TransformationStepNode valueMapperStepNode = root.getStepNode("value_mapper", "Value Mapper - overwrite");
    assertEquals(1, getIterableSize(valueMapperStepNode.getStreamFieldNodesUses()));
    StreamFieldNode usesNode = valueMapperStepNode.getStreamFieldNodesUses().iterator().next();
    ValueMapperMeta meta = (ValueMapperMeta) getStepMeta(valueMapperStepNode);
    assertEquals(meta.getFieldToUse(), usesNode.getName());
    Iterable<StreamFieldNode> inFields = valueMapperStepNode.getInputStreamFields();
    int countInputs = getIterableSize(inFields);
    Iterable<StreamFieldNode> outFields = valueMapperStepNode.getOutputStreamFields();
    int countOutputs = getIterableSize(outFields);
    assertEquals(countInputs, countOutputs);
    for (StreamFieldNode outField : outFields) {
        assertNotNull(outField.getKettleType());
        if (outField.getName().equals(meta.getTargetField())) {
            Operations ops = MetaverseUtil.convertOperationsStringToMap(usesNode.getOperations());
            List<IOperation> dataOps = ops.get(ChangeType.DATA);
            assertNotNull(dataOps);
            assertEquals(meta.getSourceValue().length, dataOps.size());
            for (int i = 0; i < dataOps.size(); i++) {
                IOperation dataOp = dataOps.get(i);
                assertEquals(DictionaryConst.PROPERTY_TRANSFORMS, dataOp.getName());
                assertEquals(dataOp.toString(), meta.getSourceValue()[i] + " -> " + meta.getTargetValue()[i]);
            }
            // there should not be any metadata operations
            assertNull(ops.get(ChangeType.METADATA));
        }
    }
    int derivedCount = getIterableSize(usesNode.getFieldNodesDerivedFromMe());
    assertEquals(1, derivedCount);
}
Also used : IOperation(org.pentaho.metaverse.api.model.IOperation) TransformationStepNode(org.pentaho.metaverse.frames.TransformationStepNode) StreamFieldNode(org.pentaho.metaverse.frames.StreamFieldNode) Operations(org.pentaho.metaverse.api.model.Operations) ValueMapperMeta(org.pentaho.di.trans.steps.valuemapper.ValueMapperMeta) Test(org.junit.Test)

Example 5 with Operations

use of org.pentaho.metaverse.api.model.Operations in project pentaho-metaverse by pentaho.

the class MetaverseValidationIT method testFilterRowsStepNode.

@Test
public void testFilterRowsStepNode() throws Exception {
    FilterRowsStepNode node = root.getFilterRowsStepNode("Filter rows");
    assertNotNull(node);
    assertEquals("Filter rows", node.getStepType());
    FilterRowsMeta meta = (FilterRowsMeta) getStepMeta(node);
    Operations ops = MetaverseUtil.convertOperationsStringToMap(node.getOperations());
    assertEquals(1, ops.get(ChangeType.DATA_FLOW).size());
    assertEquals(meta.getCondition().toString(), ops.get(ChangeType.DATA_FLOW).get(0).getDescription());
    // should not be any created nodes
    Iterable<StreamFieldNode> streamFieldNodes = node.getStreamFieldNodesCreates();
    int countCreatedStreamFieldNode = getIterableSize(streamFieldNodes);
    assertEquals(0, countCreatedStreamFieldNode);
    // should not be any deleted nodes
    streamFieldNodes = node.getStreamFieldNodesCreates();
    int countDeletedStreamFieldNode = getIterableSize(streamFieldNodes);
    assertEquals(0, countDeletedStreamFieldNode);
    // should use all of the fields that are used in the condition of the step
    List<String> expectedUses = Arrays.asList(meta.getCondition().getUsedFields());
    streamFieldNodes = node.getStreamFieldNodesUses();
    int countUsedStreamFieldNode = getIterableSize(streamFieldNodes);
    assertEquals(expectedUses.size(), countUsedStreamFieldNode);
    for (StreamFieldNode streamFieldNode : streamFieldNodes) {
        assertTrue(expectedUses.contains(streamFieldNode.getName()));
    }
}
Also used : FilterRowsMeta(org.pentaho.di.trans.steps.filterrows.FilterRowsMeta) FilterRowsStepNode(org.pentaho.metaverse.frames.FilterRowsStepNode) StreamFieldNode(org.pentaho.metaverse.frames.StreamFieldNode) Operations(org.pentaho.metaverse.api.model.Operations) Test(org.junit.Test)

Aggregations

Operations (org.pentaho.metaverse.api.model.Operations)24 Test (org.junit.Test)22 IOperation (org.pentaho.metaverse.api.model.IOperation)19 Operation (org.pentaho.metaverse.api.model.Operation)11 StreamFieldNode (org.pentaho.metaverse.frames.StreamFieldNode)6 List (java.util.List)3 ComponentDerivationRecord (org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord)3 TransformationStepNode (org.pentaho.metaverse.frames.TransformationStepNode)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 ValueMapperMeta (org.pentaho.di.trans.steps.valuemapper.ValueMapperMeta)2 MetaverseException (org.pentaho.metaverse.api.MetaverseException)2 StepFieldOperations (org.pentaho.metaverse.api.StepFieldOperations)2 FieldNode (org.pentaho.metaverse.frames.FieldNode)2 Graph (com.tinkerpop.blueprints.Graph)1 Vertex (com.tinkerpop.blueprints.Vertex)1 GremlinPipeline (com.tinkerpop.gremlin.java.GremlinPipeline)1 JSONDeserializer (flexjson.JSONDeserializer)1 HashMap (java.util.HashMap)1