Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dropping multiple tables with same prefix in Hive

I have few tables in hive that has same prefix like below..

temp_table_name
temp_table_add
temp_table_area

There are few hundreds of tables like this in my database along with many other tables. I want to delete tables that starts with "temp_table". Do any of you know any query that can do this work in Hive?

like image 620
Alex Raj Kaliamoorthy Avatar asked Mar 09 '16 10:03

Alex Raj Kaliamoorthy


People also ask

Can you drop multiple tables in the same statement?

We can drop multiple tables together using a single DROP Table statement as well. Let's create three tables and later we will drop it.

How do you use the prefix to drop a table?

SELECT CONCAT( 'DROP TABLE ', GROUP_CONCAT(table_name) , ';' ) AS statement FROM information_schema. tables WHERE table_name LIKE 'myprefix_%'; This will generate a DROP statement which you can than copy and execute to drop the tables.


1 Answers

There is no such thing as regular expressions for drop query in hive (or i didn't find them). But there are multipe ways to do it, for example :

  • With a shell script :

    hive -e "show tables 'temp_*'" | xargs -I '{}' hive -e 'drop table {}'
    
  • Or by putting your tables in a specific database and dropping the whole database.

    Create table temp.table_name;
    
    Drop database temp cascade;
    
like image 106
Tremo Avatar answered Sep 30 '22 01:09

Tremo