{"record":{"id":"af331d31da95f87b","repo":"prestodb/presto","slug":"unexpected-type-type","errorCode":null,"errorMessage":"Unexpected type: ${type}","messagePattern":"Unexpected type: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-hive/src/main/java/com/facebook/presto/hive/statistics/MetastoreHiveStatisticsProvider.java","lineNumber":672,"sourceCode":"            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();\n        }\n\n        return ColumnStatistics.builder()\n                .setDistinctValuesCount(calculateDistinctValuesCount(columnStatistics))\n                .setNullsFraction(calculateNullsFraction(column, partitionStatistics))","sourceCodeStart":654,"sourceCodeEnd":690,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-hive/src/main/java/com/facebook/presto/hive/statistics/MetastoreHiveStatisticsProvider.java#L654-L690","documentation":"MetastoreHiveStatisticsProvider.convertPartitionValueToDouble converts a raw metastore partition-statistics value into a double for stats aggregation. It only supports BOOLEAN, INTEGER/Bigint-style numeric, DOUBLE, and DATE partitions (plus decimal handled earlier); any other Type reaching the final check means the value's type is not representable as a double, so it throws IllegalArgumentException to fail fast rather than produce wrong statistics.","triggerScenarios":"Calling values()/statistics aggregation over a partition column whose Type is not BOOLEAN, the supported integer family, DOUBLE, or DATE — e.g. VARCHAR, TIMESTAMP, complex types, or a new Hive type whose value arrived from the metastore.","commonSituations":"Partition statistics tables containing columns of unsupported types (strings/timestamps); a Presto version upgrade adding a type the provider's whitelist doesn't cover; misconfigured partition column of type varchar being fed into stats computation.","solutions":["Restrict statistics collection to supported column types (filter unsupported types before calling convertPartitionValueToDouble)","Check the Type whitelist (BOOLEAN, INTEGER/numeric, DOUBLE, DATE) and extend the method if the new type is legitimately needed","Verify the metastore stats schema for the partition column matches the expected types","Upgrade Presto to a version that supports the type in question"],"exampleFix":"// before\ndouble d = MetastoreHiveStatisticsProvider.convertPartitionValueToDouble(varcharType, value); // throws\n// after\nif (type.equals(BOOLEAN) || type instanceof IntegerType || type.equals(DOUBLE) || type.equals(DATE)) {\n    double d = MetastoreHiveStatisticsProvider.convertPartitionValueToDouble(type, value);\n}","handlingStrategy":"validation","validationCode":"private static final Set<Type> SUPPORTED = ImmutableSet.of(BOOLEAN, DOUBLE, DATE, BIGINT, INTEGER, SMALLINT, TINYINT);\nif (!SUPPORTED.contains(type) && !(type instanceof DecimalType)) {\n    throw new IllegalArgumentException(\"Type not convertible to double for stats: \" + type);\n}\ndouble d = MetastoreHiveStatisticsProvider.convertPartitionValueToDouble(type, value);","typeGuard":"boolean isStatsConvertible(Type type) {\n    return type.equals(BOOLEAN) || type.equals(DOUBLE) || type.equals(DATE)\n        || type.equals(BIGINT) || type.equals(INTEGER) || type.equals(SMALLINT)\n        || type.equals(TINYINT) || type instanceof DecimalType;\n}","tryCatchPattern":"try {\n    double d = convertPartitionValueToDouble(type, value);\n} catch (IllegalArgumentException e) {\n    LOG.warn(e.getMessage());\n    // fall back to unknown statistics for this column\n}","preventionTips":["Filter partition-stat columns by supported Type before stats conversion","Keep the supported-type whitelist in one shared constant used by both callers and tests","Log and skip unsupported types instead of letting aggregation crash","Add tests for every Type your tables actually use"],"tags":["hive","statistics","illegal-argument","type-mismatch"],"backgroundTag":"unsupported-type-cast","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"}