{"record":{"id":"44151b764564ec6c","repo":"prestodb/presto","slug":"hive-cursor-error","errorCode":"HIVE_CURSOR_ERROR","errorMessage":"Failed to read ORC file: %s","messagePattern":"Failed to read ORC file: (.+?)","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-hive/src/main/java/com/facebook/presto/hive/orc/OrcBatchPageSource.java","lineNumber":214,"sourceCode":"                    blocks[fieldId] = constantBlocks[fieldId].getRegion(0, batchSize);\n                }\n                else {\n                    blocks[fieldId] = new LazyBlock(batchSize, new OrcBlockLoader(hiveColumnIndexes[fieldId]));\n                }\n            }\n            return new Page(batchSize, blocks);\n        }\n        catch (PrestoException e) {\n            closeWithSuppression(e);\n            throw e;\n        }\n        catch (OrcCorruptionException e) {\n            closeWithSuppression(e);\n            throw new PrestoException(HIVE_BAD_DATA, e);\n        }\n        catch (IOException | RuntimeException e) {\n            closeWithSuppression(e);\n            throw new PrestoException(HIVE_CURSOR_ERROR, format(\"Failed to read ORC file: %s\", orcDataSource.getId()), e);\n        }\n    }\n\n    @Override\n    public void close()\n    {\n        // some hive input formats are broken and bad things can happen if you close them multiple times\n        if (closed) {\n            return;\n        }\n        closed = true;\n\n        try {\n            stats.addMaxCombinedBytesPerRow(recordReader.getMaxCombinedBytesPerRow());\n            recordReader.close();\n        }\n        catch (IOException e) {\n            throw new UncheckedIOException(e);","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-hive/src/main/java/com/facebook/presto/hive/orc/OrcBatchPageSource.java#L196-L232","documentation":"OrcBatchPageSource.getNextPage converts OrcCorruptionException to HIVE_BAD_DATA, but any other IOException or RuntimeException during record-set advancement closes the source and is wrapped as PrestoException(HIVE_CURSOR_ERROR) with the ORC data source id. This is the connector's generic 'the cursor hit a failure while reading this file' signal.","triggerScenarios":"getNextPage -> recordSet.advanceNextPosition() throws IOException or RuntimeException that is not OrcCorruptionException (e.g., EOF from truncated file, HdfsOrcDataSource PrestoExceptions bubbling, NPEs, OOM).","commonSituations":"Truncated files whose postscript/stripes cut off; transient HDFS read failures during long scans; faulty writer output causing unexpected runtime errors; worker memory exhaustion reading wide rows.","solutions":["Read the `cause` of the HIVE_CURSOR_ERROR to get the real underlying problem","Validate file integrity: hdfs fsck and try reading the file with a Hive/ORC tooling (orc-tools dump)","Re-run the query if the cause was transient HDFS I/O (coexists with HIVE_FILESYSTEM_ERROR causes)","Replace/regenerate corrupt or truncated files; rewrite with orc-tools if the writer produced bad metadata"],"exampleFix":"// before\nSELECT * FROM t; -- HIVE_CURSOR_ERROR: Failed to read ORC file: hdfs://.../part-0 (cause: EOFException)\n\n// after\n-- java -jar orc-tools-*.jar dump /warehouse/t/part-0  # verify readability\n-- regenerate part-0 from the upstream job\nSELECT * FROM t;","handlingStrategy":"try-catch","validationCode":"# verify file readability outside Presto first\nhadoop jar orc-tools-*.jar meta /warehouse/t/part-0\nhdfs fsck /warehouse/t/part-0 -blocks","typeGuard":null,"tryCatchPattern":"try {\n    return query(sql);\n} catch (PrestoException e) {\n    if (e.getErrorCode().getName().equals(\"HIVE_CURSOR_ERROR\")) {\n        // inspect e.getCause() for the real IOException/RuntimeException\n        logRootCause(e.getCause());\n        return query(sql); // retry only if cause was transient IO\n    }\n    throw e;\n}","preventionTips":["Always check e.getCause() — HIVE_CURSOR_ERROR is a wrapper, not a diagnosis","Validate newly written ORC files with orc-tools before publishing partitions","Monitor for truncated files (writes interrupted) in table locations","Ensure worker memory is sufficient for the column widths being read"],"tags":["orc","hive","cursor-error","corruption","read"],"backgroundTag":"orc-cursor-read-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"}