This shows you the differences between two versions of the page.
— |
part-count [2015/09/23 20:27] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== PART_COUNT Function ====== | ||
+ | PART_COUNT function returns the number partitions in the specified table. | ||
+ | |||
+ | **Syntax**: | ||
+ | |||
+ | <code language="sql"> | ||
+ | PART_COUNT([db_name.]table_name, part_col=filter, ...); | ||
+ | </code> | ||
+ | |||
+ | **Parameters:** | ||
+ | |||
+ | | [dbname.]table_name | Identifier, variable or expression | | ||
+ | | part_col=filter | One or more partition filters | | ||
+ | |||
+ | **Notes**: | ||
+ | |||
+ | * HPL/SQL uses the following Hive statement to get the partition information: | ||
+ | |||
+ | <code language="sql"> | ||
+ | SHOW PARTITIONS db_name.tab_name [PARTITION (part_col=filter, ...)] | ||
+ | </code> | ||
+ | |||
+ | **Return Value:** | ||
+ | |||
+ | * The number of partitions | ||
+ | * NULL if the table does not exist or an error occurs | ||
+ | |||
+ | **Return Type:** | ||
+ | |||
+ | INT | ||
+ | |||
+ | **Examples:** | ||
+ | |||
+ | Table //db.orders// is partitioned by //dt// and //region// columns and has the following partitions: | ||
+ | |||
+ | | dt=2015-09-01/region=1 | | ||
+ | | dt=2015-09-01/region=2 | | ||
+ | | dt=2015-09-02/region=1 | | ||
+ | | dt=2015-09-03/region=3 | | ||
+ | | dt=2015-09-03/region=2 | | ||
+ | |||
+ | Get the total number of partitions: | ||
+ | |||
+ | <code language="sql"> | ||
+ | part_count(db.orders); | ||
+ | -- | ||
+ | 5 | ||
+ | </code> | ||
+ | |||
+ | Get the number of partitions in //region 1//: | ||
+ | |||
+ | <code language="sql"> | ||
+ | part_count(db.orders, region='1'); | ||
+ | -- | ||
+ | 2 | ||
+ | </code> | ||
+ | |||
+ | **Compatibility**: HPL/SQL extension. | ||
+ | |||
+ | **Version:** HPL/SQL 0.3.13 | ||
+ | |||
+ | See also: | ||
+ | * [[part-count-by|PART_COUNT_BY]] - Get the number of partitions (group by) | ||
+ | * [[part-loc|PART_LOC]] - Get the location of a partition |