Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

UDF question

UDF question

Master Collaborator

if I create a UDF that has nothing to do with any table and just adds two numbers and returns the sum , how do I run it in hive since I understand there is nothing like "select <function-name> from dual; "

3 REPLIES 3

Re: UDF question

Super Guru
@Sami Ahmad

You can do some thing like below..

hive> select sum(1) from (select 1)t;

(or)

hive> select function_name(arg1,arg2);

(or)

hive> with t as (select stack(2,2,1)id) select sum(id) from t;

Re: UDF question

Master Collaborator

I don't have any arguments? I want to add some constant numbers inside the function and display the results .

this is a very valid situation where you don't have any arguments and jjust want to do something inside the function .

Highlighted

Re: UDF question

Master Collaborator

I get this error if I try to run the function with no arguments (since I don't have any)

    > select qp();
FAILED: SemanticException [Error 10014]: Line 1:7 Wrong arguments 'qp': No matching method for class com.demo.queryp with (). Possible choices: _FUNC_(string)
hive>
  
Don't have an account?
Coming from Hortonworks? Activate your account here