Support Questions
Find answers, ask questions, and share your expertise

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.*;
public class queryp extends UDF {
    public Text evaluate(final Text s) throws SQLException {
    //----- below code works fine as a seperate class till EOF ------------
           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 ( ())
            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';
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)

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


Re: UDF question 2

Master Collaborator

can anyone answer this question please?

Don't have an account?