Write hive udfs and hiveudfs

Source: Internet
Author: User

Write hive udfs and hiveudfs
1. Configure the environment 1. Introduce the jar package: hive-exec-0.8.0.jar and hadoop-core-0.20.2.jar
2. Compile udf function 1. extends UDF2. redefine UDF evaluate function.

Package com. qunar. hiveudf; import java. text. simpleDateFormat; import java. util. calendar; import java. util. date; import org.apache.hadoop.hive.ql.exe c. UDF; public class IsSundayOrSaturday extends UDF {public Boolean evaluate (String dateString) {try {// convert string to dateString str = dateString. split ("") [0]; SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd"); Date date = sdf. parse (str); // convert date to calendarCalendar calendar = Calendar. getInstance (); calendar. setTime (date); // obtain the week int week of date = calendar. get (Calendar. DAY_OF_WEEK)-1; if (week = 0 | week = 6) {return true;} else {return false ;}} catch (Exception e) {// TODO: handle exceptionreturn false ;}}}

3. Introduce the jar package into the hadoop environment 1. Put the jar package into the physical directory of the lib of hive;
2. Open the hive client and add the jar package add jar/home/hive/lib/HiveUDF. jar.
3. create a temporary file create temporary function IsSundayOrSaturday AS 'com. qunar. hiveudf. issundayorsaturday'

4. Call the function select IsSundayOrSaturday (intime) from user_tag
Note: 1. If the function parameter contains a file, first put the file into the hive running environment add file/home/filename



What jar package is required for hive udf?

See blog.csdn.net/...981115
 
Compiling udf in fluent

It is best to take a look at the examples in the built-in help for learning udfs.

For such boundary conditions, DEFINE_PROFILE is generally used.

Then, the value is determined based on the current flow time.

Time can look at CURRENT_TIME and other macros

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.