use of org.pentaho.di.trans.dataservice.optimization.OptimizationImpactInfo in project pdi-dataservice-server-plugin by pentaho.
the class TableInputParameterGeneration method preview.
@Override
public OptimizationImpactInfo preview(Condition pushDownCondition, ParameterGeneration parameterGeneration, StepInterface stepInterface) {
OptimizationImpactInfo optimizationInfo = new OptimizationImpactInfo(stepInterface.getStepname());
try {
final String sql = getSQL(stepInterface);
optimizationInfo.setQueryBeforeOptimization(sql);
if (pushDownCondition == null) {
optimizationInfo.setModified(false);
return optimizationInfo;
}
DatabaseWrapper db = getDatabaseWrapper(stepInterface);
StringBuilder sqlFragment = new StringBuilder();
RowMeta paramsMeta = new RowMeta();
List<Object> params = new LinkedList<Object>();
dbMeta = db.getDatabaseMeta();
convertCondition(pushDownCondition, sqlFragment, paramsMeta, params);
String fragmentId = db.createRuntimePushDown(sqlFragment.toString(), paramsMeta, params, getParameterDefault());
final String modifiedSql = db.injectRuntime(db.pushDownMap, parameterGeneration.setQueryParameter(sql, fragmentId), // setVariableInSql( sql, parameterGeneration.getParameterName(), fragmentId ),
new RowMeta(), new LinkedList<Object>());
optimizationInfo.setQueryAfterOptimization(db.parameterizedQueryToString(modifiedSql, params));
optimizationInfo.setModified(true);
} catch (PushDownOptimizationException e) {
optimizationInfo.setModified(false);
optimizationInfo.setErrorMsg(e);
}
return optimizationInfo;
}
use of org.pentaho.di.trans.dataservice.optimization.OptimizationImpactInfo in project pdi-dataservice-server-plugin by pentaho.
the class ParameterPushdown method preview.
@Override
public OptimizationImpactInfo preview(DataServiceExecutor executor, PushDownOptimizationMeta meta) {
OptimizationImpactInfo impactInfo = new OptimizationImpactInfo(meta.getStepName());
try {
TransMeta serviceTrans = executor.getServiceTransMeta();
Map<String, String> defaults = Maps.newLinkedHashMap();
for (Definition definition : definitions) {
String defaultValue = serviceTrans.getParameterDefault(definition.getParameter());
defaults.put(definition.getParameter(), Objects.firstNonNull(defaultValue, ""));
}
Map<String, String> parameterValues = Maps.newLinkedHashMap(defaults);
parameterValues.putAll(captureParameterValues(executor.getSql()));
impactInfo.setQueryBeforeOptimization(mapJoiner.join(defaults));
impactInfo.setQueryAfterOptimization(mapJoiner.join(parameterValues));
impactInfo.setModified(!parameterValues.equals(defaults));
} catch (Exception e) {
impactInfo.setErrorMsg(e);
}
return impactInfo;
}
use of org.pentaho.di.trans.dataservice.optimization.OptimizationImpactInfo in project pdi-dataservice-server-plugin by pentaho.
the class ServiceCache method preview.
@Override
public OptimizationImpactInfo preview(DataServiceExecutor executor, StepInterface stepInterface) {
OptimizationImpactInfo info = new OptimizationImpactInfo(executor.getService().getStepname());
Map<CachedService.CacheKey, CachedService> availableCache = getAvailableCache(executor);
for (Map.Entry<CachedService.CacheKey, CachedService> available : availableCache.entrySet()) {
info.setModified(true);
info.setQueryBeforeOptimization(MessageFormat.format("Service results for {0} are available.", available.getKey()));
info.setQueryAfterOptimization(MessageFormat.format("{0} rows can be read from cache.", available.getValue().getRowMetaAndData().size()));
return info;
}
info.setModified(false);
info.setQueryBeforeOptimization("Service results are not available. Execute this query to cache results.");
return info;
}
use of org.pentaho.di.trans.dataservice.optimization.OptimizationImpactInfo in project pdi-dataservice-server-plugin by pentaho.
the class MongodbInputParameterGenerationTest method testPreviewWithModification.
@Test
public void testPreviewWithModification() {
OptimizationImpactInfo impact = preview(condition, parameterGeneration, stepInterface);
assertThat(impact.getStepName(), equalTo(MOCK_STEPNAME));
assertThat(impact.getQueryBeforeOptimization(), equalTo(TEST_JSON_QUERY));
assertThat(impact.getQueryAfterOptimization(), equalTo("after optimization"));
assertTrue(impact.isModified());
assertThat(impact.getErrorMsg(), equalTo(""));
}
use of org.pentaho.di.trans.dataservice.optimization.OptimizationImpactInfo in project pdi-dataservice-server-plugin by pentaho.
the class MongodbInputParameterGenerationTest method testPreviewWithNoQuery.
@Test
public void testPreviewWithNoQuery() throws KettleException {
when(stepInterface.getStepMeta().getXML()).thenReturn("<empty/>");
when(parameterGeneration.setQueryParameter("", "mockedFilter")).thenReturn("");
when(parameterGeneration.getParameterName()).thenReturn("paramName");
OptimizationImpactInfo impact = preview(condition, parameterGeneration, stepInterface);
assertThat(impact.getStepName(), equalTo(MOCK_STEPNAME));
assertThat(impact.getQueryBeforeOptimization(), equalTo("<no query>"));
assertThat(impact.getQueryAfterOptimization(), equalTo(""));
assertFalse(impact.isModified());
assertThat(impact.getErrorMsg(), equalTo(""));
}
Aggregations