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 2

UDF question 2

Master Collaborator

for hive UDFs do you have to select from a table or can they be written to do things like just adding two numbers and displaying the result? if yes then how will I call them from hive?

e.g below is the code that connects to the oracle database and queries the data dic. it runs fine as a separate class and I am trying to use it as a UDF in hive.

when I run it I get this error

package com.demo;
import org.apache.hadoop.hive.ql.exec.UDF;
import java.sql.*;
import oracle.jdbc.*;
import org.apache.hadoop.io.Text;
public class queryp extends UDF {
    public Text evaluate(final Text s) throws SQLException {
    
    //----- below code works fine as a seperate class till EOF ------------
           System.setProperty("oracle.net.tns_admin","/u01/oracle/admin");
           System.setProperty("oracle.net.wallet_location","/u01/oracle/admin");
           String url = "jdbc:oracle:thin:/@secure";
          DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
          Connection conn = DriverManager.getConnection(url);
          Statement stmt = conn.createStatement ();
          ResultSet rset = stmt.executeQuery ("select HOST_NAME,INSTANCE_NAME FROM V$INSTANCE");
          while (rset.next ())
            System.out.println (rset.getString (1));
    // -------------------------- EOF ------------------------------
          return null;
        }
}
    > add jar /tmp/hive-udf-0.1-SNAPSHOT.jar;
Added [/tmp/hive-udf-0.1-SNAPSHOT.jar] to class path
Added resources: [/tmp/hive-udf-0.1-SNAPSHOT.jar]
hive> create temporary function qp as 'com.demo.queryp';
OK
Time taken: 0.356 seconds
hive> select qp();
FAILED: SemanticException [Error 10014]: Line 1:7 Wrong arguments 'qp': No matching method for class com.fdot.demo.querypatron with (). Possible choices: _FUNC_(string)
hive>

NOTE: I do not have any arguments . this class queries the external database n returns results.

1 REPLY 1
Highlighted

Re: UDF question 2

Master Collaborator

can anyone answer this question please?

Don't have an account?
Coming from Hortonworks? Activate your account here