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查询的正则表达式(或者我没有找到它们).但是有多种方法可以做到这一点,例如:
使用shell脚本:
hive -e "show tables 'temp_*'" | xargs -I '{}' hive -e 'drop table {}'
Run Code Online (Sandbox Code Playgroud)或者将表放在特定的数据库中并删除整个数据库.
Create table temp.table_name;
Drop database temp cascade;
Run Code Online (Sandbox Code Playgroud)我的解决方案是将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)
以上解决方案都很好.但是如果要删除更多表,那么运行'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)
这种方法会快得多.
| 归档时间: |
|
| 查看次数: |
19854 次 |
| 最近记录: |