Database Reference
In-Depth Information
09 resolvers += "CDH4" at " https://repository.cloudera.com/artifactory/cloudera-repos/ "
10
11 libraryDependencies += "org.apache.hadoop" % "hadoop-core" % "0.20.2" % "provided"
12
13 libraryDependencies += "org.apache.hive" % "hive-exec" % "0.10.0" % "provided"
Each line of this file is separated from the next with a blank line. Notice that the organization name is the reverse
of my company's domain name and the Java package name to which the UDF will belong also uses the same naming
standard. The version of Scala used is defined, as are library dependencies for Hadoop and Hive.
Having created the build sbt file, I now need a directory structure to contain the UDF code. It must match the
structure of the UDF package name, starting with the directories src/main/java. The first line of the Java UDF file
contains a package name:
package nz.co.semtechsolutions.hive.udf;
And so a directory structure must be created to match this, using the mkdir command. Using the -p option causes
all subdirectories in the path to be created at the same time. I then move down to the lowest point in the directory
structure that I have created, the udf directory:
[hadoop@hc2nn udf]$ mkdir -p src/main/java/nz/co/semtechsolutions/hive/udf
[hadoop@hc2nn udf]$ cd src/main/java/nz/co/semtechsolutions/hive/udf
I have created a UDF Java file called DateConv.java that contains the Java code for the UDF function. The
following Linux cat command shows the contents of the Java:
[hadoop@hc2nn udf]$ cat DateConv.java
1 package nz.co.semtechsolutions.hive.udf;
2
3 import org.apache.hadoop.hive.ql.exec.UDF;
4 import org.apache.hadoop.io.Text;
5 import java.text.SimpleDateFormat;
6 import java.util.Date;
7
8 class DateConv extends UDF
9 {
10
11 public Text evaluate(Text s)
12 {
13
14 Text to_value = new Text("");
15
16 if (s != null)
17 {
18 try
19 {
20
21 SimpleDateFormat incommingDateFormat = new SimpleDateFormat
("dd/MM/yyyy");
22 SimpleDateFormat convertedDateFormat = new SimpleDateFormat
("yyyy-MM-dd");
23
 
Search WWH ::




Custom Search