Search in sources :

Example 16 with Operation

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

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

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

the class CalculatorStepAnalyzer method buildChangeRecord.

protected Set<ComponentDerivationRecord> buildChangeRecord(final CalculatorMetaFunction function) {
    Set<ComponentDerivationRecord> changes = new HashSet<>();
    String fieldA = function.getFieldA();
    String fieldB = function.getFieldB();
    String fieldC = function.getFieldC();
    String inputFields = (fieldA != null ? fieldA + ", " : "") + (fieldB != null ? fieldB + ", " : "") + (fieldC != null ? fieldC + ", " : "");
    List<String> fields = new ArrayList<>();
    if (fieldA != null) {
        fields.add(fieldA);
    }
    if (fieldB != null) {
        fields.add(fieldB);
    }
    if (fieldC != null) {
        fields.add(fieldC);
    }
    for (String field : fields) {
        final ComponentDerivationRecord changeRecord = new ComponentDerivationRecord(field, function.getFieldName(), ChangeType.DATA);
        changeRecord.addOperation(new Operation(Operation.CALC_CATEGORY, ChangeType.DATA, DictionaryConst.PROPERTY_TRANSFORMS, inputFields + "using " + function.getCalcTypeDesc() + " -> " + function.getFieldName()));
        changes.add(changeRecord);
    }
    return changes;
}
Also used : ComponentDerivationRecord(org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord) ArrayList(java.util.ArrayList) Operation(org.pentaho.metaverse.api.model.Operation) HashSet(java.util.HashSet)

Example 19 with Operation

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

the class FilterRowsStepAnalyzer method customAnalyze.

@Override
protected void customAnalyze(FilterRowsMeta stepMeta, IMetaverseNode stepNode) {
    // add the filter condition as properties on the step node
    final Condition condition = stepMeta.getCondition();
    if (condition != null) {
        String filterCondition = condition.toString();
        Operation operation = new Operation("filter", ChangeType.DATA_FLOW, DATA_FLOW_CONDITION, filterCondition);
        ComponentDerivationRecord changeRecord = new ComponentDerivationRecord(stepNode.getName(), ChangeType.DATA_FLOW);
        changeRecord.addOperation(operation);
        stepNode.setProperty(DictionaryConst.PROPERTY_OPERATIONS, changeRecord.toString());
    }
}
Also used : Condition(org.pentaho.di.core.Condition) ComponentDerivationRecord(org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord) Operation(org.pentaho.metaverse.api.model.Operation)

Example 20 with Operation

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

the class GroupByStepAnalyzer method buildChangeRecord.

private ComponentDerivationRecord buildChangeRecord(String subjectField, String aggregateField, int aggregateType) {
    final ComponentDerivationRecord changeRecord = new ComponentDerivationRecord(subjectField, aggregateField, ChangeType.DATA);
    changeRecord.addOperation(new Operation(Operation.AGG_CATEGORY, ChangeType.DATA, DictionaryConst.PROPERTY_TRANSFORMS, subjectField + " using " + GroupByMeta.getTypeDesc(aggregateType) + " -> " + aggregateField));
    return changeRecord;
}
Also used : ComponentDerivationRecord(org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord) Operation(org.pentaho.metaverse.api.model.Operation)

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