prestodb/presto · error · PrestoException

HIVE_BAD_DATA

HIVE_BAD_DATA

Error message

RCFile is empty: 

What it means

During createPageSource, if the HiveFileSplit reports fileSize == 0, Presto throws HIVE_BAD_DATA 'RCFile is empty: <path>'. An RCFile cannot be valid with zero length (no header, no metadata), so the connector refuses to open it instead of producing a mysterious decode failure later. This usually means the file was created but never written, or metadata is stale.

Source

Thrown at presto-hive/src/main/java/com/facebook/presto/hive/rcfile/RcFilePageSourceFactory.java:124

            TupleDomain<HiveColumnHandle> effectivePredicate,
            DateTimeZone hiveStorageTimeZone,
            HiveFileContext hiveFileContext,
            Optional<EncryptionInformation> encryptionInformation,
            Optional<byte[]> rowIDPartitionComponent)
    {
        RcFileEncoding rcFileEncoding;
        if (LazyBinaryColumnarSerDe.class.getName().equals(storage.getStorageFormat().getSerDe())) {
            rcFileEncoding = new BinaryRcFileEncoding();
        }
        else if (ColumnarSerDe.class.getName().equals(storage.getStorageFormat().getSerDe())) {
            rcFileEncoding = createTextVectorEncoding(getHiveSchema(storage.getSerdeParameters(), tableParameters), session.getSqlFunctionProperties().isLegacyTimestamp() ? hiveStorageTimeZone : UTC);
        }
        else {
            return Optional.empty();
        }

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

        FSDataInputStream inputStream;
        Path path = new Path(fileSplit.getPath());
        try {
            inputStream = hdfsEnvironment.getFileSystem(session.getUser(), path, configuration).openFile(path, hiveFileContext);
        }
        catch (Exception e) {
            if (nullToEmpty(e.getMessage()).trim().equals("Filesystem closed") ||
                    e instanceof FileNotFoundException) {
                throw new PrestoException(HIVE_CANNOT_OPEN_SPLIT, e);
            }
            throw new PrestoException(HIVE_CANNOT_OPEN_SPLIT, splitError(e, fileSplit), e);
        }

        try {
            ImmutableMap.Builder<Integer, Type> readColumns = ImmutableMap.builder();
            for (HiveColumnHandle column : columns) {

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Inspect the file ('hdfs dfs -ls -h <path>'); if it is a 0-byte artifact of a failed job, delete it and re-run the producing job to regenerate the data.
  2. Repair the partition metadata: 'MSCK REPAIR TABLE' or drop/re-add the partition so it no longer references empty files.
  3. Remove stray placeholder files created with 'hdfs dfs -touchz' from the table location.
  4. Fix the upstream writer to write to a temp path and atomically rename on success so zero-byte files never become visible.
  5. If the file genuinely should have data, check for HDFS under-replication/loss and restore from backup or source.

Example fix

// before: zero-byte file visible to the partition
hdfs dfs -touchz /data/events/ds=20260901/part-0000.rc
// after: delete it and repair the partition
hdfs dfs -rm /data/events/ds=20260901/part-0000.rc
MSCK REPAIR TABLE events;
Defensive patterns

Strategy: validation

Validate before calling

// Before listing/querying a partition, filter out zero-byte files:
FileSystem fs = path.getFileSystem(conf);
for (FileStatus f : fs.listStatus(partitionDir)) {
    if (f.getLen() == 0) {
        log.warn("Skipping/flagging empty file: %s", f.getPath());
        // repair partition or delete placeholder before querying
    }
}

Try / catch

try {
    pageSource = factory.createPageSource(...);
} catch (PrestoException e) {
    if (e.getErrorCode() == HIVE_BAD_DATA.toErrorCode() && e.getMessage().startsWith("RCFile is empty:")) {
        log.warn("Skipping empty file reported by Presto");
        // trigger MSCK REPAIR TABLE / re-ingestion, then retry
    } else {
        throw e;
    }
}

Prevention

When it happens

Trigger: createPageSource is invoked for a split whose fileSplit.getFileSize() returns 0 — a zero-byte file listed in a partition's file list.

Common situations: An upstream job failed after creating the output file but before writing data, HDFS 'touchz' placeholder files left in a partition directory, or stale partition metadata pointing at deleted/emptied files.

Related errors


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