如何在Hive的所有表中找到特定的列名? [英] How can I find a particular column name within all tables in Hive.?

查看:758
本文介绍了如何在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:

在Hive中搜索表和列

推荐答案

以下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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