hive mysql数据类型转换函数,将Hive数据库存储格式转换为orc

Hive的存储格式

textfile

hive的默认存储格式

存储方式:行存储

磁盘开销大 数据解析开销大

压缩的text文件 hive无法进行合并和拆分

SequenceFile

二进制文件,以的形式序列化到文件中

存储方式:行存储

可分割 压缩

一般选择block压缩

优势是文件和hadoop api中的mapfile是相互兼容的

rcfile

存储方式:数据按行分块 每块按照列存储

压缩快 快速列存取

读记录尽量涉及到的block最少

读取需要的列只需要读取每个row group 的头部定义。

读取全量数据的操作 性能可能比sequencefile没有明显的优势

orc

存储方式:数据按行分块 每块按照列存储

压缩快 快速列存取

效率比rcfile高,是rcfile的改良版本

自定义格式

用户可以通过实现inputformat和 outputformat来自定义输入输出格式

Hive导入数据的几种方式

从本地文件系统中导入

load data local inpath 'customer .data' into table customer;

从HDFS上导入

load data inpath '/hive/customer .data' into table customer;

从别的表中查询出相应的数据导入

insert into table customer select * from customer_tmp;

将存储格式转换为orc

因为textfile类型的数据不能直接保存到orc类型的表中,根据上面的几种导入数据的方式我们做一下转换就可以了,先导入到一个textfile类型的表中然后在通过查询导入到另外一个表就可以了

示例:

use tpcds_orc;

drop table if exists customer_tmp;

create table customer_tmp

(

c_customer_sk int ,

c_customer_id char(16) ,

c_current_cdemo_sk int ,

c_current_hdemo_sk int ,

c_current_addr_sk int ,

c_first_shipto_date_sk int ,

c_first_sales_date_sk int ,

c_salutation char(10) ,

c_first_name char(20) ,

c_last_name char(30) ,

c_preferred_cust_flag char(1) ,

c_birth_day int ,

c_birth_month int ,

c_birth_year int ,

c_birth_country varchar(20) ,

c_login char(13) ,

c_email_address char(50) ,

c_last_review_date char(10)

)

row format delimited fields terminated by '|';

load data local inpath '/data1/tpcds/data100/customer.dat' into table customer_tmp;

drop table if exists customer;

create table customer

(

c_customer_sk int ,

c_customer_id char(16) ,

c_current_cdemo_sk int ,

c_current_hdemo_sk int ,

c_current_addr_sk int ,

c_first_shipto_date_sk int ,

c_first_sales_date_sk int ,

c_salutation char(10) ,

c_first_name char(20) ,

c_last_name char(30) ,

c_preferred_cust_flag char(1) ,

c_birth_day int ,

c_birth_month int ,

c_birth_year int ,

c_birth_country varchar(20) ,

c_login char(13) ,

c_email_address char(50) ,

c_last_review_date char(10)

)

row format delimited fields terminated by '|'

stored as orc ;

insert into table customer select * from customer_tmp;

drop table customer_tmp;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值