Hive不同文件的读取与序列化
2015-07-16 15:36
501 查看
Hive不同文件的读取对比
stored as textfile
直接查看hdfshadoop fs -text
hive> create table test_txt(name string,val string) stored as textfile;
stored as sequencefile
hadoop fs -texthive> create table test_seq(name string,val string) stored as sequencefile;
stored as rcfile
hive –service rcfilecat pathhive> create table test_rc(name string,val string) stored as rcfile;
stored as inputformat ‘class’自定义
outformat ‘class’基本步骤:
1、编写自定义类
2、打成jar包
3、添加jar文件,
hive> add jar /***/***/***.jar(当前生效)或者拷贝到hive安装目录的lib目录下,重启客户端(永久生效)。
4、创建表,指定自定义的类
Hive使用SerDe
SerDe是”Serializer”和”Deserializer”的简写。Hive使用SerDe(和FileFormat)来读、写表的行。
读写数据的顺序如下:
HDFS文件-->InputFileFormat--><key,value>-->Deserializer-->Row对象 Row对象-->Serializer--><key,value>-->OutputFileFormat-->HDFS文件
Hive自带的序列化与反序列化
当然我们也可以自己实现自定义的序列化与反序列化
Hive自定义序列化与反序列化步骤
1、实现接口SerDe或者继承AbstractSerDe抽象类
2、重写里面的方法
Demo:
创建表drop table apachelog; create table apachelog( host string, identity string, user string, time string, request string, status string, size string, referer string, agent string ) row format serde 'org.apache.hadoop.hive.contrib.serde2.RegexSerDe' with serdeproperties( "input.regex" = "([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) ([0-9]*) ([0-9]*) ([^ ]*) ([^ ]*)" )stored as textfile;
cat serdedata 110.52.250.126 test user - GET 200 1292 refer agent 27.19.74.143 test root - GET 200 680 refer agent
加载数据
load data local inpath '/liguodong/hivedata/serdedata' overwrite into table apachelog;
查看内容
select * from apachelog; select host from apachelog;
相关文章推荐
- collectd配置
- 设计模式--原型模式
- java 重定向和转发的区别
- HTTP协议的C/S模式的信息交换过程
- linux内核list模块的使用
- paint 画笔的一些属性
- 关于VS2010出现“此方法显式使用的 CAS 策略已被 .NET Framework 弃用... ...请使用 NetFx40_LegacySecurityPolicy 配置开关”解决办法
- Swift中NSDictionaryOfVariableBindings的替代方案
- FORM表单中onclick()、submit()与onsubmit()的问题
- Spark1.4从HDFS读取文件运行Java语言WordCounts并将结果保存至HDFS
- PAT (Basic Level) Practise (中文)1036. 跟奥巴马一起编程(15)
- 虚函数—类的多态性
- 如何将Eclipse中的项目迁移到Android Studio 中
- Spark1.4从HDFS读取文件运行Java语言WordCounts并将结果保存至HDFS
- Maven Dependency Scope
- linux 关闭停用ipv6方法
- Java基础--多线程--售票
- 正则表达式的使用
- Android学习之SQLite学习
- iOS深入学习(Block全面分析)