{"record":{"id":"558f4e18afc231ac","repo":"prestodb/presto","slug":"hive-bad-data-558f4e","errorCode":"HIVE_BAD_DATA","errorMessage":"ORC file is empty: ","messagePattern":"ORC file is empty: ","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-hive/src/main/java/com/facebook/presto/hive/orc/DwrfSelectivePageSourceFactory.java","lineNumber":118,"sourceCode":"            List<HiveColumnHandle> columns,\n            Map<Integer, String> prefilledValues,\n            Map<Integer, HiveCoercer> coercers,\n            Optional<BucketAdaptation> bucketAdaptation,\n            List<Integer> outputColumns,\n            TupleDomain<Subfield> domainPredicate,\n            RowExpression remainingPredicate,\n            DateTimeZone hiveStorageTimeZone,\n            HiveFileContext hiveFileContext,\n            Optional<EncryptionInformation> encryptionInformation,\n            boolean appendRowNumberEnabled,\n            Optional<byte[]> rowIDPartitionComponent)\n    {\n        if (!OrcSerde.class.getName().equals(storage.getStorageFormat().getSerDe())) {\n            return Optional.empty();\n        }\n\n        if (fileSplit.getFileSize() == 0) {\n            throw new PrestoException(HIVE_BAD_DATA, \"ORC file is empty: \" + fileSplit.getPath());\n        }\n\n        checkRowIDPartitionComponent(columns, rowIDPartitionComponent);\n\n        return Optional.of(createOrcPageSource(\n                session,\n                DWRF,\n                hdfsEnvironment,\n                configuration,\n                fileSplit,\n                columns,\n                prefilledValues,\n                coercers,\n                bucketAdaptation,\n                outputColumns,\n                domainPredicate,\n                remainingPredicate,\n                false,","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-hive/src/main/java/com/facebook/presto/hive/orc/DwrfSelectivePageSourceFactory.java#L100-L136","documentation":"DwrfSelectivePageSourceFactory.createPageSource performs the same zero-length-file check for selective (row-level filtered) ORC scans, throwing PrestoException(HIVE_BAD_DATA) when fileSplit.getFileSize() == 0. After this check it also validates the rowID partition component before building the reader.","triggerScenarios":"Selective scan (with pushed-down filters or rowId usage) on an ORC/DWRF table where the assigned split's file is 0 bytes.","commonSituations":"Empty files from failed/partial writes; tables ingested by streaming writers that create the file but crash before the first flush; stale partitions pointing at cleaned directories.","solutions":["Remove the empty file: hadoop fs -rm <empty-file-path>","Re-run the producer job to write real data, then refresh the partition","Verify table location contents: hadoop fs -ls -R <table-location> | grep for 0-size files"],"exampleFix":"// before\nSELECT * FROM t WHERE ds = '2026-01-01'; -- ORC file is empty: /warehouse/t/ds=2026-01-01/f\n\n// after\n-- hadoop fs -rm /warehouse/t/ds=2026-01-01/f\n-- ALTER TABLE t DROP PARTITION (ds='2026-01-01'); then re-add after data lands\nSELECT * FROM t WHERE ds = '2026-01-01';","handlingStrategy":"validation","validationCode":"# verify selective-scan table location has no empty files\nhadoop fs -ls -R /warehouse/t/ | awk '$5 == 0 {print $NF}'","typeGuard":null,"tryCatchPattern":"try {\n    return selectiveScan(sql, filters);\n} catch (PrestoException e) {\n    if (e.getErrorCode().getName().equals(\"HIVE_BAD_DATA\")\n        && e.getMessage().startsWith(\"ORC file is empty:\")) {\n        purgeEmptyFiles(tableLocation);\n        return selectiveScan(sql, filters);\n    }\n    throw e;\n}","preventionTips":["Guarantee streaming writers flush initial data or close/delete the file on failure","Register partitions only after writer commit succeeds","Alert on zero-byte files in actively queried partitions"],"tags":["orc","hive","empty-file","hdfs","bad-data"],"backgroundTag":"orc-empty-file","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"}