Search in sources :

Example 16 with Operations

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

the class ComponentDerivationRecordTest method testAddOperation.

@Test
public void testAddOperation() throws Exception {
    Operations operations = record.getOperations();
    assertNotNull(operations);
    assertTrue(operations.isEmpty());
    String operands = "testOperand1, testOperand2";
    record.addOperation(new Operation("testOperation", operands));
    operations = record.getOperations();
    assertNotNull(operations);
    List<IOperation> checkOperations = operations.get(ChangeType.METADATA);
    assertNotNull(checkOperations);
    assertEquals(1, checkOperations.size());
    IOperation checkOperation = checkOperations.get(0);
    assertTrue("testOperand1 not in operands!", checkOperation.getDescription().contains("testOperand1"));
    assertTrue("testOperand2 not in operands!", checkOperation.getDescription().contains("testOperand2"));
}
Also used : IOperation(org.pentaho.metaverse.api.model.IOperation) IOperation(org.pentaho.metaverse.api.model.IOperation) Operation(org.pentaho.metaverse.api.model.Operation) Operations(org.pentaho.metaverse.api.model.Operations) Test(org.junit.Test)

Example 17 with Operations

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

the class ComponentDerivationRecordTest method testPutOperationNullOperation.

@Test
public void testPutOperationNullOperation() throws Exception {
    Operations operations = record.getOperations();
    assertNotNull(operations);
    assertTrue(operations.isEmpty());
    record.addOperation(null);
    String operands = "testOperand1, testOperand2";
    record.addOperation(new Operation(null, operands));
    operations = record.getOperations();
    assertNotNull(operations);
    List<IOperation> checkOperands = operations.get("testOperation");
    assertNull(checkOperands);
}
Also used : IOperation(org.pentaho.metaverse.api.model.IOperation) IOperation(org.pentaho.metaverse.api.model.IOperation) Operation(org.pentaho.metaverse.api.model.Operation) Operations(org.pentaho.metaverse.api.model.Operations) Test(org.junit.Test)

Example 18 with Operations

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

the class ComponentDerivationRecordTest method testGetOperations.

@Test
public void testGetOperations() throws Exception {
    Operations operations = record.getOperations();
    assertNotNull(operations);
    assertTrue(operations.isEmpty());
    String operands = "testOperand1, testOperand2";
    record.addOperation(new Operation("testOperation", operands));
    assertNull(record.getOperations(ChangeType.DATA));
    assertNotNull(record.getOperations(ChangeType.METADATA));
}
Also used : IOperation(org.pentaho.metaverse.api.model.IOperation) Operation(org.pentaho.metaverse.api.model.Operation) Operations(org.pentaho.metaverse.api.model.Operations) Test(org.junit.Test)

Example 19 with Operations

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

the class LineageClient method getOperationPaths.

/**
 * Returns the paths between the origin field(s) and target field(s). A path in this context is an ordered list of
 * StepFieldOperations objects, each of which corresponds to a field at a certain step where operation(s) are
 * applied. The order of the list corresponds to the order of the steps from the origin step (see getOriginSteps())
 * to the target step. This method can be used to trace a target field back to its origin and discovering what
 * operations were performed upon it during it's lifetime. Inversely the path could be used to re-apply the operations
 * to the origin field, resulting in the field's "value" at each point in the path.
 *
 * @param transMeta      a reference to a transformation's metadata
 * @param targetStepName the target step name associated with the given field names
 * @param fieldNames     an array of field names associated with the target step, for which to find the step(s) and
 *                       field(s) and operation(s) that contributed to those fields
 * @return a map of target field name to an ordered list of StepFieldOperations objects, describing the path from the
 * origin step field to the target step field, including the operations performed.
 * @throws MetaverseException if an error occurred while finding the origin steps
 */
@Override
public Map<String, Set<List<StepFieldOperations>>> getOperationPaths(TransMeta transMeta, String targetStepName, final Collection<String> fieldNames) throws MetaverseException {
    Map<String, Set<List<StepFieldOperations>>> operationPathMap = new HashMap<>();
    try {
        Future<Graph> lineageGraphTask = LineageGraphMap.getInstance().get(transMeta);
        if (lineageGraphTask != null) {
            Graph lineageGraph = lineageGraphTask.get();
            if (lineageGraph != null) {
                // Get the creator field nodes for all the field names passed in
                List<Vertex> getTargetFields = getTargetFields(lineageGraph, targetStepName, fieldNames);
                // The "origin steps pipe" with a second param of true returns a pipeline that will return paths between
                // the origin field nodes and the target field node.
                GremlinPipeline pipe = getOriginStepsPipe(getTargetFields);
                List<List<Vertex>> pathList = pipe.toList();
                if (pathList != null) {
                    for (List<Vertex> path : pathList) {
                        // Transform each path of vertices into a "path" of StepFieldOperations objects (basically save off
                        // properties of each vertex into a new list)
                        List<StepFieldOperations> stepFieldOps = new ArrayList<>();
                        String targetField = path.get(0).getProperty(DictionaryConst.PROPERTY_NAME);
                        Set<List<StepFieldOperations>> pathSet = operationPathMap.get(targetField);
                        if (pathSet == null) {
                            pathSet = new HashSet<>();
                            operationPathMap.put(targetField, pathSet);
                        }
                        for (Vertex v : path) {
                            Map<String, String> stepField = STEPFIELDOPS_PIPE_FUNC.compute(v);
                            String stepName = stepField.get("stepName");
                            String fieldName = stepField.get("fieldName");
                            Operations operations = MetaverseUtil.convertOperationsStringToMap((String) v.getProperty(DictionaryConst.PROPERTY_OPERATIONS));
                            stepFieldOps.add(0, new StepFieldOperations(stepName, fieldName, operations));
                        }
                        pathSet.add(stepFieldOps);
                    }
                }
            }
        }
    } catch (Exception e) {
        throw new MetaverseException(e);
    }
    return operationPathMap;
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) GremlinPipeline(com.tinkerpop.gremlin.java.GremlinPipeline) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MetaverseException(org.pentaho.metaverse.api.MetaverseException) Graph(com.tinkerpop.blueprints.Graph) StepFieldOperations(org.pentaho.metaverse.api.StepFieldOperations) ArrayList(java.util.ArrayList) List(java.util.List) Operations(org.pentaho.metaverse.api.model.Operations) StepFieldOperations(org.pentaho.metaverse.api.StepFieldOperations) MetaverseException(org.pentaho.metaverse.api.MetaverseException)

Example 20 with Operations

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

the class NumberRangeStepAnalyzerTest method testGetChangeRecords.

@Test
public void testGetChangeRecords() throws Exception {
    Set<ComponentDerivationRecord> changeRecords = analyzer.getChangeRecords(meta);
    assertEquals(1, changeRecords.size());
    ComponentDerivationRecord changeRecord = changeRecords.iterator().next();
    assertEquals("inField", changeRecord.getOriginalEntityName());
    assertEquals("outField", changeRecord.getChangedEntityName());
    Operations operations = changeRecord.getOperations();
    // Only data operations
    assertEquals(1, operations.size());
    List<IOperation> dataOperations = operations.get(ChangeType.DATA);
    assertEquals(2, dataOperations.size());
}
Also used : IOperation(org.pentaho.metaverse.api.model.IOperation) ComponentDerivationRecord(org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord) 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