回覆列表
  • 1 # M宋晨陽M

    最近感受了hive的udf函式的強大威力了,不僅可以使用很多已經有的udf函式,還可以自己定義符合業務場景的udf函式,下面就說一下如何寫udf/udaf/udtf函式,算是一個入門介紹吧。

    First, you need to create a new class that extends UDF, with one or more methods named evaluate.

    package com.example.hive.udf;

    import org.apache.hadoop.hive.ql.exec.UDF;

    import org.apache.hadoop.io.Text;

    public final class Lower extends UDF {

    public Text evaluate(final Text s) {

    if (s == null) { return null; }

    return new Text(s.toString().toLowerCase());

    }

    }

    After compiling your code to a jar, you need to add this to the hive classpath.

    add jar my_jar.jar;

    Once hive is started up with your jars in the classpath, the final step is to register your function

    create temporary function my_lower as "com.example.hive.udf.Lower";

  • 中秋節和大豐收的關聯?
  • 如何在mac版本的python裡安裝pip?