{"record":{"id":"bac7d90d2922a4fb","repo":"prestodb/presto","slug":"write-validation-failed-unexpected-number-of-colu-bac7d9","errorCode":null,"errorMessage":"Write validation failed: unexpected number of columns in %s statistics","messagePattern":"Write validation failed: unexpected number of columns in (.+?) statistics","errorType":"exception","errorClass":"OrcCorruptionException","httpStatus":null,"severity":"error","filePath":"presto-orc/src/main/java/com/facebook/presto/orc/OrcWriteValidation.java","lineNumber":511,"sourceCode":"            Type type = readColumns.get(column);\n            checkArgument(type != null, \"statistics validation requires all columns to be read\");\n            types.add(type);\n        }\n        return new StatisticsValidation(types.build());\n    }\n\n    private static void validateColumnStatisticsEquivalent(\n            OrcDataSourceId orcDataSourceId,\n            String name,\n            List<ColumnStatistics> actualColumnStatistics,\n            List<ColumnStatistics> expectedColumnStatistics)\n            throws OrcCorruptionException\n    {\n        requireNonNull(name, \"name is null\");\n        requireNonNull(actualColumnStatistics, \"actualColumnStatistics is null\");\n        requireNonNull(expectedColumnStatistics, \"expectedColumnStatistics is null\");\n        if (actualColumnStatistics.size() != expectedColumnStatistics.size()) {\n            throw new OrcCorruptionException(orcDataSourceId, \"Write validation failed: unexpected number of columns in %s statistics\", name);\n        }\n        for (int i = 0; i < actualColumnStatistics.size(); i++) {\n            ColumnStatistics actual = actualColumnStatistics.get(i);\n            ColumnStatistics expected = expectedColumnStatistics.get(i);\n            validateColumnStatisticsEquivalent(orcDataSourceId, name + \" column \" + i, actual, expected);\n        }\n    }\n\n    private static void validateColumnStatisticsEquivalent(\n            OrcDataSourceId orcDataSourceId,\n            String name,\n            ColumnStatistics actualColumnStatistics,\n            ColumnStatistics expectedColumnStatistics)\n            throws OrcCorruptionException\n    {\n        requireNonNull(name, \"name is null\");\n        requireNonNull(actualColumnStatistics, \"actualColumnStatistics is null\");\n        requireNonNull(expectedColumnStatistics, \"expectedColumnStatistics is null\");","sourceCodeStart":493,"sourceCodeEnd":529,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-orc/src/main/java/com/facebook/presto/orc/OrcWriteValidation.java#L493-L529","documentation":"Write validation compares lists of ColumnStatistics (file, stripe, or row group level) positionally between the statistics recorded at write time and those read from the file. If the two lists differ in length, the column count changed between write and read, so validation cannot proceed and OrcCorruptionException is thrown.","triggerScenarios":"validateColumnStatisticsEquivalent invoked (from validateFileStatistics, validateStripeStatistics, or validateRowGroupStatistics) with actualColumnStatistics.size() != expectedColumnStatistics.size() — the file's statistics metadata contains a different number of columns than the write-time record.","commonSituations":"Schema evolution (columns added/dropped) applied to existing ORC files; files rewritten by another engine with different column flattening; corrupted statistics metadata.","solutions":["Verify the file was not altered or rewritten with a different schema after writing","Re-write the file with the Presto ORC writer using the current schema","Upgrade Presto if a known bug in flattened column statistics counting applies to your version","Disable orc.write-validation when reading files produced by other engines or after schema evolution"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Skip validation when file schema differs from the written schema (schema evolution)\nif (!fileSchema.equals(writerSchema)) {\n    session.setProperty(\"orc_write_validation\", false);\n}","typeGuard":null,"tryCatchPattern":"try {\n    orcReader = new OrcReader(...);\n} catch (OrcCorruptionException e) {\n    if (e.getMessage().contains(\"unexpected number of columns\")) {\n        // re-read with validation disabled; investigate schema evolution\n    }\n}","preventionTips":["Don't apply schema evolution in place to validated ORC files","Write with Presto's writer when validation is on","Verify column count is unchanged after any file transformation","Upgrade Presto to get consistent flattened-column statistics counting"],"tags":["orc","write-validation","statistics","schema"],"backgroundTag":"orc-write-validation-mismatch","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"}