prestodb/presto · error · PrestoException

NOT_FOUND

NOT_FOUND

Error message

Not Null constraint not found on column %s

What it means

When dropping a NOT NULL constraint (Hive 3 ACID tables), Presto locates the constraint whose column matches the requested column name. If no matching NOT NULL constraint exists in the metastore (or it has no name), HiveMetadata throws NOT_FOUND because there is nothing to drop via metastore.dropConstraint.

Source

Thrown at presto-hive/src/main/java/com/facebook/presto/hive/HiveMetadata.java:3954

    {
        HiveTableHandle hiveTableHandle = (HiveTableHandle) tableHandle;
        MetastoreContext metastoreContext = getMetastoreContext(session);
        checkArgument((constraintName.isPresent() && !columnName.isPresent()) || (!constraintName.isPresent() && columnName.isPresent()));
        String constraintToDrop;
        if (constraintName.isPresent()) {
            constraintToDrop = constraintName.get();
        }
        else {
            List<TableConstraint<String>> notNullConstraints = metastore.getTableConstraints(metastoreContext, hiveTableHandle.getSchemaName(), hiveTableHandle.getTableName())
                    .stream()
                    .filter(NotNullConstraint.class::isInstance)
                    .filter(constraint -> constraint.getColumns().stream()
                            .findFirst()
                            .orElse("")
                            .equals(columnName.get()))
                    .collect(toImmutableList());
            if (notNullConstraints.isEmpty() || !notNullConstraints.get(0).getName().isPresent()) {
                throw new PrestoException(NOT_FOUND, format("Not Null constraint not found on column %s", columnName.get()));
            }
            constraintToDrop = notNullConstraints.get(0).getName().get();
        }
        metastore.dropConstraint(metastoreContext, hiveTableHandle.getSchemaName(), hiveTableHandle.getTableName(), constraintToDrop);
    }

    @Override
    public void addConstraint(ConnectorSession session, ConnectorTableHandle tableHandle, TableConstraint<String> tableConstraint)
    {
        HiveTableHandle hiveTableHandle = (HiveTableHandle) tableHandle;
        MetastoreContext metastoreContext = getMetastoreContext(session);
        metastore.addConstraint(metastoreContext, hiveTableHandle.getSchemaName(), hiveTableHandle.getTableName(), tableConstraint);
    }

    private enum SystemTableHandler
    {
        PARTITIONS, PROPERTIES;

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Verify the column actually has a NOT NULL constraint in Hive (SHOW CREATE TABLE / DESCRIBE) before dropping.
  2. Match the column name casing exactly as registered in the metastore.
  3. If the constraint is already absent, skip the drop; if the metastore record is nameless/corrupt, repair it directly in Hive or recreate the table.

Example fix

// before
ALTER TABLE t ALTER COLUMN id DROP NOT NULL; -- constraint already absent
// after
-- check first, then only drop if present
SHOW CREATE TABLE t; -- confirm NOT NULL exists, then:
ALTER TABLE t ALTER COLUMN id DROP NOT NULL;
Defensive patterns

Strategy: try-catch

Validate before calling

// check the constraint exists before dropping
// SHOW CREATE TABLE db.t;  -- confirm "NOT NULL" on the target column

Type guard

Optional<String> findConstraintName(List<Constraint> constraints, String column) { return constraints.stream().filter(c -> c.getColumns().stream().findFirst().orElse("").equals(column)).map(Constraint::getName).filter(Optional::isPresent).map(Optional::get).findFirst(); }

Try / catch

try { alterTableDropNotNull(...); } catch (PrestoException e) { if (e.getErrorCode().getCode() == StandardErrorCode.NOT_FOUND.getCode() && e.getMessage().contains("Not Null constraint not found")) { /* constraint already absent - treat as success */ } else throw e; }

Prevention

When it happens

Trigger: ALTER TABLE ... DROP NOT NULL on a column that either has no NOT NULL constraint registered, or whose constraint record lacks a name in the metastore; the filter over constraints yields an empty list.

Common situations: Constraint already dropped by another session or directly in Hive; column name mismatch (case sensitivity) between Presto and the metastore constraint record; metastore constraint entries missing names due to version/tooling issues.

Understand the failure class

Background: NOT_FOUND error code: why tRPC, Harbor, Nacos and other libraries return 404 "not found" errors for resources that may still exist — this error's family across 11 libraries.

Related errors


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