{"record":{"id":"e6f7cbd1c845b11a","repo":"prestodb/presto","slug":"hive-partition-schema-mismatch","errorCode":"HIVE_PARTITION_SCHEMA_MISMATCH","errorMessage":"Hive table (%s) is bucketed but partition (%s) is not bucketed","messagePattern":"Hive table \\((.+?)\\) is bucketed but partition \\((.+?)\\) is not bucketed","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-hive/src/main/java/com/facebook/presto/hive/HiveSplitManager.java","lineNumber":640,"sourceCode":"                    }\n                }\n\n                // Verify that the partition schema matches the table schema.\n                // Either adding or dropping columns from the end of the table\n                // without modifying existing partitions is allowed, but every\n                // column that exists in both the table and partition must have\n                // the same type.\n                List<Column> tableColumns = table.getDataColumns();\n                List<Column> partitionColumns = partition.getColumns();\n                if ((tableColumns == null) || (partitionColumns == null)) {\n                    throw new PrestoException(HIVE_INVALID_METADATA, format(\"Table '%s' or partition '%s' has null columns\", tableName, partitionName));\n                }\n                TableToPartitionMapping tableToPartitionMapping = getTableToPartitionMapping(session, resolvedHiveStorageFormat, tableName, partitionName, tableColumns, partitionColumns);\n\n                if (hiveBucketHandle.isPresent() && !hiveBucketHandle.get().isVirtuallyBucketed()) {\n                    Optional<HiveBucketProperty> partitionBucketProperty = partition.getStorage().getBucketProperty();\n                    if (!partitionBucketProperty.isPresent()) {\n                        throw new PrestoException(HIVE_PARTITION_SCHEMA_MISMATCH, format(\n                                \"Hive table (%s) is bucketed but partition (%s) is not bucketed\",\n                                hivePartition.getTableName(),\n                                hivePartition.getPartitionId().getPartitionName()));\n                    }\n                    int tableBucketCount = hiveBucketHandle.get().getTableBucketCount();\n                    int partitionBucketCount = partitionBucketProperty.get().getBucketCount();\n                    List<String> tableBucketColumns = hiveBucketHandle.get().getColumns().stream()\n                            .map(HiveColumnHandle::getName)\n                            .collect(toImmutableList());\n                    List<String> partitionBucketColumns = partitionBucketProperty.get().getBucketedBy();\n                    if (!tableBucketColumns.equals(partitionBucketColumns) || !isBucketCountCompatible(tableBucketCount, partitionBucketCount)) {\n                        throw new PrestoException(HIVE_PARTITION_SCHEMA_MISMATCH, format(\n                                \"Hive table (%s) bucketing (columns=%s, buckets=%s) is not compatible with partition (%s) bucketing (columns=%s, buckets=%s)\",\n                                hivePartition.getTableName(),\n                                tableBucketColumns,\n                                tableBucketCount,\n                                hivePartition.getPartitionId().getPartitionName(),\n                                partitionBucketColumns,","sourceCodeStart":622,"sourceCodeEnd":658,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-hive/src/main/java/com/facebook/presto/hive/HiveSplitManager.java#L622-L658","documentation":"The table is bucketed (a real, non-virtual HiveBucketHandle exists) but one of its partitions has no bucketing property in its storage descriptor. Since bucket-aware reads require every partition to share the table's bucketing, Presto throws HIVE_PARTITION_SCHEMA_MISMATCH to flag the inconsistent partition.","triggerScenarios":"A query over a bucketed partitioned table reaches a partition whose StorageDescriptor lacks SerDe bucketing metadata (bucketCols/bucket count), during computePartitionMetadata.","commonSituations":"Partitions written/added by external jobs (Spark, custom writers) that ignored the table's bucketing; table altered to add bucketing after unbucketed partitions already existed; CTAS/insert overwriting with different settings.","solutions":["Rewrite/insert the offending partitions with the table's bucketing (INSERT OVERWRITE ... with matching bucket settings) so partitions become bucketed.","Remove or repair the unbucketed partitions (ALTER TABLE DROP PARTITION) and re-add them correctly.","If bucketing is not required, unbucket the table definition or disable bucket-aware execution (hive.bucket_execution=false) for these reads.","Ensure all writers to the table honor the declared bucketing."],"exampleFix":"// before\n-- partition dt='2026-09-01' written unbucketed into bucketed table\n// after\nALTER TABLE t DROP PARTITION (dt='2026-09-01');\nINSERT OVERWRITE TABLE t PARTITION (dt='2026-09-01') SELECT ... ; -- with hive.enforce_bucketing / matching bucket count","handlingStrategy":"validation","validationCode":"// verify partition bucketing before bucketed reads\nPartition p = metastore.getPartition(db, table, values);\nboolean bucketed = p != null && p.getStorage().getBucketProperty().isPresent();\nif (!bucketed) { /* repair partition or disable bucket_execution */ }","typeGuard":null,"tryCatchPattern":"catch (PrestoException e) { if (e.getErrorCode().getCode() == HIVE_PARTITION_SCHEMA_MISMATCH.toErrorCode().getCode()) { /* rerun with hive.bucket_execution=false or rewrite the partition */ } else throw e; }","preventionTips":["Ensure all writers (Spark, MR, custom) honor the table's bucketing spec.","If altering a table to add bucketing, rewrite all existing partitions.","Periodically validate partition storage descriptors against the table definition."],"tags":["hive","bucketing","partition","schema-mismatch"],"backgroundTag":"partition-bucketing-mismatch","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"}