美文网首页
Hive查询表行数

Hive查询表行数

作者: 小神david | 来源:发表于2017-07-02 17:00 被阅读0次

    有时在大数据处理时需要查询一些数据表的行数,一般我们会使用

    select count(*) from <table>;
    

    或者

    select count(1) from <table>;
    

    进行查询。

    如果多个表项,可能会使用脚本来批量执行。

    for line in $(cat tables.txt)
    do
        echo "tablename :$line";
        value=$(hive --database databasename --hiveconf v=v1 -S -e "select count(*) from $line;")
        echo "rows count:$value"
    done;
    

    也可以使用后台并行的执行方式。

    但是这种方式执行时间比较长,有两种比较快速的方式可以迅速地查到表的行数信息:

    1.从数据库中查询元数据

    select a.TBL_ID, a.TBL_NAME, b.PARAM_KEY, b.PARAM_VALUE from TBLS as a join TABLE_PARAMS as b where a.TBL_ID = b.TBL_ID and TBL_NAME="call_center" and PARAM_KEY="numRows";
    +--------+-------------+-----------+-------------+
    | TBL_ID | TBL_NAME    | PARAM_KEY | PARAM_VALUE |
    +--------+-------------+-----------+-------------+
    |    134 | call_center | numRows   | 60          |
    +--------+-------------+-----------+-------------+
    

    2.从HUE上直接查看

    Paste_Image.png

    相关文章

      网友评论

          本文标题:Hive查询表行数

          本文链接:https://www.haomeiwen.com/subject/altocxtx.html