You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2021/08/18 11:20:53 UTC

[GitHub] [rocketmq-externals] ni-ze commented on a change in pull request #781: [#780] Support the RocketMQ TableSink based on the legacy Sink implementation

ni-ze commented on a change in pull request #781:
URL: https://github.com/apache/rocketmq-externals/pull/781#discussion_r691140471



##########
File path: rocketmq-flink/src/main/java/org/apache/rocketmq/flink/sink/table/RocketMQDynamicTableSink.java
##########
@@ -0,0 +1,257 @@
+/*
+ * 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.rocketmq.flink.sink.table;
+
+import org.apache.rocketmq.flink.legacy.RocketMQConfig;
+import org.apache.rocketmq.flink.legacy.RocketMQSink;
+
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.java.typeutils.RowTypeInfo;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.TableSchema;
+import org.apache.flink.table.connector.ChangelogMode;
+import org.apache.flink.table.connector.sink.DynamicTableSink;
+import org.apache.flink.table.connector.sink.SinkFunctionProvider;
+import org.apache.flink.table.connector.sink.abilities.SupportsWritingMetadata;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.descriptors.DescriptorProperties;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.utils.LegacyTypeInfoDataTypeConverter;
+import org.apache.flink.types.RowKind;
+
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.stream.Stream;
+
+import static org.apache.rocketmq.flink.sink.table.RocketMQRowDataConverter.MetadataConverter;
+
+/** Defines the dynamic table sink of RocketMQ. */
+public class RocketMQDynamicTableSink implements DynamicTableSink, SupportsWritingMetadata {
+
+    private final DescriptorProperties properties;
+    private final TableSchema schema;
+
+    private final String topic;
+    private final String producerGroup;
+    private final String nameServerAddress;
+    private final String tag;
+    private final String dynamicColumn;
+    private final String fieldDelimiter;
+    private final String encoding;
+
+    private final long retryTimes;
+    private final long sleepTime;
+
+    private final boolean isDynamicTag;
+    private final boolean isDynamicTagIncluded;
+    private final boolean writeKeysToBody;
+
+    private final String[] keyColumns;
+
+    private List<String> metadataKeys;
+
+    public RocketMQDynamicTableSink(
+            DescriptorProperties properties,
+            TableSchema schema,
+            String topic,
+            String producerGroup,
+            String nameServerAddress,
+            String tag,
+            String dynamicColumn,
+            String fieldDelimiter,
+            String encoding,
+            long retryTimes,
+            long sleepTime,
+            boolean isDynamicTag,
+            boolean isDynamicTagIncluded,
+            boolean writeKeysToBody,
+            String[] keyColumns) {
+        this.properties = properties;
+        this.schema = schema;
+        this.topic = topic;
+        this.producerGroup = producerGroup;
+        this.nameServerAddress = nameServerAddress;
+        this.tag = tag;
+        this.dynamicColumn = dynamicColumn;
+        this.fieldDelimiter = fieldDelimiter;
+        this.encoding = encoding;
+        this.retryTimes = retryTimes;
+        this.sleepTime = sleepTime;
+        this.isDynamicTag = isDynamicTag;
+        this.isDynamicTagIncluded = isDynamicTagIncluded;
+        this.writeKeysToBody = writeKeysToBody;
+        this.keyColumns = keyColumns;
+        this.metadataKeys = Collections.emptyList();
+    }
+
+    @Override
+    public ChangelogMode getChangelogMode(ChangelogMode requestedMode) {
+        ChangelogMode.Builder builder = ChangelogMode.newBuilder();
+        for (RowKind kind : requestedMode.getContainedKinds()) {
+            if (kind != RowKind.UPDATE_BEFORE) {

Review comment:
       Why this RowKind.UPDATA_BEFORE kind of ChangelogMode is excluded?

##########
File path: rocketmq-flink/src/test/java/org/apache/rocketmq/flink/sink/table/RocketMQDynamicTableSinkFactoryTest.java
##########
@@ -0,0 +1,107 @@
+/*
+ * 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.rocketmq.flink.sink.table;
+
+import org.apache.rocketmq.flink.common.RocketMQOptions;
+
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.table.api.Schema;
+import org.apache.flink.table.api.ValidationException;
+import org.apache.flink.table.catalog.CatalogTable;
+import org.apache.flink.table.catalog.Column;
+import org.apache.flink.table.catalog.ObjectIdentifier;
+import org.apache.flink.table.catalog.ResolvedCatalogTable;
+import org.apache.flink.table.catalog.ResolvedSchema;
+import org.apache.flink.table.connector.sink.DynamicTableSink;
+import org.apache.flink.table.factories.FactoryUtil;
+
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.apache.flink.table.api.DataTypes.STRING;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/** Tests for {@link org.apache.rocketmq.flink.sink.table.RocketMQDynamicTableSinkFactory}. */
+public class RocketMQDynamicTableSinkFactoryTest {

Review comment:
       It is look like only this test can not cover all change code.




-- 
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: dev-unsubscribe@rocketmq.apache.org

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