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