方式一:
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;