Support Questions

Find answers, ask questions, and share your expertise
Announcements
Check out our newest addition to the community, the Cloudera Data Analytics (CDA) group hub.

table row count from hive metastore

Explorer

Hi, is it possible to find out the number of rows in a table from the hive metastore?

I don't want to run "select count(*) from <table>" from the hive prompt. Rather I am looking to find that count from the hive metadata.

Appreciate any insights.

5 REPLIES 5

Hi @n c

Hcatalog holds metadata of a table details like Schema, Index, Roles, Structure, Bucketing, Partitions keys, Columns, privileges, When the table was created, By whom it was created etc. But It doesn't contain any details about how many records are stored in each table.

Alternatively analyze table tbl_name compute statistics; will give you no of files, no of records and its size.

Hope it helps.

Cloudera Employee

If table statistics are updated you can run DESC FORMATTED <table_name>. This will display row count.

New Contributor

As of the HDP 2.6.1 release here is a query that I use to find row counts on a specific partitioned table:

SELECT * FROM hive.PARTITION_PARAMS AS A, hive.PARTITIONS AS B WHERE A.PARAM_KEY='numRows' and A.PART_ID=B.PART_ID and A.PART_ID IN ( SELECT PART_ID FROM hive.PARTITIONS WHERE TBL_ID=(SELECT A.TBL_ID FROM hive.TBLS AS A, hive.DBS AS B WHERE A.DB_ID=B.DB_ID AND B.NAME='DATABASE_NAME' AND A.TBL_NAME='TABLE_NAME'))

This specific query gives me row counts for each partition of a specific table. You need to replace DATABASE_NAME and TABLE_NAME with the one you are interested in.

MySQL metastore but should work with others.


New Contributor

@n c

It works after I set this in hive-site.xml

I am not sure the reason, but it was forced to run mapreduce

hive.compute.query.using.stats=false
Take a Tour of the Community
Don't have an account?
Your experience may be limited. Sign in to explore more.