hive-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Raihan Jamal <>
Subject Custom UserDefinedFunction in Hive
Date Tue, 07 Aug 2012 01:39:48 GMT

I created the below UserDefinedFunction to get the yesterday's day in the
format I wanted as I will be passing the format into this below method from
the query.

*public final class YesterdayDate extends UDF {*

* *

*                public String evaluate(final String format) { *

*                                DateFormat dateFormat = new
SimpleDateFormat(format); *

*                                Calendar cal = Calendar.getInstance();*

*                                cal.add(Calendar.DATE, -1);     *

*                                return
dateFormat.format(cal.getTime()).toString(); *

*                } *


So whenever I try to run the query like below by adding the jar to
classpath and creating the temporary function yesterdaydate, I always get
zero result back-

hive> create temporary function *yesterdaydate* as


Time taken: 0.512 seconds

Below is the query I am running-

*hive> SELECT * FROM REALTIME where dt= yesterdaydate('yyyyMMdd') LIMIT 10;*


* *

And I always get zero result back but the data is there in that table for
Aug 5th.**

What wrong I am doing? Any suggestions will be appreciated.

NOTE:- As I am working with Hive 0.6 so it doesn’t support variable
substitution thing, so I cannot use hiveconf here and the above table has
been partitioned on dt(date) column.**

View raw message