Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can we test HIVE functions without referencing a table

I wanted to understand the UDF WeekOfYear and how it starts the first week. I had to artifically hit a table and run the query . I wanted to not hit the table and compute the values. Secondly can I look at the UDF source code?

SELECT weekofyear
('12-31-2013')
from a;
like image 351
vkaul11 Avatar asked Jan 08 '14 23:01

vkaul11


2 Answers

You do not need table to test UDF since Hive 0.13.0.

See this Jira: HIVE-178 SELECT without FROM should assume a one-row table with no columns

Test:

hive> SELECT weekofyear('2013-12-31');

Result:

1

The source code (master branch) is here: UDFWeekOfYear.java

like image 188
leftjoin Avatar answered Oct 18 '22 05:10

leftjoin


If you are Java developer, you can write Junit Test cases and test the UDFs..

you can search the source code of all hive built in functions in grepcode.

http://grepcode.com/file/repo1.maven.org/maven2/org.apache.hive/hive-exec/1.0.0/org/apache/hadoop/hive/ql/udf/UDFWeekOfYear.java

like image 42
gopikrishna_BD Avatar answered Oct 18 '22 03:10

gopikrishna_BD