prestodb/presto · error · IllegalArgumentException

Table is partitioned

Error message

Table is partitioned

What it means

truncateUnpartitionedTable only supports unpartitioned tables; when the target table has partition columns it throws a plain IllegalArgumentException("Table is partitioned"). Truncation is implemented by recursively deleting files under a single location, which has no meaning for a partitioned layout.

Source

Thrown at presto-hive-metastore/src/main/java/com/facebook/presto/hive/metastore/SemiTransactionalHiveMetastore.java:610

                        session.getClientInfo(),
                        session.getClientTags(),
                        session.getSource(),
                        getMetastoreHeaders(session),
                        isUserDefinedTypeEncodingEnabled(session),
                        columnConverterProvider,
                        session.getWarningCollector(),
                        session.getRuntimeStats()),
                databaseName,
                tableName);
        SchemaTableName schemaTableName = new SchemaTableName(databaseName, tableName);
        if (!table.isPresent()) {
            throw new TableNotFoundException(schemaTableName);
        }
        if (!table.get().getTableType().equals(MANAGED_TABLE) && !table.get().getTableType().equals(MATERIALIZED_VIEW)) {
            throw new PrestoException(NOT_SUPPORTED, "Cannot delete from non-managed Hive table");
        }
        if (!table.get().getPartitionColumns().isEmpty()) {
            throw new IllegalArgumentException("Table is partitioned");
        }

        Path path = new Path(table.get().getStorage().getLocation());
        HdfsContext context = new HdfsContext(session, databaseName, tableName, table.get().getStorage().getLocation(), false);
        setExclusive((delegate, hdfsEnvironment) -> {
            RecursiveDeleteResult recursiveDeleteResult = recursiveDeleteFiles(hdfsEnvironment, context, path, ImmutableSet.of(""), false);
            if (!recursiveDeleteResult.getNotDeletedEligibleItems().isEmpty()) {
                throw new PrestoException(HIVE_FILESYSTEM_ERROR, format(
                        "Error deleting from unpartitioned table %s. These items can not be deleted: %s",
                        schemaTableName,
                        recursiveDeleteResult.getNotDeletedEligibleItems()));
            }
            return EMPTY_HIVE_COMMIT_HANDLE;
        });
    }

    public Optional<List<PartitionNameWithVersion>> getPartitionNames(MetastoreContext metastoreContext, String databaseName, String tableName)
    {

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Use partition-level drop: ALTER TABLE t DROP PARTITION (...) for the partitions you want removed
  2. Delete with a WHERE clause on partition columns so the engine can prune and drop whole partitions
  3. Choose a different table or repartition/denormalize if full truncation is truly required

Example fix

// before
DELETE FROM events; // events partitioned by day
// after
ALTER TABLE events DROP PARTITION (day = '2026-09-01');
Defensive patterns

Strategy: validation

Validate before calling

Optional<Table> t = metastore.getTable(metastoreContext, db, tbl);
if (t.isPresent() && !t.get().getPartitionColumns().isEmpty()) {
    throw new IllegalStateException("Use ALTER TABLE DROP PARTITION for partitioned table " + db + "." + tbl);
}

Type guard

boolean isUnpartitioned(Table t) { return t.getPartitionColumns().isEmpty(); }

Try / catch

try {
    metastore.truncateUnpartitionedTable(session, db, tbl);
} catch (IllegalArgumentException e) {
    if (e.getMessage().equals("Table is partitioned")) {
        // switch to partition-drop flow
    } else throw e;
}

Prevention

When it happens

Trigger: Calling DELETE FROM <partitioned hive table> (full-table delete) or directly invoking truncateUnpartitionedTable on a table whose getPartitionColumns() is non-empty.

Common situations: Generic cleanup jobs that call DELETE without checking partitioning; schema evolved from unpartitioned to partitioned while code assumed otherwise; tests using partitioned fixtures.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/5131504d34a2b939. Report an issue: GitHub.