Search in sources :

Example 11 with Operation

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

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

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

the class StepAnalyzerTest method testMapChange.

@Test
public void testMapChange() throws Exception {
    doReturn(outputs).when(analyzer).getOutputs();
    doReturn(inputs).when(analyzer).getInputs();
    Operation operation = new Operation("testOperation", "testOperation");
    StepField original = new StepField("previousStep", "address");
    StepField changed = new StepField("nextStep", "address");
    ComponentDerivationRecord cdr = new ComponentDerivationRecord(original, changed);
    cdr.addOperation(operation);
    ComponentDerivationRecord spyCdr = spy(cdr);
    analyzer.mapChange(spyCdr);
    // get operations to verify it is not null, then agains to toString it
    verify(spyCdr, times(1)).getOperations();
    verify(analyzer).linkChangeNodes(any(IMetaverseNode.class), any(IMetaverseNode.class));
}
Also used : IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) StepField(org.pentaho.metaverse.api.StepField) ComponentDerivationRecord(org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord) Operation(org.pentaho.metaverse.api.model.Operation) Test(org.junit.Test)

Example 14 with Operation

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

the class NumberRangeStepAnalyzer method getChangeRecords.

@Override
public Set<ComponentDerivationRecord> getChangeRecords(final NumberRangeMeta meta) throws MetaverseAnalyzerException {
    Set<ComponentDerivationRecord> changeRecords = new HashSet<>();
    ComponentDerivationRecord changeRecord = new ComponentDerivationRecord(meta.getInputField(), meta.getOutputField(), ChangeType.DATA);
    List<NumberRangeRule> rules = meta.getRules();
    if (rules != null) {
        for (NumberRangeRule rule : rules) {
            changeRecord.addOperation(new Operation(Operation.MAPPING_CATEGORY, ChangeType.DATA, DictionaryConst.PROPERTY_TRANSFORMS, rule.getLowerBound() + " <= " + meta.getInputField() + " <= " + rule.getUpperBound() + " -> " + rule.getValue()));
        }
    }
    changeRecords.add(changeRecord);
    return changeRecords;
}
Also used : NumberRangeRule(org.pentaho.di.trans.steps.numberrange.NumberRangeRule) ComponentDerivationRecord(org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord) Operation(org.pentaho.metaverse.api.model.Operation) HashSet(java.util.HashSet)

Example 15 with Operation

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

the class StringOperationsStepAnalyzer method getChangeRecords.

@Override
public Set<ComponentDerivationRecord> getChangeRecords(final StringOperationsMeta stringOperationsMeta) throws MetaverseAnalyzerException {
    Set<ComponentDerivationRecord> changeRecords = new HashSet<>();
    for (int i = 0; i < stringOperationsMeta.getFieldInStream().length; i++) {
        String fieldInString = stringOperationsMeta.getFieldInStream()[i];
        String fieldOutString = stringOperationsMeta.getFieldOutStream()[i];
        if (Const.isEmpty(fieldOutString)) {
            fieldOutString = fieldInString;
        }
        final ComponentDerivationRecord changeRecord = new ComponentDerivationRecord(fieldInString, fieldOutString, ChangeType.DATA);
        String trimTypeDescription = StringOperationsMeta.getTrimTypeDesc(stringOperationsMeta.getTrimType()[i]);
        String lowerUpperDescription = StringOperationsMeta.getLowerUpperDesc(stringOperationsMeta.getLowerUpper()[i]);
        String initCapDescription = StringOperationsMeta.getInitCapDesc(stringOperationsMeta.getInitCap()[i]);
        String digitsDescription = StringOperationsMeta.getDigitsDesc(stringOperationsMeta.getDigits()[i]);
        String maskXMLDescription = StringOperationsMeta.getMaskXMLDesc(stringOperationsMeta.getMaskXML()[i]);
        String paddingDescription = StringOperationsMeta.getPaddingDesc(stringOperationsMeta.getPaddingType()[i]);
        String specialCharactersDescription = StringOperationsMeta.getRemoveSpecialCharactersDesc(stringOperationsMeta.getRemoveSpecialCharacters()[i]);
        String changeOperation = fieldOutString;
        changeOperation += " { trim = [ " + trimTypeDescription + " ] && ";
        changeOperation += "lower/upper = [ " + lowerUpperDescription + " ] && ";
        changeOperation += "padding = [ " + paddingDescription + (stringOperationsMeta.getPaddingType()[i] == StringOperationsMeta.PADDING_NONE ? "" : ", " + stringOperationsMeta.getPadChar()[i]) + ", " + stringOperationsMeta.getPadLen()[i] + " ] && ";
        changeOperation += "cap = [ " + initCapDescription + " ] && ";
        changeOperation += "maskXML = [ " + maskXMLDescription + " ] && ";
        changeOperation += "digits = [ " + digitsDescription + " ] && ";
        changeOperation += "remove = [ " + specialCharactersDescription + " ] } -> ";
        changeOperation += fieldOutString;
        changeRecord.addOperation(new Operation(Operation.CALC_CATEGORY, ChangeType.DATA, DictionaryConst.PROPERTY_TRANSFORMS, changeOperation));
        changeRecords.add(changeRecord);
    }
    return changeRecords;
}
Also used : ComponentDerivationRecord(org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord) Operation(org.pentaho.metaverse.api.model.Operation) HashSet(java.util.HashSet)

Aggregations

Operation (org.pentaho.metaverse.api.model.Operation)22 Test (org.junit.Test)12 ComponentDerivationRecord (org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord)11 IOperation (org.pentaho.metaverse.api.model.IOperation)10 Operations (org.pentaho.metaverse.api.model.Operations)10 HashSet (java.util.HashSet)7 ArrayList (java.util.ArrayList)1 Condition (org.pentaho.di.core.Condition)1 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)1 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)1 NumberRangeRule (org.pentaho.di.trans.steps.numberrange.NumberRangeRule)1 SelectMetadataChange (org.pentaho.di.trans.steps.selectvalues.SelectMetadataChange)1 IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)1 StepField (org.pentaho.metaverse.api.StepField)1