I ran into this today, when dropping a table CREATED LIKE an external
table, and ended up with a significant chunk of data unintentionally
deleted (moved to trash, thankfully!). The (potential) issue is this:
currently, CREATE TABLE LIKE doesn't maintain the EXTERNAL status of the
table, unless you specify CREATE EXTERNAL TABLE LIKE. That is,
> CREATE EXTERNAL TABLE original(val string) LOCATION '/tmp/original';
> CREATE TABLE new_table LIKE original;
> SHOW CREATE TABLE original;
OK
CREATE EXTERNAL TABLE `original`(
...
LOCATION
'hdfs://master.local:8020/tmp/original'
;
> SHOW CREATE TABLE new_table;
OK
CREATE TABLE `new_table`(
`val` string)
...
LOCATION
'hdfs://master.local:8020/user/hive/warehouse/new_table'
;
As the example shows, the new table doesn't copy the original table's
external status. Given that the external keyword wasn't specified for
the new table, this might be reasonable behavior; however, it's not
clearly specified in the hive documentation
(https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-CreateTableLike)
and was certainly confusing in my case. Is this in fact the intended
behavior? If so, would it be reasonable to add a note about this to the
documentation?
Thanks for the help,
Andrew