用于筛选和提取配置单元表名称的脚本

lyfkaqu1  于 2021-06-28  发布在  Hive
关注(0)|答案(1)|浏览(202)

我试图编写一个脚本,遍历配置单元服务器中的所有数据库,并为每个数据库返回包含具有特定名称的列的表列表。具体地说(在伪代码中):

list l
for d in show databases:
   use d
   for tbl in show tables:
     res = describe tbl | grep col_name
     if res not empty:
       l.append(tbl.name)
return l

我不知道该怎么编码。有什么帮助吗?如果有一些很好的参考来结合这些shell命令和管道等,我会很感激你的建议。

njthzxwz

njthzxwz1#

一种选择是使用 hive -e '<hive command>' (无论您选择何种脚本语言): hive -e 'show databases' 将返回所有数据库 hive -e 'use $d; show tables' 将返回数据库中的所有表
$d hive -e 'use $d; describe $tbl' 将描述表格 $tbl 在数据库中 $d

相关问题