hdfs文件导入hive(ods层),格式为ORC


方式一:

1、创建库表

-- 创建库表
set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nonstrict;
drop table if exists ods_log;
CREATE EXTERNAL TABLE ods_log (`line` string)
PARTITIONED BY (`dt` string) -- 按照时间创建分区
STORED AS -- 指定存储方式
  textfile
LOCATION '/warehouse/mall/ods/ods_log'  -- 指定数据在hdfs上的存储位置
;

2、加载数据

--加载数据
load data  inpath '/flume/data/mall/log/topic_log/2021-04-06' overwrite into table ods_log partition(dt='2021-04-06');

3、修改表存储格式

--将表存储格式修改为orc
ALTER TABLE ods_log SET FILEFORMAT ORC;

4、查看表存储结构变化

show create table ods_log;

 

 方式二:

1、创建临时表并加载数据

--创建临时表
set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nonstrict;
drop table if exists ods_log_tmp;
CREATE EXTERNAL TABLE ods_log_tmp (`line` string)
PARTITIONED BY (`dt` string) -- 按照时间创建分区
STORED AS -- 指定存储方式
  textfile
LOCATION '/warehouse/mall/ods/ods_log_tmp';

load data  inpath '/flume/data/mall/log/topic_log/2021-04-06' overwrite into table ods_log_tmp partition(dt='2021-04-06');

2、创建ods库表

-- 创建库表
set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nonstrict;
drop table if exists ods_log;
CREATE EXTERNAL TABLE ods_log (`line` string)
PARTITIONED BY (`dt` string) -- 按照时间创建分区
STORED AS -- 指定存储方式
  orc
LOCATION '/warehouse/mall/ods/ods_log'  -- 指定数据在hdfs上的存储位置
;

3、将数据导入orc格式表中

-- 加载日志数据  --- 默认压缩格式为snappy
insert overwrite  table  ods_log partition (dt='2021-04-06') select  line from ods_log_tmp;

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM