在从配置单元创建内部表的过程中,使用location子句删除内部表时,数据会被删除吗?

7ivaypg9  于 2021-06-26  发布在  Hive
关注(0)|答案(1)|浏览(311)

在配置单元中,如果我在table creation语句中使用loaction子句(提到除配置单元的默认位置以外的loaction)创建一个内部表,那么在删除该表时,它是否会像在配置单元的默认位置时那样从指定位置删除数据?

zqry0prt

zqry0prt1#

是的,即使它不是配置单元的默认位置,它也会删除该位置。假设在/user/yashu/test5目录的默认数据库中有一个测试表。

hive> desc formatted test_tmp;
+-------------------------------+-------------------------------------------------------------+-----------------------+--+
|           col_name            |                          data_type                          |        comment        |
+-------------------------------+-------------------------------------------------------------+-----------------------+--+
| # col_name                    | data_type                                                   | comment               |
|                               | NULL                                                        | NULL                  |
| id                            | int                                                         |                       |
| name                          | string                                                      |                       |
|                               | NULL                                                        | NULL                  |
| # Detailed Table Information  | NULL                                                        | NULL                  |
| Database:                     | default                                                     | NULL                  |
| Owner:                        | shu                                                   | NULL                  |
| CreateTime:                   | Fri Mar 23 03:42:15 EDT 2018                                | NULL                  |
| LastAccessTime:               | UNKNOWN                                                     | NULL                  |
| Protect Mode:                 | None                                                        | NULL                  |
| Retention:                    | 0                                                           | NULL                  |
| Location:                     | hdfs://nn1.com/user/yashu/test5                   | NULL                  |
| Table Type:                   | MANAGED_TABLE                                               | NULL                  |
| Table Parameters:             | NULL                                                        | NULL                  |
|                               | numFiles                                                    | 1                     |
|                               | totalSize                                                   | 12                    |
|                               | transient_lastDdlTime                                       | 1521790935            |
|                               | NULL                                                        | NULL                  |
| # Storage Information         | NULL                                                        | NULL                  |
| SerDe Library:                | org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe          | NULL                  |
| InputFormat:                  | org.apache.hadoop.mapred.TextInputFormat                    | NULL                  |
| OutputFormat:                 | org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat  | NULL                  |
| Compressed:                   | No                                                          | NULL                  |
| Num Buckets:                  | -1                                                          | NULL                  |
| Bucket Columns:               | []                                                          | NULL                  |
| Sort Columns:                 | []                                                          | NULL                  |
| Storage Desc Params:          | NULL                                                        | NULL                  |
|                               | field.delim                                                 | ,                     |
|                               | serialization.format                                        | ,                     |
+-------------------------------+-------------------------------------------------------------+-----------------------+--+

hadoop目录在test 5目录中有一个.txt文件

bash$    hadoop fs -ls /user/yashu/test5/
    Found 1 items
    -rw-r--r--   3 hdfs hdfs         12 2018-03-23 03:42 /user/yashu/test5/test.txt

配置单元表数据

select * from test_tmp;
+--------------+----------------+--+
| test_tmp.id  | test_tmp.name  |
+--------------+----------------+--+
| 1            | bar            |
| 2            | foo            |
+--------------+----------------+--+

一旦我在hive中删除了表,那么目录test5也从hdfs中删除了

hive> drop table test_tmp;
bash$ hadoop fs -ls /user/yashu/test5/
ls: `/user/yashu/test5/': No such file or directory

因此,一旦我们删除了配置单元中的内部表,即使配置单元表不在默认位置,也会删除表所指向的目录(位置)。

相关问题