prestodb/presto · error · PrestoException
HIVE_INVALID_METADATA
HIVE_INVALID_METADATA
Error message
Table/partition metadata has invalid sorting order:
What it means
SortingColumn.fromMetastoreApiOrder converts a Hive metastore Order byte value into Presto's SortingColumn.Order enum (ASC/DESC). If the stored sort-order byte does not map to any known HiveOrder value, the metadata is considered corrupt and HIVE_INVALID_METADATA is thrown. This guards against manually edited or foreign metadata in the metastore.
Source
Thrown at presto-hive-metastore/src/main/java/com/facebook/presto/hive/metastore/SortingColumn.java:67
public SortOrder getSortOrder()
{
return sortOrder;
}
public int getHiveOrder()
{
return hiveOrder;
}
public static Order fromMetastoreApiOrder(int value, String tablePartitionName)
{
for (Order order : values()) {
if (value == order.getHiveOrder()) {
return order;
}
}
throw new PrestoException(HIVE_INVALID_METADATA, "Table/partition metadata has invalid sorting order: " + tablePartitionName);
}
}
private final String columnName;
private final Order order;
@JsonCreator
public SortingColumn(
@JsonProperty("columnName") String columnName,
@JsonProperty("order") Order order)
{
this.columnName = requireNonNull(columnName, "columnName is null");
this.order = requireNonNull(order, "order is null");
}
@JsonProperty
public String getColumnName()
{View on GitHub (pinned to 55bb57d202)
Solutions
- Inspect the table/partition SORT_ORDER in the metastore (DESCRIBE FORMATTED or metastore DB) and fix the byte value to 0 or 1
- Drop and re-create the affected table/partition sort order with valid ASC/DESC values
- Restore the metastore entry from backup if corruption is suspected
- If another engine wrote the metadata, align it to Hive-standard sort order encoding
Example fix
// before (corrupt metastore metadata) SORT_ORDER: (col_a, 2) // after SORT_ORDER: (col_a, 1) -- 1 = DESC, 0 = ASC
Defensive patterns
Strategy: validation
Validate before calling
// Validate sort-order bytes before reading table metadata in Presto
for (Order order : storageDescriptor.getSortCols()) {
if (order.getOrder() != 0 && order.getOrder() != 1) {
throw new IllegalArgumentException("bad sort order byte: " + order.getOrder());
}
} Type guard
boolean hasValidSortOrder(byte hiveOrder) {
return hiveOrder == 0 || hiveOrder == 1;
} Try / catch
try {
table.getSortColumns();
} catch (PrestoException e) {
if (e.getErrorCode().getName().equals("HIVE_INVALID_METADATA")) {
// fix SORT_ORDER in metastore to 0 (ASC) or 1 (DESC)
}
throw e;
} Prevention
- Do not hand-edit metastore SORT_ORDER values
- Only use 0/1 for sort order bytes when writing metadata from external tools
- Validate metadata after metastore migrations
- Prefer ASC/DESC keywords in DDL over raw bytes
When it happens
Trigger: Reading table or partition SORT_ORDER metadata whose <column, order> byte is not 0 (ASC) or 1 (DESC) — e.g. metastore data written by another engine or corrupted by manual edits to the SerDe/table properties.
Common situations: Hive tables whose table parameters were hand-edited; metastore populated by third-party tools writing non-standard sort order values; metadata corruption after failed upgrades; partition-level sort info diverging from table-level.
Related errors
- GENERIC_INTERNAL_ERROR
- HIVE_INVALID_METADATA
- HIVE_INVALID_METADATA
- HIVE_INVALID_PARTITION_VALUE
- HIVE_INVALID_METADATA
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/2d423a571e18975c.
Report an issue: GitHub.