概述
管理表,也稱作內部表,受控表。
所有的 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)