如何编写查询以查找 HIVE 数据库中具有特定列名的所有表

How to write a query to find all tables in HIVE db that have a specific column name

我有一个包含大约 100 个表的数据库,我需要构建一个连接查询以从其中两个表中获取特定数据。我认识一个,但不认识另一个。基本上我需要这样的东西:

select <tables> from <HIVE_database> where exists table.column name;

我该怎么做?

您可以编写一个 shell 脚本来在所有 table 中搜索该列。

第一行给出了所有 table 个名字。它被传递给读取命令 并在每个 table 的 describe 输出中搜索列名称。

$hive -e 'show tables in <HIVE_database>'  | \
while read line
do
 echo "TABLE NAME : $line"
  eval "hive -e 'describe <HIVE_database>.$line'" | grep "<column_name>" 
done