You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by GitBox <gi...@apache.org> on 2022/06/16 15:28:02 UTC

[GitHub] [incubator-seatunnel] ruanwenjun commented on a diff in pull request #2022: [Feature][Connector]add AssertSink connector

ruanwenjun commented on code in PR #2022:
URL: https://github.com/apache/incubator-seatunnel/pull/2022#discussion_r899199866


##########
seatunnel-connectors/seatunnel-connectors-flink/pom.xml:
##########
@@ -43,7 +43,7 @@
         <module>seatunnel-connector-flink-doris</module>
         <module>seatunnel-connector-flink-influxdb</module>
         <module>seatunnel-connector-flink-clickhouse</module>
-        <module>seatunnel-connector-flink-http</module>
+        <module>seatunnel-connector-flink-assert</module>

Review Comment:
   Please add a new module, rather than change http to assert



##########
docs/sidebars.js:
##########
@@ -128,6 +128,9 @@ const sidebars = {
         'transform/sql',
         'transform/split',
         'transform/json',
+        'transform/replace',
+        'transform/udf',
+        'transform/uuid',

Review Comment:
   In my knowledge, the sidebars will be auto generated(I am not sure), but you don't need to do this change in this PR.



##########
seatunnel-connectors/seatunnel-connectors-flink/seatunnel-connector-flink-assert/src/main/java/org/apache/seatunnel/flink/assertion/sink/AssertSink.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * 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.seatunnel.flink.assertion.sink;
+
+import com.google.auto.service.AutoService;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.flink.api.java.DataSet;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.types.Row;
+import org.apache.seatunnel.common.config.CheckResult;
+import org.apache.seatunnel.flink.BaseFlinkSink;
+import org.apache.seatunnel.flink.FlinkEnvironment;
+import org.apache.seatunnel.flink.assertion.AssertExecutor;
+import org.apache.seatunnel.flink.assertion.rule.AssertFieldRule;
+import org.apache.seatunnel.flink.assertion.rule.AssertRuleParser;
+import org.apache.seatunnel.flink.batch.FlinkBatchSink;
+import org.apache.seatunnel.flink.stream.FlinkStreamSink;
+import org.apache.seatunnel.shade.com.typesafe.config.Config;
+
+import java.util.List;
+
+/**
+ * A flink sink plugin which can assert illegal data by user defined rules
+ * Refer to https://github.com/apache/incubator-seatunnel/issues/1912
+ */
+@AutoService(BaseFlinkSink.class)
+public class AssertSink implements FlinkBatchSink, FlinkStreamSink {
+    //The assertion executor
+    private static final AssertExecutor ASSERT_EXECUTOR = new AssertExecutor();
+    //User defined rules used to assert illegal data
+    private List<AssertFieldRule> assertFieldRules;
+    private static final String RULES = "rules";
+    private Config config;
+    private List<? extends Config> configList;
+
+    @Override
+    public void outputBatch(FlinkEnvironment env, DataSet<Row> inDataSet) {
+        inDataSet.map(row -> {

Review Comment:
   It's better to use reduce here.



##########
seatunnel-connectors/seatunnel-connectors-flink/seatunnel-connector-flink-assert/src/main/java/org/apache/seatunnel/flink/assertion/sink/AssertSink.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * 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.seatunnel.flink.assertion.sink;
+
+import com.google.auto.service.AutoService;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.flink.api.java.DataSet;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.types.Row;
+import org.apache.seatunnel.common.config.CheckResult;
+import org.apache.seatunnel.flink.BaseFlinkSink;
+import org.apache.seatunnel.flink.FlinkEnvironment;
+import org.apache.seatunnel.flink.assertion.AssertExecutor;
+import org.apache.seatunnel.flink.assertion.rule.AssertFieldRule;
+import org.apache.seatunnel.flink.assertion.rule.AssertRuleParser;
+import org.apache.seatunnel.flink.batch.FlinkBatchSink;
+import org.apache.seatunnel.flink.stream.FlinkStreamSink;
+import org.apache.seatunnel.shade.com.typesafe.config.Config;
+
+import java.util.List;
+
+/**
+ * A flink sink plugin which can assert illegal data by user defined rules
+ * Refer to https://github.com/apache/incubator-seatunnel/issues/1912
+ */
+@AutoService(BaseFlinkSink.class)
+public class AssertSink implements FlinkBatchSink, FlinkStreamSink {
+    //The assertion executor
+    private static final AssertExecutor ASSERT_EXECUTOR = new AssertExecutor();
+    //User defined rules used to assert illegal data
+    private List<AssertFieldRule> assertFieldRules;
+    private static final String RULES = "rules";
+    private Config config;
+    private List<? extends Config> configList;
+
+    @Override
+    public void outputBatch(FlinkEnvironment env, DataSet<Row> inDataSet) {
+        inDataSet.map(row -> {
+            System.out.println(row);

Review Comment:
   ```suggestion
               
   ```



##########
seatunnel-core/seatunnel-core-flink/src/main/java/org/apache/seatunnel/core/flink/config/FlinkRunMode.java:
##########
@@ -35,4 +35,8 @@ public enum FlinkRunMode {
     public String getMode() {
         return mode;
     }
+
+    public String toString() {
+        return mode;

Review Comment:
   ```suggestion
           return "FlinkRunMode{" +
               "mode='" + mode + '\'' +
               '}';
   ```



##########
seatunnel-connectors/seatunnel-connectors-flink/seatunnel-connector-flink-assert/src/main/java/org/apache/seatunnel/flink/assertion/sink/AssertSink.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * 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.seatunnel.flink.assertion.sink;
+
+import com.google.auto.service.AutoService;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.flink.api.java.DataSet;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.types.Row;
+import org.apache.seatunnel.common.config.CheckResult;
+import org.apache.seatunnel.flink.BaseFlinkSink;
+import org.apache.seatunnel.flink.FlinkEnvironment;
+import org.apache.seatunnel.flink.assertion.AssertExecutor;
+import org.apache.seatunnel.flink.assertion.rule.AssertFieldRule;
+import org.apache.seatunnel.flink.assertion.rule.AssertRuleParser;
+import org.apache.seatunnel.flink.batch.FlinkBatchSink;
+import org.apache.seatunnel.flink.stream.FlinkStreamSink;
+import org.apache.seatunnel.shade.com.typesafe.config.Config;
+
+import java.util.List;
+
+/**
+ * A flink sink plugin which can assert illegal data by user defined rules
+ * Refer to https://github.com/apache/incubator-seatunnel/issues/1912
+ */
+@AutoService(BaseFlinkSink.class)
+public class AssertSink implements FlinkBatchSink, FlinkStreamSink {
+    //The assertion executor
+    private static final AssertExecutor ASSERT_EXECUTOR = new AssertExecutor();
+    //User defined rules used to assert illegal data
+    private List<AssertFieldRule> assertFieldRules;
+    private static final String RULES = "rules";
+    private Config config;
+    private List<? extends Config> configList;
+
+    @Override
+    public void outputBatch(FlinkEnvironment env, DataSet<Row> inDataSet) {
+        inDataSet.map(row -> {
+            System.out.println(row);
+            ASSERT_EXECUTOR
+                    .fail(row, assertFieldRules)
+                    .ifPresent(failRule -> {
+                        throw new IllegalStateException("row :" + row + " fail rule: " + failRule);
+                    });
+            return null;
+        });
+    }
+
+    @Override
+    public void outputStream(FlinkEnvironment env, DataStream<Row> dataStream) {
+        dataStream.map(row -> {
+            System.out.println(row);

Review Comment:
   ```suggestion
           dataStream.reduce(row -> {
   
   ```



##########
seatunnel-connectors/seatunnel-connectors-flink/seatunnel-connector-flink-assert/src/test/java/org/apache/seatunnel/flink/assertion/AssertExecutorTest.java:
##########
@@ -0,0 +1,86 @@
+package org.apache.seatunnel.flink.assertion;

Review Comment:
   Please add license header



##########
seatunnel-examples/seatunnel-flink-examples/src/main/resources/examples/fake_to_console.conf:
##########
@@ -48,6 +48,44 @@ transform {
 sink {
   ConsoleSink {}
 
+  #AssertSink {

Review Comment:
   Please revert this change, and add doc for this plugin.



-- 
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: commits-unsubscribe@seatunnel.apache.org

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