I used python to do UDF in hive. Is there some method to output array/map such structured data from UDF? I am tried to return a python list in UDF, but it can't be convert to a hive array.
Asked
Active
Viewed 1,282 times
0
-
2There is split function in hive. http://stackoverflow.com/questions/4065999/does-hive-have-a-string-split-function – Ambrish Oct 13 '16 at 02:52
-
`split` function can meet my requirement. Thanks a lot! – Chris Feng Oct 20 '16 at 05:56
1 Answers
0
When you are trying to return a python list in UDF, I suggest that you split the list and process each data step by step. Here is an example.Use 'TRANSFORM' in hive wisely.
#!/usr/bin/env python
#-*- coding:utf-8 -*-
# demo.py
import sys
import datetime
import time
#Turn the timestamp into string
def timestamp_toString(stamp):
return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(stamp))
for line in sys.stdin:
print timestamp_toString(float(line))
in hive console
hive> add file /ebs/hive/test/demo.py;
select TRANSFORM(time) using 'python demo.py' as (time) from (select * from access_fccs where week=41 limit 10) a ;

Jak Liao
- 146
- 1
- 5