概述
管理表,也称作内部表,受控表。
所有的 Table 数据(不包括 External Table)都保存在warehouse这个目录中。
删除表时,元数据与数据都会被删除。
在加载数据的过程中,实际数据会被移动到数据仓库目录中;之后对数据对访问将会直接在数据仓库目录中完成。删除表时,表中的数据和元数据将会被同时删除。
操作
创建数据文件
inner_table.dat
创建表
hive>create table inner_table (key string);
加载数据
hive>load data local inpath '/root/inner_table.dat' into table inner_table;
查看数据
select * from inner_table
select count(*) from inner_table
删除表 drop table inner_table
缺点
假设,t1表的文件路径在/homet2表的文件路径在/home/t2
当删除t1表时,会把/home下的都删了。这是很危险的,所以实际开发中,不用管理表,很容易导致数据丢失。
修改管理表为外部表
alter table t1 set tblpropertise('EXTERNAL'='TRUE');
EXTERNAL,TRUE 这个词必须大写,改回内部表用FALSE
---------------------------------------------------------------
hive (default)> desc formatted map_test;OK
col_name data_type comment
# col_name data_type comment
id string
perf map<string,int>
# Detailed Table Information
Database: default
Owner: hadoop
CreateTime: Wed Aug 31 20:15:40 CST 2016
LastAccessTime: UNKNOWN
Retention: 0
Location: hdfs://hello110:9000/user/hive/warehouse/map_test
Table Type: MANAGED_TABLE
Table Parameters:
COLUMN_STATS_ACCURATE {\"BASIC_STATS\":\"true\"}
numFiles 0
numRows 0
rawDataSize 0
totalSize 0
transient_lastDdlTime 1472645800
# Storage Information
SerDe Library: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
InputFormat: org.apache.hadoop.mapred.TextInputFormat
OutputFormat: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat
Compressed: No
Num Buckets: -1
Bucket Columns: []
Sort Columns: []
Storage Desc Params:
colelction.delim ,
field.delim \t
mapkey.delim :
serialization.format \t
Time taken: 0.383 seconds, Fetched: 34 row(s)