当前位置: 代码迷 >> 综合 >> hive 表的创建与数据导入
  详细解决方案

hive 表的创建与数据导入

热度:92   发布时间:2024-02-10 05:54:35.0

1.创建hive 表

(1) 方法一:使用建表语句创建,可以指定分隔符

use test_db;
drop table if exists tablename;
CREATE TABLE tablename (id string,name string,age int
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ','
STORED AS INPUTFORMAT 'org.apache.hadoop.mapred.TextInputFormat'
OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat';

从本地文件加载数据到hive表(shell 环境下执行下面命令)

load data local inpath '/home/zz/filename' overwrite into table tablename;

从本地文件加载数据导入分区表

load data local inpath '/home/zz/order.txt' overwrite
into table tablename partition (dt='2020-08-12');

----无法直接使用insert向orc表(orc格式对数据进行了压缩,压缩比 1:20左右)插入数据,如需要可先插入txt表,之后再导入orc表

(2)方法二:创建hive表,并从其他表导入数据(stored as 可以指定数据存储方式orc,textfile)

 create table XX stored as textfile as select * from tablename;   -- 以textfile格式保存表