Search in sources :

Example 1 with FilterRowsMeta

use of org.pentaho.di.trans.steps.filterrows.FilterRowsMeta 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()));
    }
}
Also used : FilterRowsMeta(org.pentaho.di.trans.steps.filterrows.FilterRowsMeta) FilterRowsStepNode(org.pentaho.metaverse.frames.FilterRowsStepNode) StreamFieldNode(org.pentaho.metaverse.frames.StreamFieldNode) Operations(org.pentaho.metaverse.api.model.Operations) Test(org.junit.Test)

Example 2 with FilterRowsMeta

use of org.pentaho.di.trans.steps.filterrows.FilterRowsMeta in project pdi-dataservice-server-plugin by pentaho.

the class SqlTransGenerator method generateIifStep.

/**
 * This method generates a 4 steps for every IIF clause... TODO: replace with one step...
 *
 * @param iifField
 * @param lastStep
 * @param transMeta
 * @return steps
 */
private StepMeta generateIifStep(SQLField iifField, TransMeta transMeta, StepMeta lastStep) {
    IifFunction iif = iifField.getIif();
    // The Filter condition...
    // 
    FilterRowsMeta filterMeta = new FilterRowsMeta();
    filterMeta.setCondition(iifField.getIif().getSqlCondition().getCondition());
    StepMeta filterStep = new StepMeta(iifField.getExpression(), filterMeta);
    filterStep.setLocation(xLocation, 50);
    xLocation += 100;
    filterStep.setDraw(true);
    lastStep = addToTrans(filterStep, transMeta, lastStep);
    // The True and false steps...
    // 
    StepMetaInterface trueMetaInterface;
    ValueMetaInterface valueMeta = iif.getTrueValue().getValueMeta();
    if (iif.isTrueField()) {
        CalculatorMeta trueMeta = new CalculatorMeta();
        trueMetaInterface = trueMeta;
        trueMeta.allocate(1);
        CalculatorMetaFunction function = new CalculatorMetaFunction();
        function.setFieldName(Const.NVL(iifField.getAlias(), iifField.getField()));
        function.setCalcType(CalculatorMetaFunction.CALC_COPY_OF_FIELD);
        function.setValueType(valueMeta.getType());
        function.setValueLength(valueMeta.getLength());
        function.setValuePrecision(valueMeta.getPrecision());
        function.setFieldA(iif.getTrueValueString());
        function.setConversionMask(valueMeta.getConversionMask());
        // CHECKSTYLE:Indentation:OFF
        trueMeta.getCalculation()[0] = function;
    } else {
        ConstantMeta trueMeta = new ConstantMeta();
        trueMetaInterface = trueMeta;
        trueMeta.allocate(1);
        // CHECKSTYLE:Indentation:OFF
        trueMeta.getFieldName()[0] = Const.NVL(iifField.getAlias(), iifField.getField());
        trueMeta.getFieldType()[0] = iif.getTrueValue().getValueMeta().getTypeDesc();
        trueMeta.getValue()[0] = iif.getTrueValue().toString();
        trueMeta.getFieldFormat()[0] = valueMeta.getConversionMask();
    }
    StepMeta trueStep = new StepMeta("TRUE: " + iifField.getExpression(), trueMetaInterface);
    trueStep.setLocation(xLocation, 50);
    trueStep.setDraw(true);
    lastStep = addToTrans(trueStep, transMeta, filterStep);
    StepMetaInterface falseMetaInterface;
    valueMeta = iif.getFalseValue().getValueMeta();
    if (iif.isFalseField()) {
        CalculatorMeta falseMeta = new CalculatorMeta();
        falseMetaInterface = falseMeta;
        falseMeta.allocate(1);
        CalculatorMetaFunction function = new CalculatorMetaFunction();
        function.setFieldName(Const.NVL(iifField.getAlias(), iifField.getField()));
        function.setCalcType(CalculatorMetaFunction.CALC_COPY_OF_FIELD);
        function.setValueType(valueMeta.getType());
        function.setValueLength(valueMeta.getLength());
        function.setValuePrecision(valueMeta.getPrecision());
        function.setFieldA(iif.getFalseValueString());
        function.setConversionMask(valueMeta.getConversionMask());
        falseMeta.getCalculation()[0] = function;
    } else {
        ConstantMeta falseMeta = new ConstantMeta();
        falseMetaInterface = falseMeta;
        falseMeta.allocate(1);
        falseMeta.getFieldName()[0] = Const.NVL(iifField.getAlias(), iifField.getField());
        falseMeta.getFieldType()[0] = iif.getFalseValue().getValueMeta().getTypeDesc();
        falseMeta.getFieldFormat()[0] = valueMeta.getConversionMask();
        falseMeta.getValue()[0] = iif.getFalseValue().toString();
    }
    StepMeta falseStep = new StepMeta("FALSE: " + iifField.getExpression(), falseMetaInterface);
    falseStep.setLocation(xLocation, 150);
    xLocation += 100;
    falseStep.setDraw(true);
    lastStep = addToTrans(falseStep, transMeta, filterStep);
    // specify true/false targets
    List<StreamInterface> targetStreams = filterMeta.getStepIOMeta().getTargetStreams();
    targetStreams.get(0).setSubject(trueStep.getName());
    targetStreams.get(1).setSubject(falseStep.getName());
    filterMeta.searchInfoAndTargetSteps(transMeta.getSteps());
    DummyTransMeta dummyMeta = new DummyTransMeta();
    StepMeta dummyStep = new StepMeta("Collect: " + iifField.getExpression(), dummyMeta);
    dummyStep.setLocation(xLocation, 50);
    xLocation += 100;
    dummyStep.setDraw(true);
    lastStep = addToTrans(dummyStep, transMeta, trueStep);
    transMeta.addTransHop(new TransHopMeta(falseStep, dummyStep));
    return lastStep;
}
Also used : FilterRowsMeta(org.pentaho.di.trans.steps.filterrows.FilterRowsMeta) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) IifFunction(org.pentaho.di.core.sql.IifFunction) CalculatorMeta(org.pentaho.di.trans.steps.calculator.CalculatorMeta) TransHopMeta(org.pentaho.di.trans.TransHopMeta) ConstantMeta(org.pentaho.di.trans.steps.constant.ConstantMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) CalculatorMetaFunction(org.pentaho.di.trans.steps.calculator.CalculatorMetaFunction) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) StreamInterface(org.pentaho.di.trans.step.errorhandling.StreamInterface) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)

