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