dawidwys commented on a change in pull request #12184:
URL: https://github.com/apache/flink/pull/12184#discussion_r426165863



##########
File path: 
flink-connectors/flink-connector-elasticsearch-base/src/main/java/org/apache/flink/streaming/connectors/elasticsearch/table/RowElasticsearchSinkFunction.java
##########
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.streaming.connectors.elasticsearch.table;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.api.common.functions.RuntimeContext;
+import org.apache.flink.api.common.serialization.SerializationSchema;
+import 
org.apache.flink.streaming.connectors.elasticsearch.ElasticsearchSinkFunction;
+import org.apache.flink.streaming.connectors.elasticsearch.RequestIndexer;
+import org.apache.flink.table.api.TableException;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.util.Preconditions;
+
+import org.elasticsearch.action.ActionRequest;
+import org.elasticsearch.action.delete.DeleteRequest;
+import org.elasticsearch.action.update.UpdateRequest;
+import org.elasticsearch.common.xcontent.XContentType;
+
+import javax.annotation.Nullable;
+
+import java.util.Objects;
+import java.util.function.Function;
+
+/**
+ * Sink function for converting upserts into Elasticsearch {@link 
ActionRequest}s.
+ */
+@Internal
+class RowElasticsearchSinkFunction implements 
ElasticsearchSinkFunction<RowData> {
+
+       private static final long serialVersionUID = 1L;
+
+       private final IndexGenerator indexGenerator;
+       private final String docType;
+       private final SerializationSchema<RowData> serializationSchema;
+       private final XContentType contentType;
+       private final RequestFactory requestFactory;
+       private final Function<RowData, String> createKey;
+
+       public RowElasticsearchSinkFunction(
+                       IndexGenerator indexGenerator,
+                       @Nullable String docType, // this is deprecated in es 7+
+                       SerializationSchema<RowData> serializationSchema,
+                       XContentType contentType,
+                       RequestFactory requestFactory,
+                       Function<RowData, String> createKey) {
+               this.indexGenerator = 
Preconditions.checkNotNull(indexGenerator);
+               this.docType = docType;
+               this.serializationSchema = 
Preconditions.checkNotNull(serializationSchema);
+               this.contentType = Preconditions.checkNotNull(contentType);
+               this.requestFactory = 
Preconditions.checkNotNull(requestFactory);
+               this.createKey = Preconditions.checkNotNull(createKey);
+       }
+
+       @Override
+       public void process(
+                       RowData element,
+                       RuntimeContext ctx,
+                       RequestIndexer indexer) {
+               switch (element.getRowKind()) {
+                       case INSERT:
+                       case UPDATE_AFTER:
+                               processUpsert(element, indexer);
+                               break;
+                       case DELETE:

Review comment:
       I am not sure if I understood your comment.
   Will we still get the `UPDATE_BEFORE` event though we say in 
`org.apache.flink.streaming.connectors.elasticsearch.table.Elasticsearch7DynamicSink#getChangelogMode`
 that we do not support it?
   
   If we do, what should I do with it? shall I treat the same way as 
`UPDATE_AFTER`?




----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to