apache/iceberg · error · AlreadyExistsException
Cannot create namespace %s because it already exists in Glue
Error message
Cannot create namespace %s because it already exists in Glue
What it means
GlueCatalog.createNamespace throws AlreadyExistsException when Glue's CreateDatabase responds with AlreadyExistsException, i.e. a Glue database with the same name already exists. The library surfaces it because namespaces are unique within a catalog and creating a duplicate would silently overwrite nothing but signals a caller logic problem.
Source
Thrown at aws/src/main/java/org/apache/iceberg/aws/glue/GlueCatalog.java:478
throw e;
}
LOG.info("Successfully renamed table from {} to {}", from, to);
}
@Override
public void createNamespace(Namespace namespace, Map<String, String> metadata) {
try {
glue.createDatabase(
CreateDatabaseRequest.builder()
.catalogId(awsProperties.glueCatalogId())
.databaseInput(
IcebergToGlueConverter.toDatabaseInput(
namespace, metadata, awsProperties.glueCatalogSkipNameValidation()))
.build());
LOG.info("Created namespace: {}", namespace);
} catch (software.amazon.awssdk.services.glue.model.AlreadyExistsException e) {
throw new AlreadyExistsException(
"Cannot create namespace %s because it already exists in Glue", namespace);
}
}
@Override
public List<Namespace> listNamespaces(Namespace namespace) throws NoSuchNamespaceException {
if (!namespace.isEmpty()) {
// if it is not a list all op, just check if the namespace exists and return empty.
if (namespaceExists(namespace)) {
return Lists.newArrayList();
}
throw new NoSuchNamespaceException(
"Glue does not support nested namespace, cannot list namespaces under %s", namespace);
}
// should be safe to list all before returning the list, instead of dynamically load the list.
String nextToken = null;
List<Namespace> results = Lists.newArrayList();View on GitHub (pinned to 86d9c8fc54)
Solutions
- Check `catalog.namespaceExists(namespace)` before calling createNamespace, or treat AlreadyExistsException as success in idempotent setup code.
- Use a create-if-not-exists pattern: catch AlreadyExistsException and continue instead of failing the job.
- Verify you are pointing at the intended Glue catalog ID/region — the name may already exist in the wrong environment.
- If the existing namespace has wrong metadata, drop and recreate it explicitly rather than relying on create.
Example fix
// before
catalog.createNamespace(Namespace.of("analytics"), props);
// after
Namespace ns = Namespace.of("analytics");
if (!catalog.namespaceExists(ns)) {
catalog.createNamespace(ns, props);
} Defensive patterns
Strategy: try-catch
Validate before calling
Namespace ns = Namespace.of("analytics");
if (catalog.namespaceExists(ns)) {
LOG.info("Namespace already exists, skipping create");
} Try / catch
try {
catalog.createNamespace(ns, props);
} catch (AlreadyExistsException e) {
LOG.info("Namespace {} already exists, treating as success", ns);
} Prevention
- Make setup scripts idempotent: check namespaceExists or catch AlreadyExistsException
- Use one owner (single job) for namespace creation in shared environments
- Confirm the target Glue catalog ID/region before creating namespaces
When it happens
Trigger: Calling catalog.createNamespace(Namespace.of("db"), props) when Glue already contains a database named `db`; running idempotent setup scripts twice; two concurrent jobs both creating the same namespace.
Common situations: Initialization scripts that don't check existence first; re-running a failed pipeline from scratch; environment cloning where the namespace was created out-of-band in the AWS console; races between parallel deployments.
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
- Glue does not support nested namespace, cannot list namespac
- invalid input for namespace %s, error message: %s
- fail to find Glue database for namespace %s, error message:
- Cannot drop namespace %s because it still contains Iceberg t
- Cannot drop namespace %s because it still contains non-Icebe
AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12).
Data as JSON: /api/errors/5b2eec67ee718a23.
Report an issue: GitHub.