JingsongLi commented on a change in pull request #41:
URL: https://github.com/apache/flink-table-store/pull/41#discussion_r826888566



##########
File path: 
flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/sink/TableStoreSink.java
##########
@@ -0,0 +1,175 @@
+/*
+ * 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.table.store.connector.sink;
+
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.table.catalog.CatalogLock;
+import org.apache.flink.table.connector.ChangelogMode;
+import org.apache.flink.table.connector.RequireCatalogLock;
+import org.apache.flink.table.connector.sink.DataStreamSinkProvider;
+import org.apache.flink.table.connector.sink.DynamicTableSink;
+import org.apache.flink.table.connector.sink.abilities.SupportsOverwrite;
+import org.apache.flink.table.connector.sink.abilities.SupportsPartitioning;
+import org.apache.flink.table.factories.DynamicTableFactory;
+import org.apache.flink.table.store.connector.TableStore;
+import org.apache.flink.table.store.log.LogOptions;
+import org.apache.flink.table.store.log.LogSinkProvider;
+import org.apache.flink.table.store.log.LogStoreTableFactory;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.logical.LogicalType;
+import org.apache.flink.types.RowKind;
+
+import javax.annotation.Nullable;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/** Table sink to create {@link StoreSink}. */
+public class TableStoreSink
+        implements DynamicTableSink, SupportsOverwrite, SupportsPartitioning, 
RequireCatalogLock {
+
+    private final TableStore tableStore;
+    private final boolean streaming;
+    private final LogOptions.LogChangelogMode logChangelogMode;
+    @Nullable private final DynamicTableFactory.Context logStoreContext;
+    @Nullable private final LogStoreTableFactory logStoreTableFactory;
+
+    private Map<String, String> staticPartitions = new HashMap<>();
+    private boolean overwrite;
+    @Nullable private CatalogLock.Factory lockFactory;
+
+    public TableStoreSink(
+            TableStore tableStore,
+            boolean streaming,
+            LogOptions.LogChangelogMode logChangelogMode,
+            @Nullable DynamicTableFactory.Context logStoreContext,
+            @Nullable LogStoreTableFactory logStoreTableFactory) {
+        this.tableStore = tableStore;
+        this.streaming = streaming;
+        this.logChangelogMode = logChangelogMode;
+        this.logStoreContext = logStoreContext;
+        this.logStoreTableFactory = logStoreTableFactory;
+    }
+
+    @Override
+    public ChangelogMode getChangelogMode(ChangelogMode requestedMode) {
+        if (!tableStore.valueCountMode()
+                && logChangelogMode == LogOptions.LogChangelogMode.UPSERT) {
+            ChangelogMode.Builder builder = ChangelogMode.newBuilder();
+            for (RowKind kind : requestedMode.getContainedKinds()) {
+                if (kind != RowKind.UPDATE_BEFORE) {
+                    builder.addContainedKind(kind);
+                }
+            }
+            return builder.build();
+        }
+        return requestedMode;
+    }
+
+    @Override
+    public SinkRuntimeProvider getSinkRuntimeProvider(Context context) {
+        LogSinkProvider logSinkProvider = null;
+        if (logStoreTableFactory != null) {
+            logSinkProvider =
+                    logStoreTableFactory.createSinkProvider(
+                            logStoreContext,
+                            new LogStoreTableFactory.SinkContext() {
+                                @Override
+                                public boolean isBounded() {
+                                    return !streaming;

Review comment:
       context.isBounded, streaming is useless.




-- 
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.

To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to