Can I count the number of sections?

I am working on a test in which I have to find out the number of table partitions and check if this is correct. If I use show partitions TableName, I get all sections by name, but I want to get the number of sections, for example, something along the lines show count(partitions) TableName(which redirects OK btw .. so this is not good) and get 12 (for ex.).
Is there any way to achieve this?

+3
source share
5 answers

You can use:

select count(distinct <partition key>) from <TableName>;
+3
source

Using Hive CLI

$ hive --silent -e "show partitions <dbName>.<tableName>;" | wc -l

- silent mode to enable silent mode

-e indicates that the bush is executing a quoted string

+3
source

WebHCat . , , . JSON - JSON .

In this example of constructing WebHCat results for Python, only 24 is returned, representing the number of partitions for this table. (Server name is the name of the node).

curl -s 'http://*myservername*:50111/templeton/v1/ddl/database/*mydatabasename*/table/*mytablename*/partition?user.name=*myusername*' | python -c 'import sys, json; print len(json.load(sys.stdin)["partitions"])'
24
0
source

Using the following command, you will get all sections, and also at the end display the number of selected rows. This number of lines means the number of partitition

SHOW PARTITIONS [db_name.] Table_name [PARTITION (partition_spec)];

Eg -

enter image description here

0
source

Use the following syntax:

show create table <table name>;
-2
source

All Articles