Hive的transform使用

2019-04-13  本文已影响0人  峰峰仔
  1. 创建Hive表
hive> create table test_transform (id string,name string) row format delimited fields terminated by '\t';
OK
Time taken: 1.713 seconds
  1. 添加测试数据
hive>  insert into test_transform(id, name) values(1, "snow"),(2, "feng"),(3,"wind");
  1. 添加transform的python脚本
# test_transform.py 
import sys
for line in sys.stdin:
    (id, name) = line.strip('\n').split('\t')
    sys.stdout.write(id + '\t' + 'hello' + name + '\t' + name + '\n')

4.在Hive中添加python文件

add file /opt/feng/hive/test_transform.py;
  1. 运行Hive查询
hive>  select transform(id, name) using 'python test_transform.py' as (id, appendname,name) from test_transform;
#输出结果
1   hellosnow   snow
2   hellofeng   feng
3   hellowind   wind
上一篇下一篇

猜你喜欢

热点阅读