Search in sources :

Example 6 with Condition

use of org.pentaho.di.core.Condition in project pentaho-kettle by pentaho.

the class FilterRowsMetaTest method testClone.

@Test
public void testClone() {
    FilterRowsMeta filterRowsMeta = new FilterRowsMeta();
    filterRowsMeta.setCondition(new Condition());
    filterRowsMeta.setTrueStepname("true");
    filterRowsMeta.setFalseStepname("false");
    FilterRowsMeta clone = (FilterRowsMeta) filterRowsMeta.clone();
    assertNotNull(clone.getCondition());
    assertEquals("true", clone.getTrueStepname());
    assertEquals("false", clone.getFalseStepname());
}
Also used : Condition(org.pentaho.di.core.Condition) Test(org.junit.Test)

Example 7 with Condition

use of org.pentaho.di.core.Condition in project pentaho-kettle by pentaho.

the class FilterRowsIT method testFilterConditionRefersToNonExistingFields.

@Test
public void testFilterConditionRefersToNonExistingFields() throws Exception {
    KettleEnvironment.init();
    // Create a new transformation...
    TransMeta transMeta = new TransMeta();
    transMeta.setName("filterrowstest");
    PluginRegistry registry = PluginRegistry.getInstance();
    // create an injector step...
    String injectorStepname = "injector step";
    InjectorMeta im = new InjectorMeta();
    // Set the information of the injector.
    String injectorPid = registry.getPluginId(StepPluginType.class, im);
    StepMeta injectorStep = new StepMeta(injectorPid, injectorStepname, im);
    transMeta.addStep(injectorStep);
    // Create a filter rows step
    String filterStepName = "filter rows step";
    FilterRowsMeta frm = new FilterRowsMeta();
    Condition condition = new Condition();
    String nonExistingFieldName = "non-existing-field";
    condition.setLeftValuename(nonExistingFieldName);
    // IS NOT
    condition.setFunction(8);
    condition.setRightValuename(null);
    condition.setOperator(0);
    frm.setCondition(condition);
    String filterRowsStepPid = registry.getPluginId(StepPluginType.class, frm);
    StepMeta filterRowsStep = new StepMeta(filterRowsStepPid, filterStepName, frm);
    transMeta.addStep(filterRowsStep);
    TransHopMeta hi = new TransHopMeta(injectorStep, filterRowsStep);
    transMeta.addTransHop(hi);
    // Now execute the transformation
    Trans trans = new Trans(transMeta);
    trans.prepareExecution(null);
    RowProducer rp = trans.addRowProducer(injectorStepname, 0);
    // add rows
    List<RowMetaAndData> inputList = createIntegerData();
    for (RowMetaAndData rm : inputList) {
        rp.putRow(rm.getRowMeta(), rm.getData());
    }
    rp.finished();
    trans.startThreads();
    trans.waitUntilFinished();
    // expect errors
    assertEquals(1, trans.getErrors());
}
Also used : Condition(org.pentaho.di.core.Condition) RowProducer(org.pentaho.di.trans.RowProducer) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) TransMeta(org.pentaho.di.trans.TransMeta) InjectorMeta(org.pentaho.di.trans.steps.injector.InjectorMeta) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) TransHopMeta(org.pentaho.di.trans.TransHopMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) Trans(org.pentaho.di.trans.Trans) Test(org.junit.Test)

Example 8 with Condition

use of org.pentaho.di.core.Condition in project pentaho-kettle by pentaho.

the class TransDebugDialog method showStepDebugInformation.

