ParameterPushdown implements PushDownType { @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; }  List<Definition> getDefinitions(); Definition createDefinition(); @Override void init( TransMeta transMeta, DataServiceMeta dataService, PushDownOptimizationMeta optMeta ); @Override ListenableFuture<Boolean> activate( DataServiceExecutor executor, PushDownOptimizationMeta meta ); @Override OptimizationImpactInfo preview( DataServiceExecutor executor, PushDownOptimizationMeta meta ); static final String DEFINITIONS_LIST_ATTRIBUTE; static final String PARAMETER_ATTRIBUTE; static final String FIELD_NAME_ATTRIBUTE; static final String FORMAT_ATTRIBUTE; static final String DEFAULT_FORMAT; static final String PARAMETER_PREFIX; }
@Test public void testPreview() throws Exception { query( "WHERE ARTIST = 'The Rolling Stones' AND ALBUM = 'Let it Bleed' " ); when( transMeta.getParameterDefault( anyString() ) ).thenReturn( "<default>" ); OptimizationImpactInfo preview = parameterPushdown.preview( executor, optimizationMeta ); assertThat( preview.getErrorMsg(), emptyOrNullString() ); assertThat( preview.isModified(), is( true ) ); assertThat( preview.getQueryBeforeOptimization(), equalTo( "ARTIST_FIELD = <default>\n" + "ALBUM_FIELD = <default>\n" + "LIVE_FIELD = <default>" ) ); assertThat( preview.getQueryAfterOptimization(), equalTo( "ARTIST_FIELD = artist: \"The Rolling Stones\",\n" + "ALBUM_FIELD = album: \"Let it Bleed\",\n" + "LIVE_FIELD = <default>" ) ); }