TableInputParameterGeneration implements ParameterGenerationService { @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 ), 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; } TableInputParameterGeneration( ValueMetaResolver resolver ); @Override String getParameterDefault(); @Override OptimizationImpactInfo preview( Condition pushDownCondition, ParameterGeneration parameterGeneration, StepInterface stepInterface ); @Override void pushDown( Condition condition, ParameterGeneration parameterGeneration, StepInterface stepInterface );  }
@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() ); }