基于hive的transform实现自定义分隔符数据导出
2016-07-07 15:00
369 查看
1、建表语句
2、数据准备
3、加载数据
4、编写transform脚本
5、使用 hive -e 'sql' > result.data 进行数据导出
注: using 字句后面执行的python脚本的第一个参数 ^ 为分隔符
导出的结果:
摆渡人影院
create table test(name string, age int, sex string) row format delimited fields terminated by '|' stored as textfile;
2、数据准备
lairin|20|男 peter|19|男 ena|1|女
3、加载数据
load data local inpath '/home/test/test.txt' overwrite into table test;
4、编写transform脚本
''' @author: lairin ''' import sys separator = sys.argv[1] for line in sys.stdin: value = line.split() print separator.join(value)
5、使用 hive -e 'sql' > result.data 进行数据导出
hive -e " add file /home/test/demo.py; select transform(u.name, u.age, u.sex) using 'python demo.py ^' as (all) from (select * from test) as u; " > result.data
注: using 字句后面执行的python脚本的第一个参数 ^ 为分隔符
导出的结果:
lairin^20^男 peter^19^男 ena^1^女
摆渡人影院
相关文章推荐
- 并行编程要素
- Spring事务配置的五种方式(转载)
- Codeforces Round #293 (Div. 2) -- E. Arthur and Questions (思路 + 贪心)
- 简述控件约束的三种形式<二>
- Treap模板 BZOJ 3224: Tyvj 1728 普通平衡树
- android developer tiny share-20160707
- android developer tiny share-20160707
- hdu 5055 Bob and math problem(模拟)
- pthread条件变量condition(配合mutex锁使用),经典,有图
- 内存泄漏之TextLine.recycle
- java中ajax使用--传回一个对象列表
- mysql去除严格模式/插入数据库遇到重复保证唯一
- 事务码VF04开具发票所触发的行为
- 5.6 在线DDL (online DDL)详解
- Java synchronized的原理解析
- oozie安装步骤
- UIView剖析之Draw、Size、Layout方法
- RandomAccessFile
- 高质量技术文章
- android developer tiny share-20160706