{"record":{"id":"26fcb90fdfd03ffe","repo":"prestodb/presto","slug":"hive-corrupted-column-statistics","errorCode":"HIVE_CORRUPTED_COLUMN_STATISTICS","errorMessage":"Corrupted partition statistics (Table: %s Partition: [%s] Column: %s): %s","messagePattern":"Corrupted partition statistics \\(Table: (.+?) Partition: \\[(.+?)\\] Column: (.+?)\\): (.+?)","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-hive/src/main/java/com/facebook/presto/hive/statistics/MetastoreHiveStatisticsProvider.java","lineNumber":413,"sourceCode":"                        rowCount.getAsLong());\n            }\n            if (rowCount.isPresent() && trueCount.isPresent()) {\n                checkStatistics(\n                        trueCount.getAsLong() <= rowCount.getAsLong(),\n                        table,\n                        partition,\n                        column,\n                        \"booleanStatistics.trueCount must be less than or equal to rowCount. booleanStatistics.trueCount: %s. rowCount: %s.\",\n                        trueCount.getAsLong(),\n                        rowCount.getAsLong());\n            }\n        });\n    }\n\n    private static void checkStatistics(boolean expression, SchemaTableName table, String partition, String column, String message, Object... args)\n    {\n        if (!expression) {\n            throw new PrestoException(\n                    HIVE_CORRUPTED_COLUMN_STATISTICS,\n                    format(\"Corrupted partition statistics (Table: %s Partition: [%s] Column: %s): %s\", table, partition, column, format(message, args)));\n        }\n    }\n\n    private static void checkStatistics(boolean expression, SchemaTableName table, String partition, String message, Object... args)\n    {\n        if (!expression) {\n            throw new PrestoException(\n                    HIVE_CORRUPTED_COLUMN_STATISTICS,\n                    format(\"Corrupted partition statistics (Table: %s Partition: [%s]): %s\", table, partition, format(message, args)));\n        }\n    }\n\n    private static TableStatistics getTableStatistics(\n            Map<String, ColumnHandle> columns,\n            Map<String, Type> columnTypes,\n            List<HivePartition> partitions,","sourceCodeStart":395,"sourceCodeEnd":431,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-hive/src/main/java/com/facebook/presto/hive/statistics/MetastoreHiveStatisticsProvider.java#L395-L431","documentation":"A partition-level column statistic from the Hive metastore failed a sanity validation in MetastoreHiveStatisticsProvider.checkStatistics and is considered corrupted. Presto throws HIVE_CORRUPTED_COLUMN_STATISTICS naming table, partition, column and the violated invariant, refusing to use the bogus value for planning.","triggerScenarios":"Reading partition statistics (via validateColumnStatistics / getTableStatistics) where a column stat violates invariants — e.g. NDV less than 1, min > max, nulls count greater than row count, negative sizes.","commonSituations":"Stats corrupted by ANALYZE bugs or old Hive versions; stats written by third-party tools; manually edited metastore metadata; stats from a different column type after a schema change.","solutions":["Recompute statistics: run ANALYZE on the table or drop and refresh partition stats","Delete the offending column stats from the metastore for that partition","Check for Hive/Presto version bugs affecting stat writing and upgrade","Disable stats-dependent planning for that query/session as a workaround"],"exampleFix":"-- before: query fails on corrupted stats\nSELECT * FROM t WHERE p = '2024-01-01';\n-- after: refresh stats then query\nANALYZE TABLE t;\nSELECT * FROM t WHERE p = '2024-01-01';","handlingStrategy":"try-catch","validationCode":"// sanity-check stats yourself before relying on them\nboolean sane = ndv >= 1 && min.compareTo(max) <= 0 && nullsCount <= rowCount && totalSize >= 0;","typeGuard":null,"tryCatchPattern":"try {\n    return session.execute(query);\n} catch (PrestoException e) {\n    if (\"HIVE_CORRUPTED_COLUMN_STATISTICS\".equals(e.getErrorCode().getName())) {\n        runAnalyze(table); // regenerate stats, then retry\n        return session.execute(query);\n    } throw e;\n}","preventionTips":["Run ANALYZE regularly after bulk loads or schema changes","Avoid writing stats with third-party tools that bypass Hive invariants","Verify stats integrity after Hive/metastore version upgrades","Check partition stats after failed compactions"],"tags":["hive","statistics","metastore","presto-exception"],"backgroundTag":"corrupted-statistics","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"}