Hive (h) of the UDF function

Custom Functions -> UDF

01. Write a function to realize the value of the field attribute case conversion

Add hive file dependencies in pom.xml

<dependency>
  <groupId>org.apache.hive</groupId>
  <artifactId>hive-jdbc</artifactId>
  <version>0.13.1</version>
</dependency> 
   
<dependency>
  <groupId>org.apache.hive</groupId>
  <artifactId>hive-exec</artifactId>
  <version>0.13.1</version>
</dependency>

New ToLowCase class in maven project

package com.darrenzhang.hivedemo.hive_demo;

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

public class ToLowCase extends UDF{
    
    public Text evaluate(Text str){
        if(str == null) return null;
        if(str != null&& str.toString().length() <= 0) return null;
        return new Text(str.toString().toLowerCase());  
    }
    
    public static void main(String[] args){
        System.out.println(new ToLowCase().evaluate(new Text(args[0])));
    }
}

It is labeled jar package


17696673-bf1ed1b512ef3e44.png
Export to jar file
17696673-7f11f35e56b2c472.png
Civilian storage jar package

And then has been next, finish it.
After labeled jar package, jia put this package to a temporary hive list


17696673-23a4199f5a35ab22.png
The jar package posted to the hive a temporary list
17696673-294c2f007e8daa04.png
The jar package posted to the hive a temporary list
17696673-ffa3610936a5e82e.png
Whether the query added successfully

Guess you like

Origin blog.csdn.net/weixin_34380296/article/details/90974982