{"record":{"id":"5d2235436df5af12","repo":"prestodb/presto","slug":"error-encoding-historicalplanstatistics-value","errorCode":null,"errorMessage":"Error encoding historicalPlanStatistics value","messagePattern":"Error encoding historicalPlanStatistics value","errorType":"exception","errorClass":"RedisProviderSerdeException","httpStatus":null,"severity":"error","filePath":"redis-hbo-provider/src/main/java/com/facebook/presto/statistic/HistoricalStatisticsSerde.java","lineNumber":66,"sourceCode":"    }\n\n    @Override\n    public ByteBuffer encodeKey(String key)\n    {\n        return ByteBuffer.wrap(key.getBytes(StandardCharsets.UTF_8));\n    }\n\n    @Override\n    public ByteBuffer encodeValue(HistoricalPlanStatistics historicalPlanStatistics)\n    {\n        ThriftCodec<HistoricalPlanStatistics> writeCodec = thriftCodecManager.getCodec(HistoricalPlanStatistics.class);\n        SliceOutput dynamicSliceOutput = new DynamicSliceOutput(ESTIMATED_BUFFER_SIZE_BYTES);\n        try {\n            ThriftProtocolUtils.write(historicalPlanStatistics, writeCodec, Protocol.BINARY, dynamicSliceOutput);\n            return ByteBuffer.wrap(dynamicSliceOutput.slice().getBytes());\n        }\n        catch (ThriftProtocolException e) {\n            throw new RedisProviderSerdeException(\"Error encoding historicalPlanStatistics value\", e);\n        }\n    }\n\n    @Override\n    public HistoricalPlanStatistics decodeValue(ByteBuffer byteBuffer)\n    {\n        ThriftCodec<HistoricalPlanStatistics> readCodec = thriftCodecManager.getCodec(HistoricalPlanStatistics.class);\n        try {\n            return ThriftProtocolUtils.read(readCodec, Protocol.BINARY, Slices.wrappedBuffer(byteBuffer).getInput());\n        }\n        catch (ThriftProtocolException e) {\n            throw new RedisProviderSerdeException(\"Error decoding historicalPlanStatistics value\", e);\n        }\n    }\n}\n","sourceCodeStart":48,"sourceCodeEnd":82,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/redis-hbo-provider/src/main/java/com/facebook/presto/statistic/HistoricalStatisticsSerde.java#L48-L82","documentation":"HistoricalStatisticsSerde.encodeValue serializes HistoricalPlanStatistics with a Thrift binary protocol writer into a DynamicSliceOutput. If ThriftProtocolUtils.write throws ThriftProtocolException (malformed object, incompatible schema, null required fields), the method wraps it in RedisProviderSerdeException with this message.","triggerScenarios":"Calling encodeValue with a HistoricalPlanStatistics whose schema is incompatible with the configured writeCodec (schema evolution mismatch), or with fields the Thrift writer cannot serialize.","commonSituations":"HBO statistics schema changed between Presto versions so old objects no longer match the write codec; a partially constructed HistoricalPlanStatistics (missing required fields) is passed in; Thrift codec misconfiguration.","solutions":["Check the ThriftProtocolException cause for the specific field/schema mismatch and align the HistoricalPlanStatistics schema with the writeCodec","Regenerate/update Thrift codec classes after a schema version change","Validate the HistoricalPlanStatistics object (required fields present) before encoding","Catch and log at the call site (encodedValue) to avoid losing the whole statistics pipeline"],"exampleFix":"// before\nHistoricalPlanStatistics stats = new HistoricalPlanStatistics(); // required fields unset\nserde.encodeValue(stats);\n// after\nif (stats == null || stats.getPlans() == null) {\n    throw new IllegalArgumentException(\"HistoricalPlanStatistics missing required fields\");\n}\nserde.encodeValue(stats);","handlingStrategy":"try-catch","validationCode":"if (stats == null) throw new IllegalArgumentException(\"historicalPlanStatistics must not be null\");","typeGuard":null,"tryCatchPattern":"try {\n    ByteBuffer encoded = serde.encodeValue(stats);\n} catch (RedisProviderSerdeException e) {\n    log.error(\"Failed to encode HBO stats\", e.getCause());\n    // skip caching this entry rather than failing the query\n}","preventionTips":["Validate required HistoricalPlanStatistics fields before encoding","Keep Thrift schema and codec versions in sync across Presto upgrades","Log the underlying ThriftProtocolException to identify the offending field"],"tags":["redis","thrift","serialization","hbo"],"backgroundTag":"thrift-encode-failure","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"}