Created 03-15-2017 07:38 PM
i have 100 tables Test_1,Test_2......Test80 test90 out of which some 70 tables start with string Test_ need to be removed.
I need to use only hive queries, nothing from unix just pure hive commands, I am looking for something like this
drop table where tablename like Test_*
Created 03-15-2017 09:02 PM
Hive does not support like semantics for drop table, see official DDL semantics here. You will need multiple calls to accomplish this and handle them in an external driver.
Created 03-16-2017 02:58 PM
Just to elaborate the answer from @Deepesh, here is an example, how you can accomplish your goal.
1) save a list of tables you want to drop into a file
echo "show tables like 'test_*';" > tables.sql beeline -u 'jdbc:hive2://localhost:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2' -f tables.sql > tables.txt
2) from this list, generate a list of drop tables commands; for example, you can use the following python script, generate_droptables.py:
f = 'tables.txt' f = open(f) lines = f.readlines() def process_line(line): if line.startswith('|') and 'test_' in line: return line[1:].strip()[:-1].strip() names = list(map(process_line, lines)) names = list(filter(lambda x : x, names)) out = open('droptables.sql', 'w') for item in names: out.write("drop table %s;\n" % item)
3) run the list drop tables command
python generate_droptables.py beeline -u 'jdbc:hive2://localhost:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2' -f droptables.sql