Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drop and overwrite external table in hive

I need to create an external table in hiveql with the output from a SELECT clause. Every time when the HiveQL is ran the table should be dropped and recreated . When we drop an external table only the table structure is getting dropped but not the data files from HDFS location. How to achieve this?

like image 571
Dileep Dominic Avatar asked Jul 10 '26 18:07

Dileep Dominic


1 Answers

Create Table As Select (CTAS) has restrictions. One of them is that target table cannot be External.

You have these options:

  1. Create external table once, then INSERT OVERWRITE

    INSERT OVERWRITE TABLE tablename1 [PARTITION (partcol1=val1, partcol2=val2 ...) select_statement1 FROM from_statement;

  2. Use managed table, then you can DROP TABLE, then CREATE TABLE ... as SELECT

See also answer about skipTrash and auto.purge property.

like image 80
leftjoin Avatar answered Jul 14 '26 03:07

leftjoin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!