在Hive中删除具有相同前缀的多个表

Ale*_*thy 13 hadoop hive hiveql

我在hive中有几个表具有相同的前缀,如下所示.

temp_table_name
temp_table_add
temp_table_area
Run Code Online (Sandbox Code Playgroud)

在我的数据库中有几百个像这样的表以及许多其他表.我想删除以"temp_table"开头的表.你们中的任何人都知道任何可以在Hive中执行此操作的查询吗?

Tre*_*emo 17

在hive中没有用于drop查询的正则表达式(或者我没有找到它们).但是有多种方法可以做到这一点,例如:

  • 答案是完美的,但是需要进行一些实际上对我有用的小改动.我通过添加双引号来修改@Louxou的代码.这是更新的代码.`hive -e"show tables'temp_*'"| xargs -I'{}'hive -e'drop table {}'` (2认同)

Hor*_*usH 5

我的解决方案是将bash脚本与以下cmd结合使用:

hive -e "SHOW TABLES IN db LIKE 'schema*';" | grep "schema" | sed -e 's/^/hive -e \"DROP TABLE db\./1' | sed -e 's/$/\"/1' > script.sh
chmod +x script.sh
./script.sh
Run Code Online (Sandbox Code Playgroud)


Cha*_*dra 5

以上解决方案都很好.但是如果要删除更多表,那么运行'hive -e drop table'的速度很慢.所以,我用过这个:

hive -e 'use db;show tables' | grep pattern > file.hql
Run Code Online (Sandbox Code Playgroud)

使用vim编辑器打开file.hql并运行以下命令

:%s!^!drop table  
:%s!$!;
Run Code Online (Sandbox Code Playgroud)

然后运行

hive -f file.hql
Run Code Online (Sandbox Code Playgroud)

这种方法会快得多.