{"record":{"id":"5131504d34a2b939","repo":"prestodb/presto","slug":"table-is-partitioned","errorCode":null,"errorMessage":"Table is partitioned","messagePattern":"Table is partitioned","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-hive-metastore/src/main/java/com/facebook/presto/hive/metastore/SemiTransactionalHiveMetastore.java","lineNumber":610,"sourceCode":"                        session.getClientInfo(),\n                        session.getClientTags(),\n                        session.getSource(),\n                        getMetastoreHeaders(session),\n                        isUserDefinedTypeEncodingEnabled(session),\n                        columnConverterProvider,\n                        session.getWarningCollector(),\n                        session.getRuntimeStats()),\n                databaseName,\n                tableName);\n        SchemaTableName schemaTableName = new SchemaTableName(databaseName, tableName);\n        if (!table.isPresent()) {\n            throw new TableNotFoundException(schemaTableName);\n        }\n        if (!table.get().getTableType().equals(MANAGED_TABLE) && !table.get().getTableType().equals(MATERIALIZED_VIEW)) {\n            throw new PrestoException(NOT_SUPPORTED, \"Cannot delete from non-managed Hive table\");\n        }\n        if (!table.get().getPartitionColumns().isEmpty()) {\n            throw new IllegalArgumentException(\"Table is partitioned\");\n        }\n\n        Path path = new Path(table.get().getStorage().getLocation());\n        HdfsContext context = new HdfsContext(session, databaseName, tableName, table.get().getStorage().getLocation(), false);\n        setExclusive((delegate, hdfsEnvironment) -> {\n            RecursiveDeleteResult recursiveDeleteResult = recursiveDeleteFiles(hdfsEnvironment, context, path, ImmutableSet.of(\"\"), false);\n            if (!recursiveDeleteResult.getNotDeletedEligibleItems().isEmpty()) {\n                throw new PrestoException(HIVE_FILESYSTEM_ERROR, format(\n                        \"Error deleting from unpartitioned table %s. These items can not be deleted: %s\",\n                        schemaTableName,\n                        recursiveDeleteResult.getNotDeletedEligibleItems()));\n            }\n            return EMPTY_HIVE_COMMIT_HANDLE;\n        });\n    }\n\n    public Optional<List<PartitionNameWithVersion>> getPartitionNames(MetastoreContext metastoreContext, String databaseName, String tableName)\n    {","sourceCodeStart":592,"sourceCodeEnd":628,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-hive-metastore/src/main/java/com/facebook/presto/hive/metastore/SemiTransactionalHiveMetastore.java#L592-L628","documentation":"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.","triggerScenarios":"Calling DELETE FROM <partitioned hive table> (full-table delete) or directly invoking truncateUnpartitionedTable on a table whose getPartitionColumns() is non-empty.","commonSituations":"Generic cleanup jobs that call DELETE without checking partitioning; schema evolved from unpartitioned to partitioned while code assumed otherwise; tests using partitioned fixtures.","solutions":["Use partition-level drop: ALTER TABLE t DROP PARTITION (...) for the partitions you want removed","Delete with a WHERE clause on partition columns so the engine can prune and drop whole partitions","Choose a different table or repartition/denormalize if full truncation is truly required"],"exampleFix":"// before\nDELETE FROM events; // events partitioned by day\n// after\nALTER TABLE events DROP PARTITION (day = '2026-09-01');","handlingStrategy":"validation","validationCode":"Optional<Table> t = metastore.getTable(metastoreContext, db, tbl);\nif (t.isPresent() && !t.get().getPartitionColumns().isEmpty()) {\n    throw new IllegalStateException(\"Use ALTER TABLE DROP PARTITION for partitioned table \" + db + \".\" + tbl);\n}","typeGuard":"boolean isUnpartitioned(Table t) { return t.getPartitionColumns().isEmpty(); }","tryCatchPattern":"try {\n    metastore.truncateUnpartitionedTable(session, db, tbl);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().equals(\"Table is partitioned\")) {\n        // switch to partition-drop flow\n    } else throw e;\n}","preventionTips":["Check getPartitionColumns().isEmpty() before truncating","Use partition eviction instead of full-table DELETE for partitioned tables","Keep table layout metadata in sync with job assumptions"],"tags":["hive","partitioned-table","illegal-argument","delete"],"backgroundTag":"table-is-partitioned","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}