{"record":{"id":"d8c48198349e0c19","repo":"prestodb/presto","slug":"unexpected-decimal-type-decimaltype","errorCode":null,"errorMessage":"Unexpected decimal type: ${decimalType}","messagePattern":"Unexpected decimal type: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-hive/src/main/java/com/facebook/presto/hive/statistics/MetastoreHiveStatisticsProvider.java","lineNumber":667,"sourceCode":"    {\n        if (type.equals(BIGINT) || type.equals(INTEGER) || type.equals(SMALLINT) || type.equals(TINYINT)) {\n            return (Long) value;\n        }\n        if (type.equals(DOUBLE)) {\n            return (Double) value;\n        }\n        if (type.equals(REAL)) {\n            return intBitsToFloat(((Long) value).intValue());\n        }\n        if (type instanceof DecimalType) {\n            DecimalType decimalType = (DecimalType) type;\n            if (isShortDecimal(decimalType)) {\n                return parseDouble(Decimals.toString((Long) value, decimalType.getScale()));\n            }\n            if (isLongDecimal(decimalType)) {\n                return parseDouble(Decimals.toString((Slice) value, decimalType.getScale()));\n            }\n            throw new IllegalArgumentException(\"Unexpected decimal type: \" + decimalType);\n        }\n        if (type.equals(DATE)) {\n            return (Long) value;\n        }\n        throw new IllegalArgumentException(\"Unexpected type: \" + type);\n    }\n\n    @VisibleForTesting\n    static ColumnStatistics createDataColumnStatistics(String column, Type type, double rowsCount, Collection<PartitionStatistics> partitionStatistics)\n    {\n        List<HiveColumnStatistics> columnStatistics = partitionStatistics.stream()\n                .map(PartitionStatistics::getColumnStatistics)\n                .map(statistics -> statistics.get(column))\n                .filter(Objects::nonNull)\n                .collect(toImmutableList());\n\n        if (columnStatistics.isEmpty()) {\n            return ColumnStatistics.empty();","sourceCodeStart":649,"sourceCodeEnd":685,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-hive/src/main/java/com/facebook/presto/hive/statistics/MetastoreHiveStatisticsProvider.java#L649-L685","documentation":"convertPartitionValueToDouble converts a partition key's constant value to a double for statistics estimation; when the value's type is a DecimalType that is neither short (<= 64-bit) nor long (<= 128-bit) decimal, it throws IllegalArgumentException 'Unexpected decimal type'. In practice this means the decimal type is out of the supported precision range or the value/type pairing is inconsistent.","triggerScenarios":"Estimating stats over a partition column whose value conversion hits a decimal type where isShortDecimal and isLongDecimal are both false — i.e. a malformed/oversized decimal type reaching the stats path.","commonSituations":"Partition column declared with an unsupported or corrupted decimal precision in the metastore; type-mapping mismatch between Hive decimal and Presto decimal conversions; value stored with a type that no longer matches the schema.","solutions":["Verify the partition column's decimal precision/scale in the metastore and correct it to a valid DECIMAL(p,s)","Recreate the partition/table with a supported DECIMAL declaration","Check the Hive-to-Presto type mapping for decimals and align versions","Change the partition column to a supported type or exclude it from stats estimation"],"exampleFix":"// before (corrupted type)\nDECIMAL(0,0)  // precision out of supported range\n// after\nDECIMAL(10,2)","handlingStrategy":"validation","validationCode":"// validate decimal declaration before use\nDecimalType d = (DecimalType) type;\nboolean supported = d.getPrecision() >= 1\n        && (d.getPrecision() <= Decimals.MAX_SHORT_PRECISION || d.getPrecision() <= Decimals.MAX_PRECISION);\nif (!supported) throw new IllegalArgumentException(\"Unsupported decimal: \" + d);","typeGuard":null,"tryCatchPattern":"try {\n    stats = provider.getTableStatistics(...);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"Unexpected decimal type\")) {\n        // fix partition column DECIMAL(p,s) in the metastore, then re-run ANALYZE\n    } else throw e;\n}","preventionTips":["Declare partition decimals with valid precision/scale (e.g. DECIMAL(10,2))","Verify Hive decimal type mapping matches the Presto version in use","Audit metastore schemas after migrations for malformed decimal types","Re-create affected partitions after correcting the type"],"tags":["hive","statistics","decimal","type-mapping"],"backgroundTag":"unexpected-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"}