如何获取Hive数据库中的所有表定义? [英] How to get all table definitions in a database in Hive?

查看:3509
本文介绍了如何获取Hive数据库中的所有表定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找Hive中的所有表格定义。我知道,对于单表定义,我可以使用类似于 -

 描述<< table_name>> 
描述扩展<< table_name>>

但是,我找不到获取所有表定义的方法。在megastore中是否有任何类似于MySQL中的Information_Schema的表或者是否有命令来获取所有表定义?

解决方案

您可以执行此操作通过编写一个简单的bash脚本和一些bash命令。

首先,使用以下命令将数据库中的所有表名写入文本文件:

  $ hive -e'在< dbname>'中显示表格| tee tables.txt 

然后创建一个bash脚本(describe_tables.sh)循环遍历每个表列表:

  while read line 
do
echo$ line
evalhive -e'描述< dbname>。$ line'
done

然后执行脚本:

  $ chmod + x describe_tables.sh 
。./ describe_tables.sh< tables.txt> definitions.txt

definitions.txt文件将包含所有表格定义。


I am looking to get all table definitions in Hive. I know that for single table definition I can use something like -

  describe <<table_name>>
  describe extended <<table_name>>

But, I couldn't find a way to get all table definitions. Is there any table in megastore similar to Information_Schema in mysql or is there command to get all table definitions ?

解决方案

You can do this by writing a simple bash script and some bash commands.

First, write all table names in a database to a text file using:

$hive -e 'show tables in <dbname>' | tee tables.txt

Then create a bash script (describe_tables.sh) to loop over each table in this list:

while read line
do
 echo "$line"
 eval "hive -e 'describe <dbname>.$line'"
done

Then execute the script:

$chmod +x describe_tables.sh
$./describe_tables.sh < tables.txt > definitions.txt

The definitions.txt file will contain all the table definitions.

这篇关于如何获取Hive数据库中的所有表定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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