如何在配置单元python udf中输出数组

1tuwyuhd  于 2021-06-28  发布在  Hive
关注(0)|答案(1)|浏览(293)

我用python在hive中做udf。有什么方法可以从udf输出数组/Map这样的结构化数据吗?我试图在udf中返回python列表,但无法将其转换为配置单元数组。

bejyjqdl

bejyjqdl1#

当您试图在udf中返回python列表时,我建议您拆分列表并逐步处理每个数据。下面是一个例子。在Hive中明智地使用“transform”。


# !/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))

在配置单元控制台中

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 ;

相关问题