1 Hive 表的类型
1.1 默认都是 管理表(内部表)
- 内部表删除表时,会删除表数据和元数据;
- 默认存在
/user/hive/warehouse
,可以通过location
指定
desc formatted dept;
1.2 创建外部表
- 删除表时,只会删除元数据,不会删除表数据(在 HDFS);
- 创建表时可以自己指定目录位置
- 企业大部分用的外部表
create external table if not exists default.emp_ext(
empno int,
ename string,
job string,
mgr int,
hiredate string,
sal double,
comm double,
deptno int
) row format delimited fields terminated by '\t';
desc formatted emp_ext;
1.2.1 创建外部表并且指定位置
将数据和表放到 HDFS 用一个目录,数据会自动导入。
hive (default)> dfs -mkdir -p /user/hive/warehouse/emp_ext2;
- `hive (default)> dfs -put /home/hadoop/emp.txt /user/hive/warehouse/emp_ext2;
create external table if not exists default.emp_ext2(
empno int,
ename string,
job string,
mgr int,
hiredate string,
sal double,
comm double,
deptno int
) row format delimited fields terminated by '\t'
location '/user/hive/warehouse/emp_ext2';