- 创建Hive表
hive> create table test_transform (id string,name string) row format delimited fields terminated by '\t';
OK
Time taken: 1.713 seconds
- 添加测试数据
hive> insert into test_transform(id, name) values(1, "snow"),(2, "feng"),(3,"wind");
- 添加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;
- 运行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
网友评论