hive-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Raj Hadoop <>
Subject Find a date that is in the range of any array dates in Hive
Date Sat, 01 Feb 2014 05:19:53 GMT

I have the following requirement from a Hive table below.


The data above says that

From 10 Aug to 11 Aug the rate is 10.
From 12 Aug to 19 Aug the rate is 15.

From 20-Aug to till date the rate is 20.

Note : The order is maintained in 'ActivityDates' and 'Rates'.

From the above table , I need to find the rate on say a given date 15-Aug-13. In the above
case , the rate for 15-Aug-13 is 15.

How should I get this result in Hive.

I was reading about a Generic UDF and was thinking to write one like this.
The Generic UDF takes two inputs (input date , array of input dates ) . the output should
be (an int )to return the element number in the array. 

In the above case 
Generic UDF(15-Aug-13,10-Aug-13,12-Aug-13,20-Aug-13) should return the 2nd element in array
- 2.

Please advise if there is an alternative solution or if the above solution works. I have never
written a UDF or Generic UDF and would need some help from the forum members. Please advise.

View raw message