{"record":{"id":"cc93f990271194dd","repo":"apache/seatunnel","slug":"truncate-table-error","errorCode":null,"errorMessage":"truncate table error","messagePattern":"truncate table error","errorType":"exception","errorClass":"org.apache.seatunnel.api.table.catalog.exception.CatalogException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-maxcompute/src/main/java/org/apache/seatunnel/connectors/seatunnel/maxcompute/catalog/MaxComputeCatalog.java","lineNumber":258,"sourceCode":"\n    @Override\n    public void truncateTable(TablePath tablePath, boolean ignoreIfNotExists)\n            throws TableNotExistException, CatalogException {\n        try {\n            Odps odps = getOdps(tablePath.getDatabaseName(), tablePath.getSchemaName());\n            Table odpsTable = odps.tables().get(tablePath.getTableName());\n            if (odpsTable.isPartitioned()\n                    && StringUtils.isNotEmpty(\n                            readonlyConfig.get(MaxcomputeBaseOptions.PARTITION_SPEC))) {\n                PartitionSpec partitionSpec =\n                        new PartitionSpec(readonlyConfig.get(MaxcomputeBaseOptions.PARTITION_SPEC));\n                odpsTable.deletePartition(partitionSpec, ignoreIfNotExists);\n                odpsTable.createPartition(partitionSpec, true);\n            } else {\n                odpsTable.truncate();\n            }\n        } catch (Exception e) {\n            throw new CatalogException(\"truncate table error\", e);\n        }\n    }\n\n    public void createPartition(TablePath tablePath, PartitionSpec partitionSpec) {\n        try {\n            Odps odps = getOdps(tablePath.getDatabaseName(), tablePath.getSchemaName());\n            Table odpsTable = odps.tables().get(tablePath.getTableName());\n            odpsTable.createPartition(partitionSpec, true);\n        } catch (Exception e) {\n            throw new CatalogException(\"create partition error\", e);\n        }\n    }\n\n    public void truncatePartition(TablePath tablePath, PartitionSpec partitionSpec) {\n        try {\n            Odps odps = getOdps(tablePath.getDatabaseName(), tablePath.getSchemaName());\n            Table odpsTable = odps.tables().get(tablePath.getTableName());\n            odpsTable.deletePartition(partitionSpec, true);","sourceCodeStart":240,"sourceCodeEnd":276,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-maxcompute/src/main/java/org/apache/seatunnel/connectors/seatunnel/maxcompute/catalog/MaxComputeCatalog.java#L240-L276","documentation":"MaxComputeCatalog.truncateTable either deletes+recreates a partition or calls odpsTable.truncate(); any Exception is wrapped in a CatalogException with this message. Truncation failed at the SDK level (missing table, bad partition spec, permissions, or transient errors).","triggerScenarios":"truncateTable resolves the odps table; for partitioned tables it calls deletePartition/createPartition with a PartitionSpec; otherwise odpsTable.truncate(). Any of these throws and is rethrown as 'truncate table error'.","commonSituations":"PartitionSpec does not match the table's partition columns; table not found (name/database mismatch); account lacks Alter permission on the table; truncate called on a table type that doesn't support it.","solutions":["Check the cause exception for which SDK call failed","Verify the partition spec column names/values exactly match the table's partition schema","Confirm the table exists and the account has Alter/Write permissions","Manually test the equivalent truncate/delete-partition via odpscmd"],"exampleFix":"// before\nPartitionSpec spec = new PartitionSpec(\"ds='2024-01-01'\");\ncatalog.truncateTable(TablePath.of(\"proj\", \"events\"), spec); // table partitioned by ds,pt\n// after\nPartitionSpec spec = new PartitionSpec(\"ds='2024-01-01', pt='00'\"); // full partition key\ncatalog.truncateTable(TablePath.of(\"proj\", \"events\"), spec);","handlingStrategy":"validation","validationCode":"// verify partition spec matches the table's partition columns before truncating\nTable odpsTable = odps.tables().get(tableName);\nif (odpsTable.getPartitionColumnInfo().stream()\n        .noneMatch(c -> partitionSpec.keys().contains(c.getName()))) {\n    throw new IllegalArgumentException(\"PartitionSpec \" + partitionSpec + \" does not match table partition columns\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    catalog.truncateTable(tablePath, partitionSpec);\n} catch (CatalogException e) {\n    LOG.error(\"Truncate failed for \" + tablePath + \", spec=\" + partitionSpec, e);\n    throw e;\n}","preventionTips":["Describe the table in odpscmd to confirm partition columns before building a PartitionSpec","Confirm the account has Alter/Write permission on the table","For non-partitioned tables, expect truncate() semantics and no PartitionSpec","Wrap catalog mutations in save-mode checks to avoid operating on the wrong table"],"tags":["maxcompute","catalog","truncate","partition"],"backgroundTag":"database-write-failed","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}