{"record":{"id":"5a0df142076f0a92","repo":"prestodb/presto","slug":"hive-writer-data-error","errorCode":"HIVE_WRITER_DATA_ERROR","errorMessage":"Failed to write temporary file: %s","messagePattern":"Failed to write temporary file: (.+?)","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-hive/src/main/java/com/facebook/presto/hive/SortingFileWriter.java","lineNumber":264,"sourceCode":"        catch (IOException e) {\n            throw new UncheckedIOException(e);\n        }\n    }\n\n    private void writeTempFile(Consumer<TempFileWriter> consumer)\n    {\n        Path tempFile = getTempFileName();\n\n        try (TempFileWriter writer = new TempFileWriter(types, tempFileSinkFactory.createSink(fileSystem, tempFile))) {\n            consumer.accept(writer);\n            writer.close();\n            tempFiles.add(new TempFile(tempFile, writer.getWrittenBytes()));\n        }\n        catch (IOException | UncheckedIOException e) {\n            if (!sortedWriteToTempPathEnabled) {\n                cleanupFile(tempFile);\n            }\n            throw new PrestoException(HIVE_WRITER_DATA_ERROR, \"Failed to write temporary file: \" + tempFile, e);\n        }\n    }\n\n    private void cleanupFile(Path file)\n    {\n        try {\n            fileSystem.delete(file, false);\n            if (fileSystem.exists(file)) {\n                throw new IOException(\"Delete failed\");\n            }\n        }\n        catch (IOException e) {\n            log.warn(e, \"Failed to delete temporary file: \" + file);\n        }\n    }\n\n    private Path getTempFileName()\n    {","sourceCodeStart":246,"sourceCodeEnd":282,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-hive/src/main/java/com/facebook/presto/hive/SortingFileWriter.java#L246-L282","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check free space on the temp/spill filesystem and clean up or expand it (disk-full is the most common cause)","Inspect the wrapped cause 'e' in the stack trace for the real failure (permissions, codec, DataNode error)","Verify the Hive staging/temp directory is writable by the Presto process user","Retry the query; if a transient HDFS error caused it, re-running usually succeeds","If a specific compression codec keeps failing, switch the writer compression type"],"exampleFix":"// before: no room on scratch disk, writes fail\nhive.temp-dir=/full/disk/tmp\n// after\nhive.temp-dir=/data/large-volume/presto-tmp  # or free up space on the volume","handlingStrategy":"try-catch","validationCode":"// before running heavy sorts, ensure scratch space exists\nFileSystem fs = FileSystem.get(conf);\nPath tmp = new Path(conf.get(\"hive.tmp-dir\", \"/tmp\"));\nif (fs.getUsed() >= fs.getCapacity() * 0.9) {\n    throw new IllegalStateException(\"Insufficient space on temp filesystem: \" + tmp);\n}","typeGuard":null,"tryCatchPattern":"try {\n    session.execute(query);\n} catch (PrestoException e) {\n    if (HIVE_WRITER_DATA_ERROR.equals(e.getErrorCode().getName())) {\n        // inspect cause; free disk space / check staging dir permissions, then retry\n        logger.warn(\"Hive writer temp file failure: %s\", e.getCause());\n    } else {\n        throw e;\n    }\n}","preventionTips":["Monitor free space on the temp/staging filesystem before large sort queries","Ensure the Presto service user has write access to the staging directory","Keep compression codec native libraries consistent across the cluster","Set alerts for DataNode write errors in the same window as sort-heavy queries"],"tags":["hive","io","writer","disk"],"backgroundTag":"temp-file-write-failure","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}