在hive中,当我运行show tables;
时,我得到了所有表的列表,我如何知道哪些是托管表,哪些是外部表?
答案 0 :(得分:1)
对于单个表格,您可以使用desc formatted
或desc extended
create table mytable (i int);
create external table myexttable (i int);
hive> desc formatted mytable;
...
Location: hdfs://horton/user/dmarkovitz/mytable
Table Type: MANAGED_TABLE
Table Parameters:
...
hive> desc formatted myexttable;
...
Location: hdfs://horton/user/dmarkovitz/myexttable
Table Type: EXTERNAL_TABLE
Table Parameters:
...
hive> desc extended mytable;
...
Detailed Table Information Table(tableName:mytable ... tableType:MANAGED_TABLE)
hive> desc extended myexttable;
...
Detailed Table Information Table(tableName:myexttable ... tableType:EXTERNAL_TABLE)
对于许多/所有表,您可以查询Metastore(Hive元数据数据库)。
(在本演示中,Metastore是在mysql中)
select d.name as database_name
,t.tbl_name
,t.tbl_type
from metastore.DBS as d
join metastore.TBLS as t
on t.DB_ID =
d.DB_ID
where d.name = 'dmarkovitz'
;
+---------------+------------+----------------+
| database_name | tbl_name | tbl_type |
+---------------+------------+----------------+
| dmarkovitz | mytable | MANAGED_TABLE |
| dmarkovitz | myexttable | EXTERNAL_TABLE |
+---------------+------------+----------------+
仅供参考,EXTERNAL / MANAGED属性只是一个标志(元数据级别),可以使用ALTER TABLE
命令进行更改
<强>蜂房强>
alter table mytable set tblproperties ("EXTERNAL"="TRUE");
alter table myexttable set tblproperties ("EXTERNAL"="FALSE");
<强> metastore 强>
select d.name as database_name
,t.tbl_name
,t.tbl_type
from metastore.DBS as d
join metastore.TBLS as t
on t.DB_ID =
d.DB_ID
where d.name = 'dmarkovitz'
;
+---------------+------------+----------------+
| database_name | tbl_name | tbl_type |
+---------------+------------+----------------+
| dmarkovitz | mytable | EXTERNAL_TABLE |
| dmarkovitz | myexttable | MANAGED_TABLE |
+---------------+------------+----------------+
答案 1 :(得分:0)
您可以使用以下命令获取指定表的详细信息:
describe formatted <your_table>;
输出将包含一行描述table type
:
表类型:EXTERNAL_TABLE
或
表类型:MANAGED_TABLE