美文网首页
UDF 函数

UDF 函数

作者: 我的小猫不见了 | 来源:发表于2020-04-30 03:33 被阅读0次

1. 用idea创建maven工程 , 用来编辑UDF函数.

POM文件如下 , 我的hadoop是 2.6.0 cdh版本号是 cdh5.15.0

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.fanling</groupId>
    <artifactId>hivedemo</artifactId>
    <packaging>jar</packaging>
    <version>1.0.0</version>

    <repositories>
        <repository>
            <id>cloudera</id>
            <name>cloudera-repository</name>
            <url>https://repository.cloudera.com/artifactory/cloudera-repos/</url>
            <layout>default</layout>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-client</artifactId>
            <version>2.6.0-cdh5.15.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.hive</groupId>
            <artifactId>hive-exec</artifactId>
            <version>1.1.0-cdh5.15.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.hive</groupId>
            <artifactId>hive-jdbc</artifactId>
            <version>1.1.0-cdh5.15.0</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.40</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

2.然后是创建UDF类,继承UDF

image.png
package com.UDF;

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

public class MyUDF extends UDF {
    public Text evaluate(Text field) {
        if (field == null) {
            return null;
        } else {
            return new Text(field.toString().toLowerCase());
        }
    }
    public static void main(String[] args) {
        System.out.println(new MyUDF().evaluate(new Text("FANTASY")));
    }
}

然后把文件打jar包 ,

3.把文件复制到Linux , 进入hive控制台

image.png

一是注册jar包 , 二是指定class文件注册为名mylowwer的函数
调用就是:


image.png

可以看到函数可以将字段全部小写.

相关文章

  • Hive 自定义函数 UDF

    Hive 自定义函数 UDF UDF:用户定义(普通)函数,只对单行数值产生作用; UDF只能实现一进一出的操作。

  • Hive函数

    自定义函数 自定义函数包括三种:UDF、UDAF、UDTF。 UDF(User-Defined-Function)...

  • Flink1.9 UDF使用教程

    UDF是什么? UDF是用户自定义函数(User Define Function)的缩写,从定义可以看出UDF是一...

  • Hive的UDF编程-GenericUDF编程

    UDF简介 在Hive中,用户可以自定义一些函数,用于扩展HiveQL的功能,而这类函数叫做UDF(用户自定义函数...

  • UDF 函数

    1. 用idea创建maven工程 , 用来编辑UDF函数. POM文件如下 , 我的hadoop是 2.6.0 ...

  • 【Hive】Hive UDF

    [TOC] 一、UDF 介绍 UDF(User-Defined Functions)即是用户自定义的hive函数。...

  • Hive- UDF&GenericUDF

    hive udf简介 在Hive中,用户可以自定义一些函数,用于扩展HiveQL的功能,而这类函数叫做UDF(用户...

  • Hive 用户自定义函数 UDF,UDAF

    Hive有UDF:(普通)UDF,用户自定义聚合函数(UDAF)以及用户自定义生表函数(UDTF)。它们所接受的输...

  • spark-sql thriftserver 方式使用hive

    1、在hive中注册udf函数 add jar hdfs://hdp-hdfs01/apps/udf.jar; -...

  • hive-1.2.1自定义函数UDF、UDTF

    Hive中有三种UDF: 1、用户定义函数(user-defined function)UDF; 2、用户定义聚集...

网友评论

      本文标题:UDF 函数

      本文链接:https://www.haomeiwen.com/subject/lurawhtx.html