Database Reference
In-Depth Information
I enter the sbt command compile at the sbt> prompt to compile the code, followed by the package command to
package the code into a jar file. Finally, the sbt exit command causes the sbt build session to finish:
> compile
[success] Total time: 3 s, completed Sep 16, 2014 7:50:39 PM
> package
[success] Total time: 1 s, completed Sep 16, 2014 7:50:59 PM
> exit
The jar library containing the new Hive UDF code is contained in the target/scala-{version} directory. It is called
dateconv_2.10-0.1.jar, as the Linux long listing shows:
[hadoop@hc2nn udf]$ ls -l target/scala-2.10/dateconv_2.10-0.1.jar
-rw-rw-r-- 1 hadoop hadoop 1579 Sep 16 19:36 target/scala-2.10/dateconv_2.10-0.1.jar
I can use the Java jar command to show the contents of the library. For example, the following command passes
the options vtf to the jar command and takes the library as a parameter. The v option means verbose, the t option
means show the table of contents, and the f option allows the jar file name to be specified. The output shows the
structure of the jar file and shows that it contains the compiled class file DateConv.class:
[hadoop@hc1nn udf]$ jar vtf target/scala-2.10/dateconv_2.10-0.1.jar
288 Tue Sep 16 19:36:32 NZST 2014 META-INF/MANIFEST.MF
0 Tue Sep 16 19:36:32 NZST 2014 nz/
0 Tue Sep 16 19:36:32 NZST 2014 nz/co/
0 Tue Sep 16 19:36:32 NZST 2014 nz/co/semtechsolutions/
0 Tue Sep 16 19:36:32 NZST 2014 nz/co/semtechsolutions/hive/
0 Tue Sep 16 19:36:32 NZST 2014 nz/co/semtechsolutions/hive/udf/
899 Tue Sep 16 19:36:24 NZST 2014 nz/co/semtechsolutions/hive/udf/DateConv.class
Now that the Hive UDF jar file has been created, I can add it to a Hive shell session so that I can use the new
Hive UDF function in Hive Query language (Hive QL). The following add jar command in my Apache Hive session
registers the jar file with the session:
[hadoop@hc1nn udf]$ hive
hive> add jar /home/hadoop/hive/udf/target/scala-2.10/dateconv_2.10-0.1.jar;
Added /home/hadoop/hive/udf/target/scala-2.10/dateconv_2.10-0.1.jar to class path
Added resource: /home/hadoop/hive/udf/target/scala-2.10/dateconv_2.10-0.1.jar
The full name of the DateConv UDF function is co.nz.semtechsolutions.hive.udf.DateConv. This is a long name
based on the package name. It would be much more convenient and quicker to just refer to the function as DateConv.
That is what the next command does: it registers the temporary function name DateConv based on the long name:
hive> create temporary function DateConv as 'nz.co.semtechsolutions.hive.udf.DateConv';
OK
Time taken: 0.02 seconds
 
Search WWH ::




Custom Search