Search in sources :

Example 26 with ComponentDerivationRecord

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

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

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

the class GroupByStepAnalyzer method getChangeRecords.

@Override
public Set<ComponentDerivationRecord> getChangeRecords(final GroupByMeta groupByMeta) throws MetaverseAnalyzerException {
    Set<ComponentDerivationRecord> changeRecords = new HashSet<>();
    for (int i = 0; i < groupByMeta.getSubjectField().length; i++) {
        ComponentDerivationRecord changeRecord = buildChangeRecord(groupByMeta.getSubjectField()[i], groupByMeta.getAggregateField()[i], groupByMeta.getAggregateType()[i]);
        changeRecords.add(changeRecord);
    }
    return changeRecords;
}
Also used : ComponentDerivationRecord(org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord) HashSet(java.util.HashSet)

Example 29 with ComponentDerivationRecord

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

Example 30 with ComponentDerivationRecord

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

the class GroupByStepAnalyzerTest method testGetChangeRecords.

@Test
public void testGetChangeRecords() throws Exception {
    Set<ComponentDerivationRecord> changeRecords = analyzer.getChangeRecords(meta);
    assertEquals(2, changeRecords.size());
    ComponentDerivationRecord next = changeRecords.iterator().next();
    assertTrue(next.getOriginalEntityName().equals("member") || next.getOriginalEntityName().equals("donation"));
    if (next.getOriginalEntityName().equals("member")) {
        assertEquals("memberlist", next.getChangedEntityName());
    } else {
        assertEquals("totalcity", next.getChangedEntityName());
    }
}
Also used : ComponentDerivationRecord(org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord) Test(org.junit.Test)

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