hive-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Edward Capriolo <>
Subject Classpath question with testcase and UDF
Date Tue, 14 Jul 2009 14:57:47 GMT
Hey all,

I am working on a UDF that can be used with prepared statements ad a
technique to go from Hive->SQL. The usage would be something like
from src SELECT
dboutput("jdbc:mysql://localhost:20","user","pass","INSERT INTO A
(col1,col2) VALUES (?,?)", key,value)

public class GenericUDFDBOutput extends GenericUDF {
  private static Log LOG =

  ObjectInspector[] argumentOIs;
  GenericUDFUtils.ReturnObjectInspectorResolver returnOIResolver;
  Connection connection = null;
  private String url;
  private String user;
  private String pass;
  private IntWritable result = new IntWritable(-1);

  public ObjectInspector initialize(ObjectInspector[] arguments)
      throws UDFArgumentTypeException {

    this.argumentOIs = arguments;

public Object evaluate(DeferredObject[] arguments) throws HiveException {

    System.err.println("we are here");
    url = arguments[0].get().toString()+";create=true";
    url = "jdbc:derby:;databaseName=test_dboutput_db;create=true";
    user = arguments[1].get().toString();
    pass = arguments[2].get().toString();
    try {
      try {
      } catch (InstantiationException e) {
      } catch (IllegalAccessException e) {
      } catch (ClassNotFoundException e) {
      connection = DriverManager.getConnection(url, user, pass);
      PreparedStatement ps = connection.prepareStatement(arguments[3].get()
      for (int i = 4; i < arguments.length; ++i) {
        PrimitiveObjectInspector poi = ((PrimitiveObjectInspector)
        ps.setObject(i - 3, poi.getPrimitiveJavaObject(arguments[i]));

--end snip--

In my test case I am attempting to use the derby embedded driver since
I figured it would probably already be in the classpath.
org.apache.derby.jdbc.EmbeddedDriver. It is not. I took several stabs
and adding it to the ant files but I get the feeling that the
TestCliDriver is not inheriting those paths. Any suggestions?


View raw message