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/04/28 02:33:18 UTC

[GitHub] [incubator-seatunnel] BenJFan commented on a diff in pull request #1761: [Feature][seatunnel-transforms] Add Replace transforms for flink #1759

BenJFan commented on code in PR #1761:
URL: https://github.com/apache/incubator-seatunnel/pull/1761#discussion_r860402414


##########
seatunnel-transforms/seatunnel-transforms-flink/seatunnel-transform-flink-replace/src/main/java/org/apache/seatunnel/flink/transform/Replace.java:
##########
@@ -0,0 +1,105 @@
+package org.apache.seatunnel.flink.transform;
+
+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.CheckConfigUtil;
+import org.apache.seatunnel.common.config.CheckResult;
+import org.apache.seatunnel.flink.FlinkEnvironment;
+import org.apache.seatunnel.flink.batch.FlinkBatchTransform;
+import org.apache.seatunnel.flink.stream.FlinkStreamTransform;
+import org.apache.seatunnel.shade.com.typesafe.config.Config;
+
+public class Replace implements FlinkStreamTransform, FlinkBatchTransform {
+
+    private Config config;
+
+    private static final String PATTERN = "pattern";
+    private static final String REPLACEMENT = "replacement";
+    private static final String ISREGEX = "is_regex";
+    private static final String REPLACEFIRST = "replace_first";
+
+    private String pattern = "";
+    private String replacement = "";
+    private Boolean isRegex = false;
+    private Boolean replaceFirst = false;
+
+
+    /**
+     * @param config
+     */
+    @Override
+    public void setConfig(Config config) {
+        this.config = config;
+    }
+
+    /**
+     * @return

Review Comment:
   Useless comment. Just remove it will be better.



##########
docs/en/transform/replace.md:
##########
@@ -67,13 +67,103 @@ Use `Replace` as udf in sql.
   Replace {
     fields = "_replaced"
     pattern = "([^ ]*) ([^ ]*)"
-    replacement = "$2
+    replacement = "$2“
     isRegex = true
     replaceFirst = true
   }
 
-  # Use the split function (confirm that the fake table exists)
+  # Use the replace function (confirm that the fake table exists)
   sql {
     sql = "select * from (select raw_message, replace(raw_message) as info_row from fake) t1"
   }
 ```
+
+## Options(Flink)
+
+| name  | type   | required | default value |
+| ----- | ------ | -------- |---------------|
+| pattern      | string | no       | -             |
+| replacement | string  | no      | -             |
+| is_regex | boolean  | no      | false         |
+| replace_first | boolean  | no      | false         |
+| common-options | string | no       | -             |
+
+### pattern [string]
+
+the regular expression to which this string is to be matched or a common string literal, the default is ""
+
+### replacement [string]
+
+the string to be substituted for each match, the default is ""
+
+### is_regex [boolean]
+
+Whether or not to interpret the pattern as a regex (true) or string literal (false), the dafault is false
+
+### replace_first [boolean]
+
+when replace_first set true , The string constructed by replacing the first matching subsequence by the replacement
+string,

Review Comment:
   Wrong line break



##########
seatunnel-transforms/seatunnel-transforms-flink/seatunnel-transform-flink-replace/src/main/java/org/apache/seatunnel/flink/transform/Replace.java:
##########
@@ -0,0 +1,105 @@
+package org.apache.seatunnel.flink.transform;
+
+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.CheckConfigUtil;
+import org.apache.seatunnel.common.config.CheckResult;
+import org.apache.seatunnel.flink.FlinkEnvironment;
+import org.apache.seatunnel.flink.batch.FlinkBatchTransform;
+import org.apache.seatunnel.flink.stream.FlinkStreamTransform;
+import org.apache.seatunnel.shade.com.typesafe.config.Config;
+
+public class Replace implements FlinkStreamTransform, FlinkBatchTransform {
+
+    private Config config;
+
+    private static final String PATTERN = "pattern";
+    private static final String REPLACEMENT = "replacement";
+    private static final String ISREGEX = "is_regex";
+    private static final String REPLACEFIRST = "replace_first";
+
+    private String pattern = "";
+    private String replacement = "";
+    private Boolean isRegex = false;
+    private Boolean replaceFirst = false;
+
+
+    /**
+     * @param config
+     */
+    @Override
+    public void setConfig(Config config) {
+        this.config = config;
+    }
+
+    /**
+     * @return

Review Comment:
   Useless comment. Just remove it will be better.



##########
docs/en/transform/replace.md:
##########
@@ -67,13 +67,103 @@ Use `Replace` as udf in sql.
   Replace {
     fields = "_replaced"
     pattern = "([^ ]*) ([^ ]*)"
-    replacement = "$2
+    replacement = "$2“
     isRegex = true
     replaceFirst = true
   }
 
-  # Use the split function (confirm that the fake table exists)
+  # Use the replace function (confirm that the fake table exists)
   sql {
     sql = "select * from (select raw_message, replace(raw_message) as info_row from fake) t1"
   }
 ```
+
+## Options(Flink)
+
+| name  | type   | required | default value |
+| ----- | ------ | -------- |---------------|
+| pattern      | string | no       | -             |
+| replacement | string  | no      | -             |
+| is_regex | boolean  | no      | false         |
+| replace_first | boolean  | no      | false         |
+| common-options | string | no       | -             |
+
+### pattern [string]
+
+the regular expression to which this string is to be matched or a common string literal, the default is ""

Review Comment:
   Use uppercase in start.



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