Apache Hive : HPL/SQL - MAX_PART_STRING Function

Last updated: August 12, 2026

Apache Hive : HPL/SQL - MAX_PART_STRING Function

MAX_PART_STRING function finds the maximum value (last in alphabetical order) for the specified partition column of type STRING (VARCHAR/CHAR).

Syntax:

MAX_PART_STRING([db_name.]table_name [, column_name [, part_col=filter, ...]]); 

Parameters:

ParameterTypeValueDescription
[dbname.]table_nameVARCHARIdentifier, variable or expressionTable name
column_nameVARCHARIdentifier, variable or expressionPartition column name
part_col=filterPartition filter

Notes:

  • If column name is not specified, the first partition column is used
  • Partition filter applied before finding the maximum value

Return Value:

  • The maximum string for the specified partition
  • NULL if the table or partition do not exist, or the table is empty

Return Type:

STRING (VARCHAR/CHAR).

Example 1:

Table db.orders is partitioned by country and has the following partitions:

Partitions
country=US
country=UK
country=DE

Find the maximum value of the partition:

MAX_PART_STRING(db.orders); 

Result: US

Example 2:

Table db.sales is partitioned by country and local_date and has the following partitions:

Partitions
country=US/local_date=2014-12-02
country=DE/local_date=2014-12-04
country=UK/local_date=2014-12-04

Find the maximum value for country partition column for local_date ‘2014-12-04’:

MAX_PART_STRING(db.sales, country, local_date='2014-12-04'); 

Result: UK

Compatibility: HPL/SQL extension.

See also: