wg1026688210 commented on a change in pull request #13918:
URL: https://github.com/apache/flink/pull/13918#discussion_r517147663



##########
File path: 
flink-connectors/flink-connector-elasticsearch6/src/main/java/org/apache/flink/streaming/connectors/elasticsearch/table/Elasticsearch6DynamicSink.java
##########
@@ -115,50 +117,58 @@ public ChangelogMode getChangelogMode(ChangelogMode 
requestedMode) {
 
        @Override
        public SinkFunctionProvider getSinkRuntimeProvider(Context context) {
-               return () -> {
-                       SerializationSchema<RowData> format = 
this.format.createRuntimeEncoder(context, schema.toRowDataType());
-
-                       final RowElasticsearchSinkFunction upsertFunction =
-                               new RowElasticsearchSinkFunction(
-                                       
IndexGeneratorFactory.createIndexGenerator(config.getIndex(), schema),
-                                       config.getDocumentType(),
-                                       format,
-                                       XContentType.JSON,
-                                       REQUEST_FACTORY,
-                                       KeyExtractor.createKeyExtractor(schema, 
config.getKeyDelimiter())
-                               );
-
-                       final ElasticsearchSink.Builder<RowData> builder = 
builderProvider.createBuilder(
-                               config.getHosts(),
-                               upsertFunction);
-
-                       builder.setFailureHandler(config.getFailureHandler());
-                       
builder.setBulkFlushMaxActions(config.getBulkFlushMaxActions());
-                       builder.setBulkFlushMaxSizeMb((int) 
(config.getBulkFlushMaxByteSize() >> 20));
-                       
builder.setBulkFlushInterval(config.getBulkFlushInterval());
-                       
builder.setBulkFlushBackoff(config.isBulkFlushBackoffEnabled());
-                       
config.getBulkFlushBackoffType().ifPresent(builder::setBulkFlushBackoffType);
-                       
config.getBulkFlushBackoffRetries().ifPresent(builder::setBulkFlushBackoffRetries);
-                       
config.getBulkFlushBackoffDelay().ifPresent(builder::setBulkFlushBackoffDelay);
-
-                       // we must overwrite the default factory which is 
defined with a lambda because of a bug
-                       // in shading lambda serialization shading see 
FLINK-18006
-                       if (config.getUsername().isPresent()
-                               && config.getPassword().isPresent()
-                               && 
!StringUtils.isNullOrWhitespaceOnly(config.getUsername().get())
-                               && 
!StringUtils.isNullOrWhitespaceOnly(config.getPassword().get())) {
-                               builder.setRestClientFactory(new 
AuthRestClientFactory(config.getPathPrefix().orElse(null), 
config.getUsername().get(), config.getPassword().get()));
-                       } else {
-                               builder.setRestClientFactory(new 
DefaultRestClientFactory(config.getPathPrefix().orElse(null)));
+               return new SinkFunctionProvider() {

Review comment:
       According to the previous code in `ElasticSearchTableSink`, anonymous 
class is called  to create ES sinkFunctionProvider instead of Factory method 
`of` being called. So to make less change of code, I kept the usage of 
anonymous class. On the other Hand, using `Of` here seem not to be a good 
choice cuz it makes code not so clear for reading and modifying.
   What's more, if `Of` is being called, this pr is blocked until #13902 
finished and merged.
    WDYT?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to