0

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.

Chris Feng
  • 189
  • 5
  • 19

1 Answers1

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