private void showStepDebugInformation() {
    // 
    for (Control control : wComposite.getChildren()) {
        control.dispose();
    }
    wComposite.layout(true, true);
    int[] selectionIndices = wSteps.table.getSelectionIndices();
    if (selectionIndices == null || selectionIndices.length != 1) {
        return;
    }
    previousIndex = selectionIndices[0];
    // What step did we click on?
    // 
    final StepMeta stepMeta = transDebugMeta.getTransMeta().getStep(selectionIndices[0]);
    // What is the step debugging metadata?
    // --> This can be null (most likely scenario)
    // 
    final StepDebugMeta stepDebugMeta = stepDebugMetaMap.get(stepMeta);
    // At the top we'll put a few common items like first[x], etc.
    // 
    // The row count (e.g. number of rows to keep)
    // 
    wRowCount = new LabelText(wComposite, BaseMessages.getString(PKG, "TransDebugDialog.RowCount.Label"), BaseMessages.getString(PKG, "TransDebugDialog.RowCount.ToolTip"));
    FormData fdRowCount = new FormData();
    fdRowCount.left = new FormAttachment(0, 0);
    fdRowCount.right = new FormAttachment(100, 0);
    fdRowCount.top = new FormAttachment(0, 0);
    wRowCount.setLayoutData(fdRowCount);
    wRowCount.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetDefaultSelected(SelectionEvent arg0) {
            ok(false);
        }
    });
    // Do we retrieve the first rows passing?
    // 
    wFirstRows = new Button(wComposite, SWT.CHECK);
    props.setLook(wFirstRows);
    wFirstRows.setText(BaseMessages.getString(PKG, "TransDebugDialog.FirstRows.Label"));
    wFirstRows.setToolTipText(BaseMessages.getString(PKG, "TransDebugDialog.FirstRows.ToolTip"));
    FormData fdFirstRows = new FormData();
    fdFirstRows.left = new FormAttachment(middle, 0);
    fdFirstRows.right = new FormAttachment(100, 0);
    fdFirstRows.top = new FormAttachment(wRowCount, margin);
    wFirstRows.setLayoutData(fdFirstRows);
    // Do we pause on break point, when the condition is met?
    // 
    wPauseBreakPoint = new Button(wComposite, SWT.CHECK);
    props.setLook(wPauseBreakPoint);
    wPauseBreakPoint.setText(BaseMessages.getString(PKG, "TransDebugDialog.PauseBreakPoint.Label"));
    wPauseBreakPoint.setToolTipText(BaseMessages.getString(PKG, "TransDebugDialog.PauseBreakPoint.ToolTip"));
    FormData fdPauseBreakPoint = new FormData();
    fdPauseBreakPoint.left = new FormAttachment(middle, 0);
    fdPauseBreakPoint.right = new FormAttachment(100, 0);
    fdPauseBreakPoint.top = new FormAttachment(wFirstRows, margin);
    wPauseBreakPoint.setLayoutData(fdPauseBreakPoint);
    // The condition to pause for...
    // 
    condition = null;
    if (stepDebugMeta != null) {
        condition = stepDebugMeta.getCondition();
    }
    if (condition == null) {
        condition = new Condition();
    }
    // The input fields...
    try {
        stepInputFields = transDebugMeta.getTransMeta().getStepFields(stepMeta);
    } catch (KettleStepException e) {
        stepInputFields = new RowMeta();
    }
    wlCondition = new Label(wComposite, SWT.RIGHT);
    props.setLook(wlCondition);
    wlCondition.setText(BaseMessages.getString(PKG, "TransDebugDialog.Condition.Label"));
    wlCondition.setToolTipText(BaseMessages.getString(PKG, "TransDebugDialog.Condition.ToolTip"));
    FormData fdlCondition = new FormData();
    fdlCondition.left = new FormAttachment(0, 0);
    fdlCondition.right = new FormAttachment(middle, -margin);
    fdlCondition.top = new FormAttachment(wPauseBreakPoint, margin);
    wlCondition.setLayoutData(fdlCondition);
    wCondition = new ConditionEditor(wComposite, SWT.BORDER, condition, stepInputFields);
    FormData fdCondition = new FormData();
    fdCondition.left = new FormAttachment(middle, 0);
    fdCondition.right = new FormAttachment(100, 0);
    fdCondition.top = new FormAttachment(wPauseBreakPoint, margin);
    fdCondition.bottom = new FormAttachment(100, 0);
    wCondition.setLayoutData(fdCondition);
    getStepDebugData(stepDebugMeta);
    // Add a "clear" button at the bottom on the left...
    // 
    Button wClear = new Button(wComposite, SWT.PUSH);
    props.setLook(wClear);
    wClear.setText(BaseMessages.getString(PKG, "TransDebugDialog.Clear.Label"));
    wClear.setToolTipText(BaseMessages.getString(PKG, "TransDebugDialog.Clear.ToolTip"));
    FormData fdClear = new FormData();
    fdClear.left = new FormAttachment(0, 0);
    fdClear.bottom = new FormAttachment(100, 0);
    wClear.setLayoutData(fdClear);
    wClear.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            // Clear the preview step information for this step...
            // 
            stepDebugMetaMap.remove(stepMeta);
            wSteps.table.setSelection(new int[] {});
            previousIndex = -1;
            // refresh the steps list...
            // 
            refreshStepList();
            showStepDebugInformation();
        }
    });
    wComposite.layout(true, true);
}
Also used : FormData(org.eclipse.swt.layout.FormData) Condition(org.pentaho.di.core.Condition) KettleStepException(org.pentaho.di.core.exception.KettleStepException) RowMeta(org.pentaho.di.core.row.RowMeta) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ConditionEditor(org.pentaho.di.ui.core.widget.ConditionEditor) Label(org.eclipse.swt.widgets.Label) StepMeta(org.pentaho.di.trans.step.StepMeta) Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) LabelText(org.pentaho.di.ui.core.widget.LabelText) FormAttachment(org.eclipse.swt.layout.FormAttachment) StepDebugMeta(org.pentaho.di.trans.debug.StepDebugMeta)

