Search in sources :

Example 1 with PushDownOptimizationException

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

the class TableInputParameterGeneration method getSQL.

private String getSQL(StepInterface stepInterface) throws PushDownOptimizationException {
    TableInput tableInput;
    if (stepInterface instanceof TableInput) {
        tableInput = (TableInput) stepInterface;
    } else {
        throw new PushDownOptimizationException("Unable to push down to push down to type " + stepInterface.getClass());
    }
    final TableInputMeta tableInputMeta = (TableInputMeta) tableInput.getStepMeta().getStepMetaInterface();
    return tableInputMeta.getSQL();
}
Also used : TableInput(org.pentaho.di.trans.steps.tableinput.TableInput) PushDownOptimizationException(org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationException) TableInputMeta(org.pentaho.di.trans.steps.tableinput.TableInputMeta)

Example 2 with PushDownOptimizationException

use of org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationException 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 3 with PushDownOptimizationException

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

the class MongodbInputParameterGenerationTest method testPreviewWithConversionFailure.

@Test
public void testPreviewWithConversionFailure() throws KettleException {
    when(mongodbPredicate.asFilterCriteria()).thenThrow(new PushDownOptimizationException("FAILURE"));
    OptimizationImpactInfo impact = preview(condition, parameterGeneration, stepInterface);
    assertThat(impact.getStepName(), equalTo(MOCK_STEPNAME));
    assertThat(impact.getQueryBeforeOptimization(), equalTo(TEST_JSON_QUERY));
    assertFalse(impact.isModified());
    assertThat(impact.getErrorMsg(), containsString("FAILURE"));
}
Also used : OptimizationImpactInfo(org.pentaho.di.trans.dataservice.optimization.OptimizationImpactInfo) PushDownOptimizationException(org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationException) Test(org.junit.Test)

Example 4 with PushDownOptimizationException

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

the class TableInputParameterGenerationTest method testFailures.

@Test
public void testFailures() throws Exception {
    // Throw exception if type is not TableInput
    try {
        service.pushDown(mock(Condition.class), mock(ParameterGeneration.class), mock(StepInterface.class));
        fail();
    } catch (PushDownOptimizationException thrown) {
        assertThat(thrown.getMessage(), notNullValue());
    }
    // Throw exception if connection fails
    KettleDatabaseException expected = new KettleDatabaseException();
    data.db = mock(DatabaseWrapper.class);
    doThrow(expected).when(data.db).connect();
    try {
        service.pushDown(mock(Condition.class), mock(ParameterGeneration.class), stepInterface);
        fail();
    } catch (PushDownOptimizationException thrown) {
        assertThat(thrown.getCause(), equalTo((Throwable) expected));
    }
}
Also used : Condition(org.pentaho.di.core.Condition) ParameterGenerationTest.newCondition(org.pentaho.di.trans.dataservice.optimization.paramgen.ParameterGenerationTest.newCondition) StepInterface(org.pentaho.di.trans.step.StepInterface) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) PushDownOptimizationException(org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationException) Test(org.junit.Test)

Example 5 with PushDownOptimizationException

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

the class MongodbInputParameterGenerationTest method testQueryBeforeOptimizationWithConversionFailure.

@Test
public void testQueryBeforeOptimizationWithConversionFailure() throws KettleException {
    when(mongodbPredicate.asFilterCriteria()).thenThrow(new PushDownOptimizationException("FAILURE"));
    OptimizationImpactInfo impact = preview(condition, parameterGeneration, stepInterface);
    assertThat(impact.getQueryBeforeOptimization(), equalTo(TEST_JSON_QUERY));
}
Also used : OptimizationImpactInfo(org.pentaho.di.trans.dataservice.optimization.OptimizationImpactInfo) PushDownOptimizationException(org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationException) Test(org.junit.Test)

Aggregations

PushDownOptimizationException (org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationException)7 Test (org.junit.Test)3 OptimizationImpactInfo (org.pentaho.di.trans.dataservice.optimization.OptimizationImpactInfo)3 Condition (org.pentaho.di.core.Condition)2 LinkedList (java.util.LinkedList)1 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)1 RowMeta (org.pentaho.di.core.row.RowMeta)1 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)1 ParameterGenerationTest.newCondition (org.pentaho.di.trans.dataservice.optimization.paramgen.ParameterGenerationTest.newCondition)1 StepInterface (org.pentaho.di.trans.step.StepInterface)1 TableInput (org.pentaho.di.trans.steps.tableinput.TableInput)1 TableInputMeta (org.pentaho.di.trans.steps.tableinput.TableInputMeta)1