Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to add Custom function in Hive

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to add custom functions in Hive". The explanation in this article is simple and clear and easy to learn and understand. Please follow the editor's train of thought to study and learn "how to add custom functions in Hive".

Environment introduction: CentOS7+hive-1.1.0-cdh6.7.0+Maven3.3.9

1. Download the source code

Hive-1.1.0-cdh6.7.0-src.tar.gz

Http://archive.cloudera.com/cdh6/cdh/5/hive-1.1.0-cdh6.7.0-src.tar.gz

2. Decompress the source code

Tar-zxvf hive-1.1.0-cdh6.7.0-src.tar.gz-C / home/hadoop/

Cd / home/hadoop/hive-1.1.0-cdh6.7.0

3. Add HelloUDF.java file to HIVE source code

Cp HelloUDF.java / home/hadoop/hive-1.1.0-cdh6.7.0/ql/src/java/org/apache/hadoop/hive/ql/udf/

4. Modify FunctionRegistry.java file

Cd / home/hadoop/hive-1.1.0-cdh6.7.0/ql/src/java/org/apache/hadoop/hive/ql/exec/

Vi FunctionRegistry.java

Add: import org.apache.hadoop.hive.ql.udf.HelloUDF to import

Add: system.registerUDF ("helloUDF", HelloUDF.class, false) to the static block of the file header

5. Recompile

Cd / home/hadoop/hive-1.1.0-cdh6.7.0

Mvn clean package-DskipTests-Phadoop-2-Pdist

6. The compilation results are all: BUILD SUCCESS

Directory where the file is located: / home/hadoop/hive-1.1.0-cdh6.7.0/hive-1.1.0-cdh6.7.0/packaging/target

7. Configure the hive environment

When you configure the hive environment, you can reconfigure or copy the compiled package with the UDF function to the old hive environment:

7.1. All configuration: refer to the previous documentation.

Copy the compiled package with UDF function to the old hive environment

Go to / home/hadoop/hive-1.1.0-cdh6.7.0/packaging/target/apache-hive-1.1.0-cdh6.7.0-bin/apache-hive-1.1.0-cdh6.7.0-bin/lib, find the hive-exec-1.1.0-cdh6.7.0.jar package, and replace the control package in the old environment

Command:

Cd / home/hadoop/app/hive-1.1.0-cdh6.7.0/lib

Mv hive-exec-1.1.0-cdh6.7.0.jar hive-exec-1.1.0-cdh6.7.0.jar_bak

Cd / home/hadoop/hive-1.1.0-cdh6.7.0/packaging/target/apache-hive-1.1.0-cdh6.7.0-bin/apache-hive-1.1.0-cdh6.7.0-bin/lib

Cp hive-exec-1.1.0-cdh6.7.0.jar / home/hadoop/app/hive-1.1.0-cdh6.7.0/lib

Finally start hive

8. Test:

Hive

Hive (default) > show functions;-- helloudf can be found

Thank you for reading, the above is the content of "how to add custom functions in Hive". After the study of this article, I believe you have a deeper understanding of how to add custom functions in Hive, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 280

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report