赞
踩
使用truncate命令删除外部表:
truncate table mytable;
#FAILED: SemanticException [Error 10146]: Cannot truncate non-managed table mytable. (state=,code=0)
查看表结构
1. describe extended tablename
2. desc formatted tablename;
| NULL | NULL |
| # Partition Information | NULL | NULL |
| # col_name | data_type | comment |
| | NULL | NULL |
| load_date | string | |
| | NULL | NULL |
| # Detailed Table Information | NULL | NULL |
| Database: | ods_project | NULL |
| Owner: | hive | NULL |
| CreateTime: | Wed Jul 25 16:24:48 CST 2018 | NULL |
| LastAccessTime: | UNKNOWN | NULL |
| Protect Mode: | None | NULL |
| Retention: | 0 | NULL |
| Location: | hdfs://***/myname | NULL |
| Table Type: | EXTERNAL_TABLE | NULL |
| Table Parameters: | NULL | NULL |
| | EXTERNAL | TRUE |
| | numPartitions | 1 |
| | transient_lastDdlTime | 1532507088 |
| | NULL | NULL |
| # Storage Information | NULL | NULL |
| SerDe Library: | org.apache.hadoop.hive.ql.io.orc.OrcSerde | NULL |
| InputFormat: | org.apache.hadoop.hive.ql.io.orc.OrcInputFormat | NULL |
| OutputFormat: | org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat | NULL |
| Compressed: | No | NULL |
| Num Buckets: | -1 | NULL |
| Bucket Columns: | [] | NULL |
| Sort Columns: | [] | NULL |
| Storage Desc Params: | NULL | NULL |
| | serialization.format | 1 |
+-------------------------------+----------------------------------------------------+-----------------------+--
truncate不能删除外部表,只能删除内部表
1.删除该表分区:
alter table tablename drop partition(load_date='2018-11-23',p_hou16);
2.删除hdfs中的数据
[hdfs@localhost ~]$ hadoop fs -ls /home/tablename
Found 8 items
drwxr-x--- - root users 0 2018-09-27 13:39 /home/tablename/p_date=2018-03-19
drwxr-x--- - root users 0 2018-09-27 15:24 /home/tablename/p_date=2018-03-20
可以将外部表变为内部表,再删除内部表
ALTER TABLE xxx SET TBLPROPERTIES('EXTERNAL'='False');
drop table xxx;
外部表:创建表的时候指定了EXTERNAL,外部表在删除分区后,hdfs中的数据还存在,不会被删除
内部表:创建表的时候未指定,直接使用drop就能把hdfs里的数据删掉
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。