Search in sources :

Example 11 with OptimizationImpactInfo

use of org.pentaho.di.trans.dataservice.optimization.OptimizationImpactInfo in project pdi-dataservice-server-plugin by pentaho.

the class ParameterGenerationTest method testPreview.

@Test
public void testPreview() throws KettleValueException, PushDownOptimizationException {
    Condition condition = newCondition("A_src", "A_value");
    SQL query = mockSql(condition);
    when(executor.getSql()).thenReturn(query);
    OptimizationImpactInfo optImpact = mock(OptimizationImpactInfo.class);
    when(service.preview(any(Condition.class), same(paramGen), same(stepInterface))).thenReturn(optImpact);
    assertEquals(optImpact, paramGen.preview(executor, stepInterface));
    ArgumentCaptor<Condition> pushDownCaptor = ArgumentCaptor.forClass(Condition.class);
    verify(service).preview(pushDownCaptor.capture(), same(paramGen), same(stepInterface));
    Condition verify = pushDownCaptor.getValue();
    assertEquals("A_tgt", verify.getLeftValuename());
    assertEquals("A_value", verify.getRightExactString());
}
Also used : SQLCondition(org.pentaho.di.core.sql.SQLCondition) Condition(org.pentaho.di.core.Condition) OptimizationImpactInfo(org.pentaho.di.trans.dataservice.optimization.OptimizationImpactInfo) SQL(org.pentaho.di.core.sql.SQL) Test(org.junit.Test)

Example 12 with OptimizationImpactInfo

use of org.pentaho.di.trans.dataservice.optimization.OptimizationImpactInfo in project pdi-dataservice-server-plugin by pentaho.

the class TableInputParameterGenerationTest method testPreview.

@Test
public void testPreview() throws KettleValueException, PushDownOptimizationException {
    ParameterGeneration param = factory.createPushDown();
    param.setParameterName("param");
    Condition employeeFilter = newCondition("fooField", "barValue");
    when(stepInterface.getStepMeta()).thenReturn(mock(StepMeta.class));
    TableInputMeta mockTableInput = mock(TableInputMeta.class);
    String origQuery = "SELECT * FROM TABLE WHERE ${param}";
    when(mockTableInput.getSQL()).thenReturn("SELECT * FROM TABLE WHERE ${param}");
    when(stepInterface.getStepMeta().getStepMetaInterface()).thenReturn(mockTableInput);
    when(stepInterface.getStepname()).thenReturn("testStepName");
    OptimizationImpactInfo impact = service.preview(employeeFilter, param, stepInterface);
    assertThat(impact.getQueryBeforeOptimization(), equalTo(origQuery));
    assertThat(impact.getStepName(), equalTo("testStepName"));
    assertThat(impact.getQueryAfterOptimization(), equalTo("Parameterized SQL:  SELECT * FROM TABLE WHERE fooField = ?   {1: barValue}"));
    assertTrue(impact.isModified());
}
Also used : Condition(org.pentaho.di.core.Condition) ParameterGenerationTest.newCondition(org.pentaho.di.trans.dataservice.optimization.paramgen.ParameterGenerationTest.newCondition) OptimizationImpactInfo(org.pentaho.di.trans.dataservice.optimization.OptimizationImpactInfo) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) StepMeta(org.pentaho.di.trans.step.StepMeta) TableInputMeta(org.pentaho.di.trans.steps.tableinput.TableInputMeta) Test(org.junit.Test)

Example 13 with OptimizationImpactInfo

use of org.pentaho.di.trans.dataservice.optimization.OptimizationImpactInfo in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceTestModelTest method testGetSetClearOptimizationImpactDescription.

@Test
public void testGetSetClearOptimizationImpactDescription() throws Exception {
    assertEquals("\n[No Push Down Optimizations Defined]\n", model.getOptimizationImpactDescription());
    OptimizationImpactInfo mockInfo = mock(OptimizationImpactInfo.class);
    when(mockInfo.getDescription()).thenReturn("my optimization");
    model.addOptimizationImpact(mockInfo);
    assertEquals("\nmy optimization\n- - - - - - - - - - - - - - - - - - - - - -\n\n", model.getOptimizationImpactDescription());
    model.clearOptimizationImpact();
    assertEquals("\n[No Push Down Optimizations Defined]\n", model.getOptimizationImpactDescription());
}
Also used : OptimizationImpactInfo(org.pentaho.di.trans.dataservice.optimization.OptimizationImpactInfo) Test(org.junit.Test)

Example 14 with OptimizationImpactInfo

use of org.pentaho.di.trans.dataservice.optimization.OptimizationImpactInfo in project pdi-dataservice-server-plugin by pentaho.

the class MongodbInputParameterGeneration method preview.

@Override
public OptimizationImpactInfo preview(Condition pushDownCondition, ParameterGeneration parameterGeneration, StepInterface stepInterface) {
    OptimizationImpactInfo impactInfo = new OptimizationImpactInfo(stepInterface.getStepname());
    try {
        String jsonQuery = getJsonQuery(stepInterface);
        impactInfo.setQueryBeforeOptimization(jsonQuery);
        if (pushDownCondition == null) {
            impactInfo.setModified(false);
            return impactInfo;
        }
        String predicate = getMongodbPredicate(pushDownCondition, getFieldMappings(stepInterface)).asFilterCriteria();
        String modifiedQuery = parameterGeneration.setQueryParameter(jsonQuery, predicate);
        if (!modifiedQuery.equals(jsonQuery)) {
            impactInfo.setQueryAfterOptimization(modifiedQuery);
            impactInfo.setModified(true);
        }
    } catch (KettleException e) {
        log.logDetailed(String.format("Unable to optimize step '%s'", stepInterface.getStepname()));
        impactInfo.setModified(false);
        impactInfo.setErrorMsg(e);
    }
    return impactInfo;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) OptimizationImpactInfo(org.pentaho.di.trans.dataservice.optimization.OptimizationImpactInfo)

Aggregations

OptimizationImpactInfo (org.pentaho.di.trans.dataservice.optimization.OptimizationImpactInfo)14 Test (org.junit.Test)9 PushDownOptimizationException (org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationException)3 Condition (org.pentaho.di.core.Condition)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 JUnitMatchers.containsString (org.junit.matchers.JUnitMatchers.containsString)1 Matchers.anyString (org.mockito.Matchers.anyString)1 KettleException (org.pentaho.di.core.exception.KettleException)1 DuplicateParamException (org.pentaho.di.core.parameters.DuplicateParamException)1 RowMeta (org.pentaho.di.core.row.RowMeta)1 SQL (org.pentaho.di.core.sql.SQL)1 SQLCondition (org.pentaho.di.core.sql.SQLCondition)1 TransMeta (org.pentaho.di.trans.TransMeta)1 ParameterGenerationTest.newCondition (org.pentaho.di.trans.dataservice.optimization.paramgen.ParameterGenerationTest.newCondition)1 StepMeta (org.pentaho.di.trans.step.StepMeta)1 TableInputMeta (org.pentaho.di.trans.steps.tableinput.TableInputMeta)1