prestodb/presto · error · PrestoException

HIVE_WRITER_DATA_ERROR

HIVE_WRITER_DATA_ERROR

Error message

Failed to write temporary file: %s

What it means

SortingFileWriter buffers sorted records and flushes them into temporary spill files on disk. When the underlying writer fails while producing one of those temp files (IOException or UncheckedIOException), Presto wraps the cause in a HIVE_WRITER_DATA_ERROR naming the temp file path. It signals that a data-writing operation inside the Hive writer machinery failed, not a metadata or connectivity problem.

Source

Thrown at presto-hive/src/main/java/com/facebook/presto/hive/SortingFileWriter.java:264

        catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }

    private void writeTempFile(Consumer<TempFileWriter> consumer)
    {
        Path tempFile = getTempFileName();

        try (TempFileWriter writer = new TempFileWriter(types, tempFileSinkFactory.createSink(fileSystem, tempFile))) {
            consumer.accept(writer);
            writer.close();
            tempFiles.add(new TempFile(tempFile, writer.getWrittenBytes()));
        }
        catch (IOException | UncheckedIOException e) {
            if (!sortedWriteToTempPathEnabled) {
                cleanupFile(tempFile);
            }
            throw new PrestoException(HIVE_WRITER_DATA_ERROR, "Failed to write temporary file: " + tempFile, e);
        }
    }

    private void cleanupFile(Path file)
    {
        try {
            fileSystem.delete(file, false);
            if (fileSystem.exists(file)) {
                throw new IOException("Delete failed");
            }
        }
        catch (IOException e) {
            log.warn(e, "Failed to delete temporary file: " + file);
        }
    }

    private Path getTempFileName()
    {

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Check free space on the temp/spill filesystem and clean up or expand it (disk-full is the most common cause)
  2. Inspect the wrapped cause 'e' in the stack trace for the real failure (permissions, codec, DataNode error)
  3. Verify the Hive staging/temp directory is writable by the Presto process user
  4. Retry the query; if a transient HDFS error caused it, re-running usually succeeds
  5. If a specific compression codec keeps failing, switch the writer compression type

Example fix

// before: no room on scratch disk, writes fail
hive.temp-dir=/full/disk/tmp
// after
hive.temp-dir=/data/large-volume/presto-tmp  # or free up space on the volume
Defensive patterns

Strategy: try-catch

Validate before calling

// before running heavy sorts, ensure scratch space exists
FileSystem fs = FileSystem.get(conf);
Path tmp = new Path(conf.get("hive.tmp-dir", "/tmp"));
if (fs.getUsed() >= fs.getCapacity() * 0.9) {
    throw new IllegalStateException("Insufficient space on temp filesystem: " + tmp);
}

Try / catch

try {
    session.execute(query);
} catch (PrestoException e) {
    if (HIVE_WRITER_DATA_ERROR.equals(e.getErrorCode().getName())) {
        // inspect cause; free disk space / check staging dir permissions, then retry
        logger.warn("Hive writer temp file failure: %s", e.getCause());
    } else {
        throw e;
    }
}

Prevention

When it happens

Trigger: writeTempFile() (invoked from flushToTempFile or combineFiles) fails while writing sorted rows to a newly created temporary file; disk full, permission denied on the staging directory, or a codec/compression error while closing the writer.

Common situations: HDFS or local scratch disk out of space during large sorts; misconfigured hive temp/staging directory permissions; compression codec failure (e.g. bad zlib/native codec) when finalizing the temp file; transient DataNode errors mid-write.

Related errors


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