且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何获取Hive数据库中的所有表定义?

更新时间:2023-01-19 12:26:25

您可以执行此操作通过编写一个简单的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.