从配置单元中的所有表中获取行数 [英] Get row count from all tables in hive

查看:146
本文介绍了从配置单元中的所有表中获取行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从使用配置单元的所有表中获取行计数。我对数据库名称,表名和行数很感兴趣。

解决方案

您需要做一个

  select count(*)from table 



所有表格。

要自动执行此操作,您可以制作一个小型bash脚本和一些bash命令。
首次运行

  $ hive -e'show tables'| tee tables.txt 

这将数据库中的所有表存储在文本文件tables.txt中



使用以下内容创建一个bash文件(count_tables.sh)。

  while read line 
do
echo$ line
evalhive -e'select count(*)from $ line'
done



现在执行以下命令。

pre $ code > $ chmod + x count_tables.sh
$。/ count_tables.sh< tables.txt> counts.txt

这将创建一个文本文件(counts.txt),其中包含所有表的计数数据库

How can I get row count from all tables using hive. I am interested in database name, table name and row count

解决方案

You will need to do a

select count(*) from table

for all tables.

To automate this, you can make a small bash script and some bash commands. First run

$hive -e 'show tables' | tee tables.txt

This stores all tables in the database in a text file tables.txt

Create a bash file (count_tables.sh) with the following contents.

while read line
do
 echo "$line "
 eval "hive -e 'select count(*) from $line'"
done

Now run the following commands.

$chmod +x count_tables.sh
$./count_tables.sh < tables.txt > counts.txt

This creates a text file(counts.txt) with the counts of all the tables in the database

这篇关于从配置单元中的所有表中获取行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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