MAPREDUCE服务 MRS-配置FlinkServer作业中使用UDF:UDF java代码及SQL样例

时间:2024-10-22 09:17:13

UDF java代码及SQL样例

  • UDF java使用样例
    package com.xxx.udf;
    import org.apache.flink.table.functions.ScalarFunction;
    public class UdfClass_UDF extends ScalarFunction {
        public int eval(String s) {
            return s.length();
        }
    }
  • UDF SQL使用样例
    CREATE TEMPORARY FUNCTION udf as 'com.xxx.udf.UdfClass_UDF';
    CREATE TABLE udfSource (a VARCHAR) WITH ('connector' = 'datagen','rows-per-second'='1');
    CREATE TABLE udfSink (a VARCHAR,b int) WITH ('connector' = 'print');
    INSERT INTO
      udfSink
    SELECT
      a,
      udf(a)
    FROM
      udfSource;
support.huaweicloud.com/cmpntguide-mrs/mrs_01_24211.html