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