{"record":{"id":"d6b2cb6df7915bc2","repo":"prestodb/presto","slug":"not-found-d6b2cb","errorCode":"NOT_FOUND","errorMessage":"Not Null constraint not found on column %s","messagePattern":"Not Null constraint not found on column (.+?)","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-hive/src/main/java/com/facebook/presto/hive/HiveMetadata.java","lineNumber":3954,"sourceCode":"    {\n        HiveTableHandle hiveTableHandle = (HiveTableHandle) tableHandle;\n        MetastoreContext metastoreContext = getMetastoreContext(session);\n        checkArgument((constraintName.isPresent() && !columnName.isPresent()) || (!constraintName.isPresent() && columnName.isPresent()));\n        String constraintToDrop;\n        if (constraintName.isPresent()) {\n            constraintToDrop = constraintName.get();\n        }\n        else {\n            List<TableConstraint<String>> notNullConstraints = metastore.getTableConstraints(metastoreContext, hiveTableHandle.getSchemaName(), hiveTableHandle.getTableName())\n                    .stream()\n                    .filter(NotNullConstraint.class::isInstance)\n                    .filter(constraint -> constraint.getColumns().stream()\n                            .findFirst()\n                            .orElse(\"\")\n                            .equals(columnName.get()))\n                    .collect(toImmutableList());\n            if (notNullConstraints.isEmpty() || !notNullConstraints.get(0).getName().isPresent()) {\n                throw new PrestoException(NOT_FOUND, format(\"Not Null constraint not found on column %s\", columnName.get()));\n            }\n            constraintToDrop = notNullConstraints.get(0).getName().get();\n        }\n        metastore.dropConstraint(metastoreContext, hiveTableHandle.getSchemaName(), hiveTableHandle.getTableName(), constraintToDrop);\n    }\n\n    @Override\n    public void addConstraint(ConnectorSession session, ConnectorTableHandle tableHandle, TableConstraint<String> tableConstraint)\n    {\n        HiveTableHandle hiveTableHandle = (HiveTableHandle) tableHandle;\n        MetastoreContext metastoreContext = getMetastoreContext(session);\n        metastore.addConstraint(metastoreContext, hiveTableHandle.getSchemaName(), hiveTableHandle.getTableName(), tableConstraint);\n    }\n\n    private enum SystemTableHandler\n    {\n        PARTITIONS, PROPERTIES;\n","sourceCodeStart":3936,"sourceCodeEnd":3972,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-hive/src/main/java/com/facebook/presto/hive/HiveMetadata.java#L3936-L3972","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the column actually has a NOT NULL constraint in Hive (SHOW CREATE TABLE / DESCRIBE) before dropping.","Match the column name casing exactly as registered in the metastore.","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."],"exampleFix":"// before\nALTER TABLE t ALTER COLUMN id DROP NOT NULL; -- constraint already absent\n// after\n-- check first, then only drop if present\nSHOW CREATE TABLE t; -- confirm NOT NULL exists, then:\nALTER TABLE t ALTER COLUMN id DROP NOT NULL;","handlingStrategy":"try-catch","validationCode":"// check the constraint exists before dropping\n// SHOW CREATE TABLE db.t;  -- confirm \"NOT NULL\" on the target column","typeGuard":"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(); }","tryCatchPattern":"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; }","preventionTips":["Confirm the column currently has a NOT NULL constraint before issuing DROP NOT NULL.","Use exact column-name casing as shown by SHOW CREATE TABLE.","Coordinate with other users/tools to avoid double-dropping constraints."],"tags":["hive","constraints","not-null","metastore"],"backgroundTag":"constraint-not-found","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"}