Search in sources :

Example 36 with Condition

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

the class TableInputParameterGenerationTest method testConvertCondition.

@Test
public void testConvertCondition() throws Exception {
    // ( ( A | B ) & !C )
    Condition condition = new Condition();
    condition.addCondition(newCondition("A", "valA"));
    condition.getCondition(0).addCondition(newCondition(OR, "B", 32));
    condition.addCondition(newCondition(AND, "C", "valC"));
    condition.getCondition(1).negate();
    StringBuilder sqlBuilder = new StringBuilder();
    RowMeta paramsMeta = mock(RowMeta.class);
    List<Object> values = new LinkedList<Object>();
    service.convertCondition(condition, sqlBuilder, paramsMeta, values);
    assertThat(sqlBuilder.toString(), equalTo("( ( A = ? OR B = ? ) AND NOT C = ? )"));
    // Verify that resolved ValueMeta added 3 times, and data stored in order
    verify(paramsMeta, times(3)).addValueMeta(resolvedValueMeta);
    verify(databaseMeta, times(3)).quoteField(anyString());
    assertThat(values, equalTo(Arrays.<Object>asList("valA", 32, "valC")));
}
Also used : Condition(org.pentaho.di.core.Condition) ParameterGenerationTest.newCondition(org.pentaho.di.trans.dataservice.optimization.paramgen.ParameterGenerationTest.newCondition) RowMeta(org.pentaho.di.core.row.RowMeta) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 37 with Condition

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

the class TableInputParameterGenerationTest method testFunctionType.

@SuppressWarnings("unchecked")
private void testFunctionType(int function, String expected, Object value) throws Exception {
    ValueMetaAndData right_exact = new ValueMetaAndData("mock_value", value);
    Condition condition = new Condition("field_name", function, null, right_exact);
    RowMeta paramsMeta = mock(RowMeta.class);
    List<Object> params = mock(List.class);
    assertThat(service.convertAtomicCondition(condition, paramsMeta, params), equalTo(expected));
    if (value != null) {
        verify(paramsMeta).addValueMeta(resolvedValueMeta);
        verify(params).add(value);
    }
    verifyNoMoreInteractions(paramsMeta, params);
}
Also used : Condition(org.pentaho.di.core.Condition) ParameterGenerationTest.newCondition(org.pentaho.di.trans.dataservice.optimization.paramgen.ParameterGenerationTest.newCondition) RowMeta(org.pentaho.di.core.row.RowMeta) ValueMetaAndData(org.pentaho.di.core.row.ValueMetaAndData)

Example 38 with Condition

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

the class MongodbPredicate method getMongoOp.

private MongoOp getMongoOp(Condition condition) throws PushDownOptimizationException {
    validateConditionForOpDetermination(condition);
    final Condition firstChild = condition.getChildren().get(1);
    MongoOp op = MongoOp.getMongoOp(firstChild.getOperator());
    if (op == null) {
        throw new PushDownOptimizationException("Unsupported operator:  " + firstChild.getOperatorDesc());
    }
    return op;
}
Also used : Condition(org.pentaho.di.core.Condition) PushDownOptimizationException(org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationException)

Example 39 with Condition

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

the class ParameterGeneration method preview.

@Override
public OptimizationImpactInfo preview(DataServiceExecutor executor, StepInterface stepInterface) {
    ParameterGenerationService service = serviceProvider.getService(stepInterface.getStepMeta());
    Condition pushDownCondition = getPushDownCondition(executor.getSql());
    return service.preview(pushDownCondition, this, stepInterface);
}
Also used : Condition(org.pentaho.di.core.Condition)

Example 40 with Condition

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

the class ParameterGeneration method activate.

@Override
public boolean activate(DataServiceExecutor executor, StepInterface stepInterface) {
    ParameterGenerationService service = serviceProvider.getService(stepInterface.getStepMeta());
    Condition pushDownCondition = getPushDownCondition(executor.getSql());
    return handlePushDown(service, pushDownCondition, stepInterface);
}
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