如何在Hive的所有表中找到特定的列名? [英] How can I find a particular column name within all tables in Hive.?
问题描述
如何在Hive的所有表中找到特定的列名?
How can I find a particular column name within all tables in Hive?
我在配置单元中运行了此查询:select table_name,column_name from retail.columns where column_name like '%emp%';
(零售是一个数据库).
I ran this query in hive: select table_name,column_name from retail.columns where column_name like '%emp%';
(retail is a database).
但是它给出了:
错误失败:SemanticException行0:-1找不到表列"
error FAILED: SemanticException Line 0:-1 Table not found 'columns'
我尝试查询:select distinct table_name from default.columns where column_name = 'emp'
(默认是我的数据库).但这也给了错误.
I tried query: select distinct table_name from default.columns where column_name = 'emp'
(default is mine database). But it's also giving error.
我搜索了这些,得到了我写的用于SQL数据库的查询.
I searched about these, I got which query I wrote it's for SQL databases.
但是我想在配置单元数据库中搜索?如何进入蜂巢?
But I want to search in hive database? How to get in hive?
之前也曾问过同样的问题,但我认为情况可能已经改变,可能会有直接的解决方案:
The same question has been asked before but I feel things might have changed and there might be direct solution:
推荐答案
以下shell脚本将为您提供所需的结果:
below shell script will give you desired result:
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
这篇关于如何在Hive的所有表中找到特定的列名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!