Permalink
Browse files

Add Hive UDF.

  • Loading branch information...
1 parent 935f9cb commit 24eaed7ecd7911fb76f09bf3365f8be2b7deccd8 @tomwhite committed May 19, 2010
View
6 README
@@ -7,8 +7,10 @@ http://oreilly.com/catalog/9780596521998/
This version of the code has been tested with Hadoop Core 0.20.0, Pig 0.2.0,
HBase 0.20.0-dev (compiled from SVN trunk), and ZooKeeper 3.1.1.
-Before running the examples you need to install Hadoop Core, Pig, HBase, and
-ZooKeeper as explained in the book.
+Before running the examples you need to install Hadoop Core, Pig, Hive, HBase,
+and ZooKeeper as explained in the book.
+
+You also need to install Ivy (http://ant.apache.org/ivy/).
Then you can compile the code:
View
@@ -35,6 +35,13 @@
</not>
</condition>
</fail>
+ <fail message="Please set the environment variable HIVE_INSTALL.">
+ <condition>
+ <not>
+ <isset property="env.HIVE_INSTALL"/>
+ </not>
+ </condition>
+ </fail>
<fail message="Please set the environment variable ZOOKEEPER_INSTALL.">
<condition>
<not>
@@ -54,6 +61,10 @@
<fileset dir="${env.PIG_INSTALL}">
<include name="*.jar"/>
<include name="lib/**/*.jar"/>
+ </fileset>
+ <fileset dir="${env.HIVE_INSTALL}">
+ <include name="*.jar"/>
+ <include name="lib/**/*.jar"/>
</fileset>
<fileset dir="${env.ZOOKEEPER_INSTALL}">
<include name="*.jar"/>
@@ -121,6 +132,9 @@
<jar destfile="pig.jar" basedir="${classes.dir}"/>
</target>
+ <target name="hive" depends="compile" description="Creates a jar containing Hiveß UDFs.">
+ <jar destfile="hive.jar" basedir="${classes.dir}"/>
+ </target>
<target name="findbugs" depends="jar">
<taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask"/>
View
@@ -0,0 +1 @@
+X
@@ -0,0 +1,2 @@
+ab
+cde
@@ -0,0 +1,4 @@
+ pomegranate
+banana
+apple
+ lychee
@@ -0,0 +1,5 @@
+A 1950 0 1
+B 1950 22 1
+A 1950 -11 1
+B 1949 111 1
+A 1949 78 1
@@ -0,0 +1,25 @@
+package com.hadoopbook.hive;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.hadoop.hive.ql.exec.UDF;
+import org.apache.hadoop.io.Text;
+
+public class Strip extends UDF {
+ private Text result = new Text();
+
+ public Text evaluate(Text str) {
+ if (str == null) {
+ return null;
+ }
+ result.set(StringUtils.strip(str.toString()));
+ return result;
+ }
+
+ public Text evaluate(Text str, String stripChars) {
+ if (str == null) {
+ return null;
+ }
+ result.set(StringUtils.strip(str.toString(), stripChars));
+ return result;
+ }
+}

0 comments on commit 24eaed7

Please sign in to comment.