Search in sources :

Example 1 with OptimizationImpactInfo

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;
}
Also used : RowMeta(org.pentaho.di.core.row.RowMeta) OptimizationImpactInfo(org.pentaho.di.trans.dataservice.optimization.OptimizationImpactInfo) PushDownOptimizationException(org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationException) LinkedList(java.util.LinkedList)

Example 2 with OptimizationImpactInfo

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;
}
Also used : OptimizationImpactInfo(org.pentaho.di.trans.dataservice.optimization.OptimizationImpactInfo) TransMeta(org.pentaho.di.trans.TransMeta) DuplicateParamException(org.pentaho.di.core.parameters.DuplicateParamException)

Example 3 with OptimizationImpactInfo

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;
}
Also used : OptimizationImpactInfo(org.pentaho.di.trans.dataservice.optimization.OptimizationImpactInfo) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 4 with OptimizationImpactInfo

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(""));
}
Also used : OptimizationImpactInfo(org.pentaho.di.trans.dataservice.optimization.OptimizationImpactInfo) Test(org.junit.Test)

Example 5 with OptimizationImpactInfo

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(""));
}
Also used : OptimizationImpactInfo(org.pentaho.di.trans.dataservice.optimization.OptimizationImpactInfo) Test(org.junit.Test)

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