{"record":{"id":"d3c56563f4b37ce8","repo":"prestodb/presto","slug":"hive-bad-data-d3c565","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/DwrfAggregatedPageSourceFactory.java","lineNumber":87,"sourceCode":"        this.stripeMetadataSourceFactory = requireNonNull(stripeMetadataSourceFactory, \"stripeMetadataSourceFactory is null\");\n    }\n\n    @Override\n    public Optional<? extends ConnectorPageSource> createPageSource(\n            Configuration configuration,\n            ConnectorSession session,\n            HiveFileSplit fileSplit,\n            Storage storage,\n            List<HiveColumnHandle> columns,\n            HiveFileContext hiveFileContext,\n            Optional<EncryptionInformation> encryptionInformation)\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        return Optional.of(createOrcPageSource(\n                session,\n                DWRF,\n                hdfsEnvironment,\n                configuration,\n                fileSplit,\n                columns,\n                isUseOrcColumnNames(session),\n                typeManager,\n                functionResolution,\n                stats,\n                orcFileTailSource,\n                stripeMetadataSourceFactory,\n                hiveFileContext,\n                encryptionInformation,\n                NO_ENCRYPTION,","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-hive/src/main/java/com/facebook/presto/hive/orc/DwrfAggregatedPageSourceFactory.java#L69-L105","documentation":"DwrfAggregatedPageSourceFactory.createPageSource validates the split before creating the ORC reader. If the file size is 0 it throws PrestoException with HIVE_BAD_DATA because a zero-byte file cannot be a valid ORC/DWRF file. The serDe check first ensures this factory is the right one for ORC SerDe tables.","triggerScenarios":"Querying a Hive ORC (DWRF) table partition whose underlying file has fileSize == 0 — e.g., an empty file created by a failed job or by tools that create zero-length placeholders.","commonSituations":"Empty files left by aborted/failed ETL jobs; HDFS files created via 'touch' or recreate-then-write patterns that failed mid-way; partition added to metastore before data was written.","solutions":["Locate and remove the zero-byte file: hadoop fs -ls <path> and hadoop fs -rm the empty file","Repair the partition (MSCK REPAIR TABLE or re-run the writing job) so valid data replaces the empty file","If empty files are expected, upgrade Presto — newer versions skip zero-length ORC files instead of failing"],"exampleFix":"// before\n-- query fails: ORC file is empty: hdfs://.../part-0000\n\n// after (remove empty file, then query)\n-- hadoop fs -rm hdfs://.../part-0000\n-- hadoop fs -touchz is NOT a valid fix for ORC partitions\nSELECT * FROM my_orc_table;","handlingStrategy":"validation","validationCode":"# before querying, ensure no zero-byte ORC files\nhadoop fs -ls -R /warehouse/my_table | awk '$5 == 0 {print $NF}'","typeGuard":null,"tryCatchPattern":"try {\n    return query(sql);\n} catch (PrestoException e) {\n    if (e.getErrorCode().getName().equals(\"HIVE_BAD_DATA\")\n        && String.valueOf(e.getMessage()).startsWith(\"ORC file is empty:\")) {\n        String path = extractPath(e.getMessage());\n        hdfs.remove(path); // or quarantine, then repair partition\n        return query(sql);\n    }\n    throw e;\n}","preventionTips":["Make ETL jobs write to a temp path then atomically rename into the partition","Monitor table directories for zero-length files as part of data quality checks","Avoid `touch`/placeholder files inside ORC table locations","Only register partitions in the metastore after data is fully written"],"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-12T02:17:10.037Z"}