如何在 Hive 的所有表中找到特定的列名?

Moh*_*.kc 6 hadoop hive

如何在 Hive 的所有表中找到特定的列名称?

我在配置单元中运行了这个查询:(select table_name,column_name from retail.columns where column_name like '%emp%';零售一个数据库)。

但它给予:

错误失败:SemanticException 第 0 行:-1 找不到表“列”

我尝试查询:(select distinct table_name from default.columns where column_name = 'emp'默认我的数据库)。但它也给出了错误。

我搜索了这些,得到了我为 SQL 数据库编写的查询。

但我想在 hive 数据库中搜索?如何进入蜂巢?

以前曾问过同样的问题,但我觉得事情可能已经改变,并且可能有直接的解决方案:

如何在 Hadoop/Hive 中搜索具有给定列名的所有表并返回哪些表具有该列名?

在 Hive 中搜索表和列

Abh*_*and 4

下面的 shell 脚本将为您提供所需的结果:

hive -S -e 'show databases'|
while read database
do
   eval "hive -S -e 'show tables in $database'"|
   while read line
   do
if eval "hive -S -e 'describe $database.$line'"| grep -q "<column_name"; then
  output="Required table name: $database.$line"'\n';
else
output=""'\n';

fi
echo -e "$output"
 done
done
Run Code Online (Sandbox Code Playgroud)