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

问题描述 投票:3回答:2

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

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

但它给了:

错误FAILED:SemanticException第0行:-1未找到表'列'

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

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

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

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

How can you search for all tables with a given column name and return which tables have this column name in Hadoop/Hive?

Searching Tables and Columns in Hive

hadoop hive
2个回答
2
投票

下面的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

-1
投票

这是您可以在Metastore上使用的查询:

选择来自TBLS的TBL_NAME,COLUMN_NAME,TYPE_NAME,在CD_ID = TBL_ID上加入COLUMNS_V2,其中COLUMN_NAME喜欢“列”;

其中'column'是您要查找的列名称。

© www.soinside.com 2019 - 2024. All rights reserved.