Apache Hive : HPL/SQL - MIN_PART_INT Function
Table of Contents
Apache Hive : HPL/SQL - MIN_PART_INT Function
MIN_PART_INT function finds the minimum value for the specified partition column of type INT.
Syntax:
MIN_PART_INT([db_name.]table_name [, column_name [, part_col=filter, ...]]);
Parameters:
| Parameter | Type | Value | Description |
|---|---|---|---|
| [dbname.]table_name | VARCHAR | Identifier, variable or expression | Table name |
| column_name | VARCHAR | Identifier, variable or expression | Partition column name |
| part_col=filter | Partition filter |
Notes:
- If column name is not specified, the first partition column is used
- Partition filter applied before finding the minimum value
- If the partition contains non-integer values they are ignored
Return Value:
- The minimum INT value for the specified partition
- NULL if the table or partition do not exist, or the table is empty
Return Type:
INT.
Example 1:
Table db.orders is partitioned by country, local_dt and hour and has the following partitions:
| Partitions |
|---|
| country=US/local_dt=2014-12-05/hour=1 |
| country=US/local_dt=2014-12-05/hour=2 |
| country=US/local_dt=2014-12-05/hour=3 |
| country=US/local_dt=2014-12-05/hour=UNKNOWN |
Find the minimum value of the partition hour:
MIN_PART_INT(db.orders, hour);
Result: 1
Example 2:
Table db.sales is partitioned by country, local_date and hour has the following partitions:
| Partitions |
|---|
| country=US/local_dt=2014-12-06/hour=1 |
| country=US/local_dt=2014-12-07/hour=4 |
| country=US/local_dt=2014-12-07/hour=5 |
| country=US/local_dt=2014-12-07/hour=UNKNOWN |
| country=US/local_dt=2014-12-08/hour=3 |
Find the maximum value for hour partition for local_date ‘2014-12-07’:
MIN_PART_IN(db.sales, hour, local_date='2014-12-07');
Result: 4
Compatibility: HPL/SQL extension.
See also: