hive streaming

1. hive 的streaming 包括:
    map(), reduce(), transform(), 常用的为 transform

2. 恒等变换
select transform(name, salary) using "/bin/cat" as new_name, new_salary from employees where country = 'CHINA';

3. 改变类型
select transform(name, salary) using "/bin/cat" as (new_name string, new_salary int) from employees where country = 'CHINA';

4. 投影变换
select transform(name, salary) using "/bin/cut -f1,2" as (new_name string, new_salary int) from employees where country = 'CHINA';
cut 命令可以任意选取及格字段

5. 操作变换
select transform(name, salary) using "/bin/sed s/John/Tom/" as (new_name string, new_salary int) from employees where country = 'CHINA';

*********************************
6. 调用脚本处理
   1. 创建脚本:test2.py 每行数据 名字改大写, 工资一律加 500
import sys
for line in sys.stdin:
    try:
        line = line.strip()
        content = line.split("\t")
        name = content[0].upper()
        salay = float(content[1].strip()) + 5000
        print "%s\t%f" %(name, salay)
    except Exception, err:
        continue
  2. 添加文件:
  add file /opt/hive/current/testscript/test2.py;
 3. 调用脚本:
 select new_salary from(select transform(name, salary) using "python test2.py" as new_name, new_salary  from employees where country = 'CHINA') as tmp;

多次调用transform可以实现MapReduce的操作
    





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值