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