hive streaming
2016-05-10 20:40
281 查看
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的操作
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的操作
相关文章推荐
- spoj 26130 Binary numbers
- 剑指offer之面试题4替换空格
- Android ImageLoader用法总结
- 第一个Node.js应用
- struts2的action里面name属性命名为account就会无法找到结果页面(其他名称正常),欢迎发言,求解释?
- 程序从命令行接收多个数字,求和之后输出结果。
- Jython:Java如何传值给Python
- LintCode 81 -- 数据流中位数
- 某里巴巴Java工程师常规面试题以及解答
- Hdu 4578 Transformation(区间加值,区间乘值,区间赋值,查询区间的p次方)
- 利用孪生素数判断素数
- HDU 5317 RGCDQ
- 程序从命令行接收多个数字,求和之后输出结果。
- HDU 5546 Ancient Go (ccpc2015南阳G)
- setcookie 设置无效
- std::list::back带来的坑
- 返回值的问题(oj2136)
- null==0问题
- 团队项目——地铁信息查询数据结构设计
- 第十一周项目2 继承之职员信息薪水类