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());
}
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());
}
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());
}
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;
}
Aggregations