Support Questions

Find answers, ask questions, and share your expertise

How can I create a udf in impala

avatar
Contributor

Hi 

I perform many queries with the below statement and I thought that instead of writing over and over again the same cases if it is possible to create a UDF in impala to handle this like sql server.

 

 

 (select people, sum(new_money) as new_money from 
    (
    select people,
    case
    when pocket_01 = 'leather' then sum(nvl(money,0.0))/100 else 0.0
    end +
    case
    when pocket_02 = 'leather' then sum(nvl(money,0.0))/100 else 0.0
    end +
    case
    when pocket_03 = 'leather' then sum(nvl(money,0.0))/100 else 0.0
    end +
    case
    when pocket_04 = 'leather' then sum(nvl(money,0.0))/100 else 0.0
    end +
    case
    when pocket_05 = 'leather' then sum(nvl(money,0.0))/100 else 0.0
    end +
    case
    when pocket_06 = 'leather' then sum(nvl(money,0.0))/100 else 0.0
    end +
    case
    when pocket_07 = 'leather' then sum(nvl(money,0.0))/100 else 0.0
    end ) as new_money from bank where date = '20201010'
    ) target 
    group by people ) as target

 

 

Is this possible? I have searched everywhere to find a simple example of how to create a udf but I only found this in the cloudera documentation which didnt help me a lot.

1 ACCEPTED SOLUTION
3 REPLIES 3

avatar
Expert Contributor

The documentation is here: 

https://docs.cloudera.com/documentation/enterprise/6/6.3/topics/impala_udf.html

 

You can either implement Impala UDF using C++ or Hive UDF using Java

avatar
Contributor

Thanks for your quick response. Although I wrote that I have read clouderas documentation about UDFS and it didnt help me a lot. Is there any source with examples?