Example 9 with Condition

use of org.pentaho.di.core.Condition in project pentaho-metaverse by pentaho.

the class FilterRowsStepAnalyzer method getUsedFields.

@Override
protected Set<StepField> getUsedFields(FilterRowsMeta meta) {
    // add uses links to all of the fields that are part of the filter condition
    Set<StepField> usedFields = new HashSet<>();
    final Condition condition = meta.getCondition();
    if (condition != null) {
        for (String usedField : condition.getUsedFields()) {
            usedFields.addAll(createStepFields(usedField, getInputs()));
        }
    }
    return usedFields;
}
Also used : Condition(org.pentaho.di.core.Condition) StepField(org.pentaho.metaverse.api.StepField) HashSet(java.util.HashSet)

Example 10 with Condition

use of org.pentaho.di.core.Condition in project pdi-dataservice-server-plugin by pentaho.

the class TableInputParameterGeneration method convertCondition.

protected void convertCondition(Condition condition, StringBuilder builder, RowMeta paramsMeta, List<Object> params) throws PushDownOptimizationException {
    // Condition is composite: Recursively add children
    if (condition.isNegated()) {
        builder.append("NOT ");
    }
    if (condition.isComposite()) {
        builder.append("( ");
        for (Condition child : condition.getChildren()) {
            if (child.getOperator() == Condition.OPERATOR_AND) {
                builder.append(" AND ");
            } else if (child.getOperator() == Condition.OPERATOR_OR) {
                builder.append(" OR ");
            }
            convertCondition(child, builder, paramsMeta, params);
        }
        builder.append(" )");
    } else {
        builder.append(convertAtomicCondition(condition, paramsMeta, params));
    }
}
Also used : Condition(org.pentaho.di.core.Condition)

Aggregations

Condition (org.pentaho.di.core.Condition)42 Test (org.junit.Test)14 Matchers.anyString (org.mockito.Matchers.anyString)6 RowMeta (org.pentaho.di.core.row.RowMeta)6 SQLCondition (org.pentaho.di.core.sql.SQLCondition)6 StepMeta (org.pentaho.di.trans.step.StepMeta)6 KettleException (org.pentaho.di.core.exception.KettleException)5 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)5 SQL (org.pentaho.di.core.sql.SQL)5 ParameterGenerationTest.newCondition (org.pentaho.di.trans.dataservice.optimization.paramgen.ParameterGenerationTest.newCondition)5 KettleStepException (org.pentaho.di.core.exception.KettleStepException)4 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)4 ValueMetaAndData (org.pentaho.di.core.row.ValueMetaAndData)4 JUnitMatchers.containsString (org.junit.matchers.JUnitMatchers.containsString)3 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)3 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2