Search in sources :

Example 21 with ComponentDerivationRecord

use of org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord 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)

Example 22 with ComponentDerivationRecord

use of org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord in project pentaho-metaverse by pentaho.

the class StringsReplaceStepAnalyzer method buildChangeRecord.

private ComponentDerivationRecord buildChangeRecord(final ReplaceStringMeta stringsReplaceMeta, final int index) throws MetaverseAnalyzerException {
    String fieldInString = stringsReplaceMeta.getFieldInStream()[index];
    String fieldOutString = stringsReplaceMeta.getFieldOutStream()[index];
    if (containsField(fieldOutString)) {
        Integer nameIdx = renameIndex.get(fieldOutString);
        renameIndex.put(fieldOutString, (nameIdx == null ? 1 : nameIdx + 1));
        fieldOutString += "_" + renameIndex.get(fieldOutString);
    }
    if (fieldOutString == null || fieldOutString.length() < 1) {
        fieldOutString = fieldInString;
    }
    final ComponentDerivationRecord changeRecord = new ComponentDerivationRecord(fieldInString, fieldOutString, ChangeType.DATA);
    final String fieldReplaceString = stringsReplaceMeta.getFieldReplaceByString()[index];
    String changeOperation = fieldInString + " -> [ replace [ ";
    changeOperation += stringsReplaceMeta.getReplaceString()[index] + " with ";
    if (fieldReplaceString != null && fieldReplaceString.length() > 0) {
        changeOperation += fieldReplaceString;
    } else {
        changeOperation += stringsReplaceMeta.getReplaceByString()[0];
    }
    changeOperation += " ] ] -> " + fieldOutString;
    changeRecord.addOperation(new Operation(Operation.CALC_CATEGORY, ChangeType.DATA, DictionaryConst.PROPERTY_TRANSFORMS, changeOperation));
    return changeRecord;
}
Also used : ComponentDerivationRecord(org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord) Operation(org.pentaho.metaverse.api.model.Operation)

Example 23 with ComponentDerivationRecord

use of org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord in project pentaho-metaverse by pentaho.

the class TableOutputStepAnalyzer method getChangeRecords.

@Override
public Set<ComponentDerivationRecord> getChangeRecords(TableOutputMeta meta) throws MetaverseAnalyzerException {
    Set<ComponentDerivationRecord> changes = new HashSet<>();
    String[] tableFields = meta.getFieldDatabase();
    String[] streamFields = meta.getFieldStream();
    if (getInputs() != null) {
        Set<String> stepNames = getInputs().getStepNames();
        for (int i = 0; i < tableFields.length; i++) {
            String tableField = tableFields[i];
            String streamField = streamFields[i];
            for (String stepName : stepNames) {
                if (!RESOURCE.equals(stepName)) {
                    StepField inputField = new StepField(stepName, streamField);
                    StepField outField = new StepField(RESOURCE, tableField);
                    ComponentDerivationRecord change = new ComponentDerivationRecord(inputField, outField);
                    changes.add(change);
                }
            }
        }
    }
    return changes;
}
Also used : StepField(org.pentaho.metaverse.api.StepField) ComponentDerivationRecord(org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 24 with ComponentDerivationRecord

use of org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord in project pentaho-metaverse by pentaho.

the class ValueMapperStepAnalyzer method getChangeRecords.

@Override
public Set<ComponentDerivationRecord> getChangeRecords(ValueMapperMeta valueMapperMeta) throws MetaverseAnalyzerException {
    final String fieldToUse = valueMapperMeta.getFieldToUse();
    final String targetField = valueMapperMeta.getTargetField() == null ? fieldToUse : valueMapperMeta.getTargetField();
    final String[] sourceValues = valueMapperMeta.getSourceValue();
    final String[] targetValues = valueMapperMeta.getTargetValue();
    Set<ComponentDerivationRecord> changeRecords = new HashSet<>(1);
    final ComponentDerivationRecord changeRecord = new ComponentDerivationRecord(fieldToUse, targetField, ChangeType.DATA);
    for (int i = 0; i < sourceValues.length; i++) {
        String mapping = sourceValues[i] + " -> " + targetValues[i];
        changeRecord.addOperation(new Operation(Operation.MAPPING_CATEGORY, ChangeType.DATA, DictionaryConst.PROPERTY_TRANSFORMS, mapping));
    }
    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)

Example 25 with ComponentDerivationRecord

use of org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord in project pentaho-metaverse by pentaho.

the class CalculatorStepAnalyzer method getChangeRecords.

@Override
public Set<ComponentDerivationRecord> getChangeRecords(final CalculatorMeta calculatorMeta) throws MetaverseAnalyzerException {
    Set<ComponentDerivationRecord> changeRecords = new HashSet<ComponentDerivationRecord>();
    for (CalculatorMetaFunction function : calculatorMeta.getCalculation()) {
        Set<ComponentDerivationRecord> changeRecord = buildChangeRecord(function);
        changeRecords.addAll(changeRecord);
    }
    return changeRecords;
}
Also used : ComponentDerivationRecord(org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord) CalculatorMetaFunction(org.pentaho.di.trans.steps.calculator.CalculatorMetaFunction) HashSet(java.util.HashSet)

Aggregations

ComponentDerivationRecord (org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord)43 Test (org.junit.Test)23 HashSet (java.util.HashSet)21 StepField (org.pentaho.metaverse.api.StepField)11 Operation (org.pentaho.metaverse.api.model.Operation)11 Matchers.anyString (org.mockito.Matchers.anyString)5 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)5 IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)5 IOperation (org.pentaho.metaverse.api.model.IOperation)3 Operations (org.pentaho.metaverse.api.model.Operations)3 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)2 SelectMetadataChange (org.pentaho.di.trans.steps.selectvalues.SelectMetadataChange)2 IAnalysisContext (org.pentaho.metaverse.api.IAnalysisContext)2 IFieldLineageMetadataProvider (org.pentaho.metaverse.api.analyzer.kettle.step.IFieldLineageMetadataProvider)2 StepNodes (org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes)2 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 Condition (org.pentaho.di.core.Condition)1 CalculatorMetaFunction (org.pentaho.di.trans.steps.calculator.CalculatorMetaFunction)1 NumberRangeRule (org.pentaho.di.trans.steps.numberrange.NumberRangeRule)1