AutoParameterGenerationService implements AutoOptimizationService { @Override public List<PushDownOptimizationMeta> apply( DataServiceMeta dataServiceMeta ) { TransMeta transMeta = dataServiceMeta.getServiceTrans(); LogChannelInterface logChannel = transMeta.getLogChannel() != null ? transMeta.getLogChannel() : LogChannel.GENERAL; try { String stepName = dataServiceMeta.getStepname(); List<String> fields = Arrays.asList( transMeta.getStepFields( stepName ).getFieldNames() ); Map<String, Set<List<StepFieldOperations>>> operationPaths = lineageClient.getOperationPaths( transMeta, stepName, fields ); SourceLineageMap sourceLineageMap = SourceLineageMap.create( operationPaths ) .filterKeys( stepSupported( transMeta ) ) .filterKeys( not( in( parametrizedSteps( dataServiceMeta ) ) ) ) .filter( fieldUnchanged() ); return generateOptimizationList( sourceLineageMap ); } catch ( Throwable e ) { logChannel.logError( "Unable to run Auto-Optimization", e ); return Collections.emptyList(); } } AutoParameterGenerationService( ILineageClient lineageClient,
                                         ParameterGenerationFactory serviceProvider ); @Override List<PushDownOptimizationMeta> apply( DataServiceMeta dataServiceMeta ); @Override Set<Class<? extends PushDownType>> getProvidedOptimizationTypes();  }
@Test public void testApply() throws Exception { Map<String, Set<List<StepFieldOperations>>> operationPaths; List<StepFieldOperations> field1_input1 = Lists.newArrayList( new StepFieldOperations( "Input 1", "field1_origin", null ), new StepFieldOperations( "Modifier", "field1", new MockOperations(). put( ChangeType.DATA ).put( ChangeType.METADATA ) ) ); List<StepFieldOperations> field2_input1 = Lists.newArrayList( new StepFieldOperations( "Input 1", "field2_origin", null ), new StepFieldOperations( "Rename", "field2", new MockOperations(). put( ChangeType.METADATA ) ) ); List<StepFieldOperations> field2_input2 = Lists.newArrayList( new StepFieldOperations( "Input 2", "field2", null ) ); operationPaths = Maps.newHashMap(); operationPaths.put( "field1", ImmutableSet.of( field1_input1 ) ); operationPaths.put( "field2", ImmutableSet.of( field2_input1, field2_input2 ) ); when( lineageClient.getOperationPaths( same( transMeta ), eq( SERVICE_STEP ), eq( ImmutableList.copyOf( SERVICE_FIELDS ) ) ) ).thenReturn( operationPaths ); StepMeta input1Meta = mock( StepMeta.class ); when( transMeta.findStep( "Input 1" ) ).thenReturn( input1Meta ); when( serviceProvider.supportsStep( input1Meta ) ).thenReturn( true ); List<PushDownOptimizationMeta> optimizationMetaList = service.apply( dataService ); assertThat( optimizationMetaList, contains( allOf( hasProperty( "stepName", equalTo( "Input 1" ) ), hasProperty( "type", is( parameterGeneration ) ) ) ) ); verify( parameterGeneration ).setParameterName( anyString() ); verify( parameterGeneration ).createFieldMapping( "field2", "field2_origin" ); }