apache/iceberg · error · AlreadyExistsException
Already exists
Error message
Already exists
What it means
InMemoryOutputFile.create() enforces create-new semantics: it throws AlreadyExistsException if the file already exists in the parent InMemoryFileIO. Use createOrOverwrite() when replacing an existing file is intended.
Solutions
- Use createOrOverwrite() instead of create() when the file may legitimately already exist.
- Delete the existing file (io.deleteFile(location)) before create(), or use a unique location per write.
- Catch org.apache.iceberg.exceptions.AlreadyExistsException if the duplicate is expected and should be skipped.
Example fix
// before
OutputFile out = io.newOutputFile(location);
try (PositionOutputStream s = out.create()) { ... } // throws if exists
// after
try (PositionOutputStream s = out.createOrOverwrite()) { ... } Defensive patterns
Strategy: validation
Validate before calling
if (out instanceof InMemoryOutputFile && ((InMemoryOutputFile) out).exists()) { /* delete or use createOrOverwrite */ } Try / catch
try {
out.create();
} catch (AlreadyExistsException e) {
out.createOrOverwrite(); // or skip
} Prevention
- Default to createOrOverwrite() unless strict create-new semantics are required.
- Use unique locations per write attempt in retried tasks.
- Clean up prior outputs before re-running writes to fixed locations.
When it happens
Trigger: Calling InMemoryOutputFile.create() (or outputStream(), which delegates to create()) for a location that already has bytes; writing the same location twice via create(); re-running a task that writes without cleaning up first.
Common situations: Retried test setup that re-creates files at fixed locations; assuming create() overwrites like Hadoop's create(overwrite=true); writing manifest/data files to reused in-memory locations across test runs sharing the static map.
Understand the failure class
Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.
Related errors
- Cannot create namespace
- Cannot rename to . Table already exists
- Namespace already exists
- Namespace already exists
- No in-memory file found for location
AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12).
Data as JSON: /api/errors/814178e6ee2169a2.
Report an issue: GitHub.
Appendix: source
Thrown at core/src/main/java/org/apache/iceberg/inmemory/InMemoryOutputFile.java:68
* files are populated into the parentFileIO through other means).
*
* @param location the location returned by location() of this OutputFile, the InputFile obtained
* from calling toInputFile(), and the location for looking up the associated InputFile from a
* parentFileIO, if non-null.
* @param parentFileIO if non-null, commits an associated InMemoryInputFile on close() into the
* parentFileIO, and uses the parentFileIO for "already exists" checks if creating without
* overwriting.
*/
public InMemoryOutputFile(String location, InMemoryFileIO parentFileIO) {
Preconditions.checkNotNull(location, "location is null");
this.location = location;
this.parentFileIO = parentFileIO;
}
@Override
public PositionOutputStream create() {
if (exists || (parentFileIO != null && parentFileIO.fileExists(location))) {
throw new AlreadyExistsException("Already exists");
}
return createOrOverwrite();
}
@Override
public PositionOutputStream createOrOverwrite() {
exists = true;
contents = new ByteArrayOutputStream();
return new InMemoryPositionOutputStream(contents);
}
@Override
public String location() {
return location;
}
@Override
public InputFile toInputFile() {View on GitHub (pinned to 86d9c8fc54)