{"record":{"id":"925692d1a09ed3db","repo":"prestodb/presto","slug":"hive-unknown-column-statistic-type","errorCode":"HIVE_UNKNOWN_COLUMN_STATISTIC_TYPE","errorMessage":"Unknown column statistics type: ","messagePattern":"Unknown column statistics type: ","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-hive-metastore/src/main/java/com/facebook/presto/hive/metastore/Statistics.java","lineNumber":277,"sourceCode":"                    break;\n                case TOTAL_SIZE_IN_BYTES:\n                    result.setTotalSizeInBytes(0);\n                    break;\n                case NUMBER_OF_DISTINCT_VALUES:\n                    result.setDistinctValuesCount(0);\n                    break;\n                case NUMBER_OF_NON_NULL_VALUES:\n                    result.setNullsCount(0);\n                    break;\n                case NUMBER_OF_TRUE_VALUES:\n                    result.setBooleanStatistics(new BooleanStatistics(OptionalLong.of(0L), OptionalLong.of(0L)));\n                    break;\n                case MIN_VALUE:\n                case MAX_VALUE:\n                    setMinMaxForEmptyPartition(columnType, result);\n                    break;\n                default:\n                    throw new PrestoException(HIVE_UNKNOWN_COLUMN_STATISTIC_TYPE, \"Unknown column statistics type: \" + columnStatisticType.name());\n            }\n        }\n        return result.build();\n    }\n\n    private static void setMinMaxForEmptyPartition(Type type, HiveColumnStatistics.Builder result)\n    {\n        if (type.equals(BIGINT) || type.equals(INTEGER) || type.equals(SMALLINT) || type.equals(TINYINT)) {\n            result.setIntegerStatistics(new IntegerStatistics(OptionalLong.empty(), OptionalLong.empty()));\n        }\n        else if (type.equals(DOUBLE) || type.equals(REAL)) {\n            result.setDoubleStatistics(new DoubleStatistics(OptionalDouble.empty(), OptionalDouble.empty()));\n        }\n        else if (type.equals(DATE)) {\n            result.setDateStatistics(new DateStatistics(Optional.empty(), Optional.empty()));\n        }\n        else if (type.equals(TIMESTAMP)) {\n            result.setIntegerStatistics(new IntegerStatistics(OptionalLong.empty(), OptionalLong.empty()));","sourceCodeStart":259,"sourceCodeEnd":295,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-hive-metastore/src/main/java/com/facebook/presto/hive/metastore/Statistics.java#L259-L295","documentation":"When building HiveColumnStatistics for an empty partition, Statistics.createColumnStatisticsForEmptyPartition maps each recorded column statistic type (from the metastore) to a builder call. Unknown enum values hit the default branch and throw HIVE_UNKNOWN_COLUMN_STATISTIC_TYPE, meaning the metastore returned a statistic type this Presto version does not understand.","triggerScenarios":"Running ANALYZE or reading stats on a partition with no rows where columnStatistics encounters a ColumnStatisticType not handled by the switch (e.g. metadata written by a newer Presto/Hive version with additional statistic kinds).","commonSituations":"Mixed-version clusters where a newer coordinator wrote stats and an older metastore/reader reads them; stats left behind after a Presto downgrade; foreign tools writing metastore statistics.","solutions":["Upgrade Presto to a version that recognizes the statistic type in the metastore","Drop and recompute statistics: call ANALYZE on the table after clearing stale stats from the metastore","Remove the unknown statistic entries directly from the metastore (TAB_COL_STATS table)","Pin all Presto nodes to the same version to avoid mixed-statistic writers"],"exampleFix":"// before: older Presto reading stats written by newer version\n-- HIVE_UNKNOWN_COLUMN_STATISTIC_TYPE: Unknown column statistics type: XYZ\n// after: upgrade coordinator/workers to matching version, then\nANALYZE TABLE t COMPUTE STATISTICS;","handlingStrategy":"try-catch","validationCode":"// Check metastore stats for unrecognized statistic types before ANALYZE/read\nSet<String> known = Set.of(\"NUMBER_OF_DISTINCT_VALUES\",\"MIN_VALUE\",\"MAX_VALUE\",\"NUMBER_OF_TRUE_VALUES\", ...);\ncolStats.stream().filter(s -> !known.contains(s.getStatisticType())).forEach(s -> log.warn(\"unknown stat: \" + s));","typeGuard":null,"tryCatchPattern":"try {\n    metastoreMetadata.getSessionProperty(...); // triggers stats read\n} catch (PrestoException e) {\n    if (e.getErrorCode().getName().equals(\"HIVE_UNKNOWN_COLUMN_STATISTIC_TYPE\")) {\n        // purge TAB_COL_STATS rows for the table and rerun ANALYZE\n    }\n    throw e;\n}","preventionTips":["Keep all Presto nodes and metastore clients on the same version","Purge stale column stats after downgrades","Avoid writing statistics with tools incompatible with your Presto version","Re-run ANALYZE after upgrades to regenerate stats in a known format"],"tags":["hive","statistics","metastore","version-mismatch"],"backgroundTag":"unknown-column-statistic-type","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"}