{"record":{"id":"d025f85b5ae99aef","repo":"prestodb/presto","slug":"unexpected-row-group-s-in-stripe-at-offset-s","errorCode":null,"errorMessage":"Unexpected row group %s in stripe at offset %s","messagePattern":"Unexpected row group (.+?) in stripe at offset (.+?)","errorType":"exception","errorClass":"OrcCorruptionException","httpStatus":null,"severity":"error","filePath":"presto-orc/src/main/java/com/facebook/presto/orc/OrcWriteValidation.java","lineNumber":447,"sourceCode":"                stack.addAll(orcType.getFieldTypeIndexes());\n            }\n        }\n        return valueNodes.build();\n    }\n\n    public void validateRowGroupStatistics(\n            OrcDataSourceId orcDataSourceId,\n            long stripeOffset,\n            int rowGroupIndex,\n            List<ColumnStatistics> actual)\n            throws OrcCorruptionException\n    {\n        List<RowGroupStatistics> rowGroups = rowGroupStatistics.get(stripeOffset);\n        if (rowGroups == null) {\n            throw new OrcCorruptionException(orcDataSourceId, \"Unexpected stripe at offset %s\", stripeOffset);\n        }\n        if (rowGroups.size() <= rowGroupIndex) {\n            throw new OrcCorruptionException(orcDataSourceId, \"Unexpected row group %s in stripe at offset %s\", rowGroupIndex, stripeOffset);\n        }\n\n        // exclude stats for flat map keys because they are not present in the row group stats\n        ImmutableList.Builder<ColumnStatistics> actualAdjusted = ImmutableList.builder();\n        ImmutableMap.Builder<Integer, ColumnStatistics> actualAdjustedByNode = ImmutableMap.builder();\n        for (int i = 1; i < actual.size(); i++) {\n            if (!flattenedKeyToMapNodes.containsKey(i)) {\n                actualAdjusted.add(actual.get(i));\n                actualAdjustedByNode.put(i, actual.get(i));\n            }\n        }\n\n        RowGroupStatistics expectedRowGroup = rowGroups.get(rowGroupIndex);\n        RowGroupStatistics actualRowGroup = new RowGroupStatistics(BOTH, actualAdjustedByNode.build());\n\n        if (expectedRowGroup.getValidationMode() != HASHED) {\n            Map<Integer, ColumnStatistics> expectedByColumnIndex = expectedRowGroup.getColumnStatistics();\n","sourceCodeStart":429,"sourceCodeEnd":465,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-orc/src/main/java/com/facebook/presto/orc/OrcWriteValidation.java#L429-L465","documentation":"Write validation compares per-row-group statistics recorded at write time to those read back. The recorded stripe has fewer row groups than the row group index requested, so the reader cannot validate that row group and treats the file as corrupt.","triggerScenarios":"validateRowGroupStatistics called with rowGroupIndex >= number of recorded row groups for the stripe at stripeOffset — typically a stripe whose ROW_INDEX entry count changed after write (file modified, corrupted footer/metadata).","commonSituations":"Files post-processed by compaction tools; partial/corrupted writes; reader and writer disagreeing on row-group sizing (different orc-row-group-size defaults).","solutions":["Restore/re-download the file — it was likely modified or corrupted after writing","Re-write the file with the Presto ORC writer","Align row group size settings between writer and reader clusters if validation metadata is version-skewed","Set orc.write-validation=false if reading files from other engines where this metadata is absent"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Ensure row group size matches the writer's setting before enabling validation\n// e.g. writer used 10000 rows per row group\nassert session.getSystemProperty(\"orc_row_group_size\").equals(\"1MB\"); // keep aligned with writer","typeGuard":null,"tryCatchPattern":"try {\n    orcBatchReader.nextPage();\n} catch (OrcCorruptionException e) {\n    if (e.getMessage().contains(\"Unexpected row group\")) {\n        // file metadata altered; re-read with validation off or restore backup\n    }\n}","preventionTips":["Avoid modifying ORC files after writing","Use identical ORC configurations on writer and reader clusters","Verify file integrity after any copy/compaction step","Disable validation for third-party-written files"],"tags":["orc","corruption","write-validation","row-group"],"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"}