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
- 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.
- Repair the partition metadata: 'MSCK REPAIR TABLE' or drop/re-add the partition so it no longer references empty files.
- Remove stray placeholder files created with 'hdfs dfs -touchz' from the table location.
- Fix the upstream writer to write to a temp path and atomically rename on success so zero-byte files never become visible.
- 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
- Write upstream output to temp dirs and atomically rename on job success.
- Never leave 'touchz' placeholders in live table locations.
- Run MSCK REPAIR TABLE (or drop/re-add partitions) after cleaning table directories.
- Add ingestion pipeline checks that fail the job if any output file is 0 bytes.
- Periodically audit partitions for empty files before scheduling queries.
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.