prestodb/presto · error · PrestoException

HIVE_BAD_DATA

HIVE_BAD_DATA

Error message

ORC file is empty: 

What it means

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.

Source

Thrown at presto-hive/src/main/java/com/facebook/presto/hive/orc/DwrfAggregatedPageSourceFactory.java:87

        this.stripeMetadataSourceFactory = requireNonNull(stripeMetadataSourceFactory, "stripeMetadataSourceFactory is null");
    }

    @Override
    public Optional<? extends ConnectorPageSource> createPageSource(
            Configuration configuration,
            ConnectorSession session,
            HiveFileSplit fileSplit,
            Storage storage,
            List<HiveColumnHandle> columns,
            HiveFileContext hiveFileContext,
            Optional<EncryptionInformation> encryptionInformation)
    {
        if (!OrcSerde.class.getName().equals(storage.getStorageFormat().getSerDe())) {
            return Optional.empty();
        }

        if (fileSplit.getFileSize() == 0) {
            throw new PrestoException(HIVE_BAD_DATA, "ORC file is empty: " + fileSplit.getPath());
        }

        return Optional.of(createOrcPageSource(
                session,
                DWRF,
                hdfsEnvironment,
                configuration,
                fileSplit,
                columns,
                isUseOrcColumnNames(session),
                typeManager,
                functionResolution,
                stats,
                orcFileTailSource,
                stripeMetadataSourceFactory,
                hiveFileContext,
                encryptionInformation,
                NO_ENCRYPTION,

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Locate and remove the zero-byte file: hadoop fs -ls <path> and hadoop fs -rm the empty file
  2. Repair the partition (MSCK REPAIR TABLE or re-run the writing job) so valid data replaces the empty file
  3. If empty files are expected, upgrade Presto — newer versions skip zero-length ORC files instead of failing

Example fix

// before
-- query fails: ORC file is empty: hdfs://.../part-0000

// after (remove empty file, then query)
-- hadoop fs -rm hdfs://.../part-0000
-- hadoop fs -touchz is NOT a valid fix for ORC partitions
SELECT * FROM my_orc_table;
Defensive patterns

Strategy: validation

Validate before calling

# before querying, ensure no zero-byte ORC files
hadoop fs -ls -R /warehouse/my_table | awk '$5 == 0 {print $NF}'

Try / catch

try {
    return query(sql);
} catch (PrestoException e) {
    if (e.getErrorCode().getName().equals("HIVE_BAD_DATA")
        && String.valueOf(e.getMessage()).startsWith("ORC file is empty:")) {
        String path = extractPath(e.getMessage());
        hdfs.remove(path); // or quarantine, then repair partition
        return query(sql);
    }
    throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/d3c56563f4b37ce8. Report an issue: GitHub.