Search in sources :

Example 21 with Condition

use of org.pentaho.di.core.Condition 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 22 with Condition

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

the class KettleDatabaseRepositoryConditionDelegate method saveCondition.

public ObjectId saveCondition(Condition condition, ObjectId id_condition_parent) throws KettleException {
    try {
        condition.setObjectId(insertCondition(id_condition_parent, condition));
        for (int i = 0; i < condition.nrConditions(); i++) {
            Condition subc = condition.getCondition(i);
            repository.saveCondition(subc, condition.getObjectId());
        }
        return condition.getObjectId();
    } catch (KettleException dbe) {
        throw new KettleException("Error saving condition to the repository.", dbe);
    }
}
Also used : Condition(org.pentaho.di.core.Condition) KettleException(org.pentaho.di.core.exception.KettleException)

Example 23 with Condition

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

the class KettleDatabaseRepositoryConditionDelegate method loadCondition.

/**
 * Read a condition from the repository.
 *
 * @param id_condition
 *          The condition id
 * @throws KettleException
 *           if something goes wrong.
 */
public Condition loadCondition(ObjectId id_condition) throws KettleException {
    Condition condition = new Condition();
    try {
        RowMetaAndData r = getCondition(id_condition);
        if (r != null) {
            condition.setNegated(r.getBoolean("NEGATED", false));
            condition.setOperator(Condition.getOperator(r.getString("OPERATOR", null)));
            long conditionId = r.getInteger("ID_CONDITION", -1L);
            if (conditionId > 0) {
                condition.setObjectId(new LongObjectId(conditionId));
            } else {
                condition.setObjectId(null);
            }
            ObjectId[] subids = repository.getSubConditionIDs(condition.getObjectId());
            if (subids.length == 0) {
                condition.setLeftValuename(r.getString("LEFT_NAME", null));
                condition.setFunction(Condition.getFunction(r.getString("CONDITION_FUNCTION", null)));
                condition.setRightValuename(r.getString("RIGHT_NAME", null));
                long id_value = r.getInteger("ID_VALUE_RIGHT", -1L);
                if (id_value > 0) {
                    ValueMetaAndData v = repository.loadValueMetaAndData(new LongObjectId(id_value));
                    condition.setRightExact(v);
                }
            } else {
                for (int i = 0; i < subids.length; i++) {
                    condition.addCondition(loadCondition(subids[i]));
                }
            }
            return condition;
        } else {
            throw new KettleException("Condition with id_condition=" + id_condition + " could not be found in the repository");
        }
    } catch (KettleException dbe) {
        throw new KettleException("Error loading condition from the repository (id_condition=" + id_condition + ")", dbe);
    }
}
Also used : Condition(org.pentaho.di.core.Condition) KettleException(org.pentaho.di.core.exception.KettleException) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) ObjectId(org.pentaho.di.repository.ObjectId) LongObjectId(org.pentaho.di.repository.LongObjectId) LongObjectId(org.pentaho.di.repository.LongObjectId) ValueMetaAndData(org.pentaho.di.core.row.ValueMetaAndData)

Example 24 with Condition

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

the class FilterRowsMetaTest method modifiedTarget.

@Test
public void modifiedTarget() throws Exception {
    FilterRowsMeta filterRowsMeta = new FilterRowsMeta();
    StepMeta trueOutput = new StepMeta("true", new DummyTransMeta());
    StepMeta falseOutput = new StepMeta("false", new DummyTransMeta());
    filterRowsMeta.setCondition(new Condition());
    filterRowsMeta.setTrueStepname(trueOutput.getName());
    filterRowsMeta.setFalseStepname(falseOutput.getName());
    filterRowsMeta.searchInfoAndTargetSteps(ImmutableList.of(trueOutput, falseOutput));
    trueOutput.setName("true renamed");
    falseOutput.setName("false renamed");
    assertEquals("true renamed", filterRowsMeta.getTrueStepname());
    assertEquals("false renamed", filterRowsMeta.getFalseStepname());
}
Also used : Condition(org.pentaho.di.core.Condition) StepMeta(org.pentaho.di.trans.step.StepMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) Test(org.junit.Test)

Example 25 with Condition

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

the class ConditionLoadSaveValidator method getTestObject.

@Override
public Condition getTestObject() {
    Condition rtn = new Condition();
    rtn.setFunction(rand.nextInt(Condition.functions.length));
    rtn.setLeftValuename(UUID.randomUUID().toString());
    rtn.setNegated(rand.nextBoolean());
    rtn.setOperator(rand.nextInt(Condition.operators.length));
    rtn.setRightValuename(UUID.randomUUID().toString());
    return rtn;
}
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