使用LOCATION子句创建的Hive内部表,删除时会删除指定位置数据吗?
Great questions about Hive managed tables—let's break down their behavior clearly when using custom LOCATION clauses:
1. 使用LOCATION子句创建内部表后,删除该表时对应数据是否会被删除?
Absolutely yes. The core trait of a Hive managed (internal) table is that Hive takes full ownership of both the table's metadata (stored in the Metastore) and the actual data files. Whether you explicitly specify a LOCATION or not, running DROP TABLE <table_name>; will delete both the table's metadata entry and all data files in the associated storage path.
For example, if you create a table like this:
CREATE TABLE employee (id INT, name STRING) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' LOCATION '/user/hive/custom_data/employee';
Executing DROP TABLE employee; will:
- Remove the
employeetable record from the Hive Metastore - Delete every file and subdirectory under
/user/hive/custom_data/employee
2. 若创建内部表时通过LOCATION子句指定了非Hive默认存储位置,删除该表时是否会如同默认位置的内部表一样,删除指定位置的数据?
Yes, exactly. The storage location (default warehouse vs. custom path) doesn't change the core behavior of a managed table. Hive treats the custom LOCATION path as the official storage location for that table, so dropping the table will clean up both metadata and all data in that custom path—just like it would for a table using the default warehouse location.
A quick edge case to note: Make sure the Hive process has proper read/write permissions on the custom path. If permissions are missing, you might end up with metadata deleted but data left behind (this is an access issue, not the intended default behavior of managed tables).
内容的提问来源于stack exchange,提问作者Ayesha Jahangir

