You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hive.apache.org by Kumar V <ku...@yahoo.com> on 2013/07/16 19:11:56 UTC

How to read UDF returning a list

Hi,
    I have a UDF that returns a list and another one that returns a list of lists.  I am not sure how to read the results back as lists in JDBC/hiveserver1.
All I can do is

while (rset.next()) {
  String fld = rset.getString(2);
}

This returns the field as a string like : 

"[[John,Jack,Jill],[Smith,Hill,Smith],[25,26,27],[NULL],[1,4,5]]"


Is there a way to read the data as a list instead of a String ? 
I tried rset.getArray(2).  But got an error "unsupported function".  I am using hive 0.9.  

Or, is there a way to convert this to a list in Java without parsing this string ?  I saw some Groovy code online while seem to do something like that.  But would need this in Java/Python.
Would be helpful if someone has any ideas/pointers.

Thanks,
Murali.

Re: how to know a hive query failed

Posted by Brad Ruderman <br...@radiumone.com>.
Sry - sent email prematurely.

You need to poll and read the stderr and stdout for text messages alerting
there is an error. In python this is what I use:

def execute_hive_query(query, hive_exception = None):
return_code = None
cmd = ["hive","-S", "-e", query]
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
while return_code is None:
time.sleep(10)
return_code = proc.poll()
out = proc.stdout.read()
error = proc.stderr.read()
handle_hive_exception(out,error,hive_exception)

def handle_hive_exception(stdout,stderr,hive_exception = None):
if hive_exception is not None:
hive_exception(stdout,stderr)
else:
if stderr != '':
stderr = stderr.lower()
if stderr.find('error') > -1 or stderr.find('failed') >-1:
if stderr.find('log4j:error could not find value for key
log4j.appender.fa') == -1:
raise Exception(stderr)
return


On Tue, Jul 16, 2013 at 8:03 PM, Brad Ruderman <br...@radiumone.com>wrote:

> You need to stream and read the stderr and stdout for text messages
> alerting there is an error. In python this is what I use:
>
>
> On Tue, Jul 16, 2013 at 7:42 PM, kentkong_work <ke...@163.com>wrote:
>
>> **
>> hi,
>>     I use a shell script to run hive query in background, like this
>>     hive -e "select uname, age from usertable" >> result.csv &
>>
>>     sometimes, the hive query failed, but I can't find.
>>     only thing I can do is waiting for long time, 5 or 6 hours, if I
>> still can't see the result.csv, I know the query failed.
>>     is there some way to let hive tell me the query failed?
>>
>>
>> Kent
>>
>
>

Re: how to know a hive query failed

Posted by Brad Ruderman <br...@radiumone.com>.
You need to stream and read the stderr and stdout for text messages
alerting there is an error. In python this is what I use:


On Tue, Jul 16, 2013 at 7:42 PM, kentkong_work <ke...@163.com>wrote:

> **
> hi,
>     I use a shell script to run hive query in background, like this
>     hive -e "select uname, age from usertable" >> result.csv &
>
>     sometimes, the hive query failed, but I can't find.
>     only thing I can do is waiting for long time, 5 or 6 hours, if I still
> can't see the result.csv, I know the query failed.
>     is there some way to let hive tell me the query failed?
>
>
> Kent
>

how to know a hive query failed

Posted by kentkong_work <ke...@163.com>.
hi,
    I use a shell script to run hive query in background, like this
    hive -e "select uname, age from usertable" >> result.csv &

    sometimes, the hive query failed, but I can't find.
    only thing I can do is waiting for long time, 5 or 6 hours, if I still can't see the result.csv, I know the query failed.
    is there some way to let hive tell me the query failed?


Kent