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/05/09 03:21:57 UTC

[GitHub] [incubator-seatunnel] ruanwenjun commented on a diff in pull request #1826: [Feature][flink-transform] add transform for register user define function

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


##########
seatunnel-transforms/seatunnel-transforms-flink/seatunnel-transform-flink-udf/src/main/java/org/apache/seatunnel/flink/transform/Udf.java:
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.transform;
+
+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;
+
+import org.apache.flink.api.java.DataSet;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.table.api.TableEnvironment;
+import org.apache.flink.table.functions.UserDefinedFunction;
+import org.apache.flink.types.Row;
+import org.apache.flink.util.Preconditions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+
+public class Udf implements FlinkStreamTransform, FlinkBatchTransform {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(Udf.class);
+
+    private static final String CLASS_NAMES = "class_names";
+    private static final String FUNCTION_NAMES = "function_names";
+    private Config config;
+    private List<String> className;
+    private List<String> functionName;

Review Comment:
   ```suggestion
       private List<String> classNames;
       private List<String> functionNames;
   ```



##########
docs/en/transform/udf.md:
##########
@@ -0,0 +1,47 @@
+# udf
+
+## Description
+
+Supports using UDF in data integration by the transform.
+Need to specify the function name and class name and put UDF jars in Flink's classpath or import them via 'Flink run -c xxx.jar'
+
+:::tip
+
+This transform **ONLY** supported by Flink.
+
+:::
+
+## Options
+
+| name           | type   | required | default value |
+| -------------- | ------ | -------- | ------------- |
+| class_names    | string | yes      | -             |
+| function_names | string | yes      | -             |
+
+### class_names [string-list]
+
+The names of UDF classes. 
+
+### function_names [string]
+
+The names of UDF which you want to use as.
+
+### common options [string]
+
+Transform plugin common parameters, please refer to [Transform Plugin](common-options.mdx) for details
+
+## Examples
+
+Use `udf` in sql.
+
+```bash
+  udf {
+    class_names = ["com.example.udf.flink.TestUDF"]
+    function_names = ["test_1"]
+  }

Review Comment:
   It's better to change to below format, this is easier to see the relation.
   ```
   udf {
       test_1 = "com.example.udf.flink.TestUDF"
       test_2 = "xx"
       ...
   }
   ```
   



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