【问题标题】:How to output array in hive python UDF如何在 hive python UDF 中输出数组
【发布时间】:2016-10-13 02:03:37
【问题描述】:

我用python在hive中做UDF。是否有一些方法可以从 UDF 输出数组/映射此类结构化数据? 我试图在 UDF 中返回一个 python 列表,但它无法转换为配置单元数组。

【问题讨论】:

标签: python hive udf


【解决方案1】:

当您尝试在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 ;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-12
    • 1970-01-01
    • 2014-07-22
    相关资源
    最近更新 更多