Example 3 with FilterRowsMeta

use of org.pentaho.di.trans.steps.filterrows.FilterRowsMeta in project pentaho-kettle by pentaho.

the class StringSearcherTest method testSearchConditionCase.

@Test
public void testSearchConditionCase() {
    String dummyStepname = "Output";
    DummyTransMeta dummyMeta = new DummyTransMeta();
    String dummyStepPid = PluginRegistry.getInstance().getPluginId(StepPluginType.class, dummyMeta);
    StepMeta dummyStep = new StepMeta(dummyStepPid, dummyStepname, dummyMeta);
    List<StringSearchResult> stringList = new ArrayList<StringSearchResult>();
    StringSearcher.findMetaData(dummyStep, 0, stringList, dummyMeta, 0);
    int checkCount = 0;
    String aResult = null;
    // Check that it found a couple of fields and emits the values properly
    for (int i = 0; i < stringList.size(); i++) {
        aResult = stringList.get(i).toString();
        if (aResult.endsWith("Dummy (stepid)")) {
            checkCount++;
        } else if (aResult.endsWith("Output (name)")) {
            checkCount++;
        }
        if (checkCount == 2) {
            break;
        }
    }
    assertEquals(2, checkCount);
    FilterRowsMeta filterRowsMeta = new FilterRowsMeta();
    Condition condition = new Condition();
    condition.setNegated(false);
    condition.setLeftValuename("wibble_t");
    condition.setRightValuename("wobble_s");
    condition.setFunction(org.pentaho.di.core.Condition.FUNC_EQUAL);
    filterRowsMeta.setDefault();
    filterRowsMeta.setCondition(condition);
    String filterRowsPluginPid = PluginRegistry.getInstance().getPluginId(StepPluginType.class, filterRowsMeta);
    StepMeta filterRowsStep = new StepMeta(filterRowsPluginPid, "Filter Rows", filterRowsMeta);
    stringList.clear();
    StringSearcher.findMetaData(filterRowsStep, 0, stringList, filterRowsMeta, 0);
    checkCount = 0;
    for (int i = 0; i < stringList.size(); i++) {
        aResult = stringList.get(i).toString();
        if (aResult.endsWith("FilterRows (stepid)")) {
            checkCount++;
        } else if (aResult.endsWith("Filter Rows (name)")) {
            checkCount++;
        }
        if (checkCount == 2) {
            break;
        }
    }
    assertEquals(2, checkCount);
}
Also used : FilterRowsMeta(org.pentaho.di.trans.steps.filterrows.FilterRowsMeta) Condition(org.pentaho.di.core.Condition) ArrayList(java.util.ArrayList) StepMeta(org.pentaho.di.trans.step.StepMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) Test(org.junit.Test)

Example 4 with FilterRowsMeta

use of org.pentaho.di.trans.steps.filterrows.FilterRowsMeta in project pdi-dataservice-server-plugin by pentaho.

the class SqlTransGenerator method generateFilterStep.

private StepMeta generateFilterStep(Condition condition, boolean isHaving) {
    FilterRowsMeta meta = new FilterRowsMeta();
    meta.setCondition(condition);
    StepMeta stepMeta = new StepMeta(isHaving ? "Having filter" : "Where filter", meta);
    stepMeta.setLocation(xLocation, 50);
    xLocation += 100;
    stepMeta.setDraw(true);
    return stepMeta;
}
Also used : FilterRowsMeta(org.pentaho.di.trans.steps.filterrows.FilterRowsMeta) StepMeta(org.pentaho.di.trans.step.StepMeta)

Aggregations

FilterRowsMeta (org.pentaho.di.trans.steps.filterrows.FilterRowsMeta)4 StepMeta (org.pentaho.di.trans.step.StepMeta)3 Test (org.junit.Test)2 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)2 ArrayList (java.util.ArrayList)1 Condition (org.pentaho.di.core.Condition)1 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)1 IifFunction (org.pentaho.di.core.sql.IifFunction)1 TransHopMeta (org.pentaho.di.trans.TransHopMeta)1 StepMetaInterface (org.pentaho.di.trans.step.StepMetaInterface)1 StreamInterface (org.pentaho.di.trans.step.errorhandling.StreamInterface)1 CalculatorMeta (org.pentaho.di.trans.steps.calculator.CalculatorMeta)1 CalculatorMetaFunction (org.pentaho.di.trans.steps.calculator.CalculatorMetaFunction)1 ConstantMeta (org.pentaho.di.trans.steps.constant.ConstantMeta)1 Operations (org.pentaho.metaverse.api.model.Operations)1 FilterRowsStepNode (org.pentaho.metaverse.frames.FilterRowsStepNode)1 StreamFieldNode (org.pentaho.metaverse.frames.StreamFieldNode)1