{"record":{"id":"72e25488658aa199","repo":"apache/iceberg","slug":"cannot-apply-unknown-unique-constraint-72e254","errorCode":null,"errorMessage":"Cannot apply unknown unique constraint: ","messagePattern":"Cannot apply unknown unique constraint: ","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"flink/v2.2/flink/src/main/java/org/apache/iceberg/flink/util/FlinkAlterTableUtil.java","lineNumber":256,"sourceCode":"      TableChange.After after = (TableChange.After) newPosition;\n      pendingUpdate.moveAfter(modifyColumnPosition.getOldColumn().getName(), after.column());\n    } else {\n      throw new UnsupportedOperationException(\n          \"Cannot apply unknown modify-column-position change: \" + modifyColumnPosition);\n    }\n  }\n\n  private static void applyUniqueConstraint(\n      UpdateSchema pendingUpdate, UniqueConstraint constraint) {\n    switch (constraint.getType()) {\n      case PRIMARY_KEY:\n        pendingUpdate.setIdentifierFields(constraint.getColumns());\n        break;\n      case UNIQUE_KEY:\n        throw new UnsupportedOperationException(\n            \"Unsupported table change: setting unique key constraints.\");\n      default:\n        throw new UnsupportedOperationException(\n            \"Cannot apply unknown unique constraint: \" + constraint.getType().name());\n    }\n  }\n}\n","sourceCodeStart":238,"sourceCodeEnd":261,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/flink/v2.2/flink/src/main/java/org/apache/iceberg/flink/util/FlinkAlterTableUtil.java#L238-L261","documentation":"The default branch of the constraint-type switch fires when UniqueConstraint.getType() returns a value other than PRIMARY_KEY or UNIQUE_KEY — an unknown/unrecognized constraint type enum. It guards against new or foreign constraint types reaching Iceberg's Flink alter logic.","triggerScenarios":"A UniqueConstraint instance with a non-standard/unknown ConstraintType passed into applySchemaChanges (custom Flink fork, version skew adding new enum constants).","commonSituations":"Flink or iceberg-flink version mismatch introducing new constraint enum constants; custom catalog implementations synthesizing constraint objects.","solutions":["Align Flink and iceberg-flink-runtime versions so enum values match","Log constraint.getType().name() and confirm which value is being sent","Extend/handle the new type in a patched applyUniqueConstraint if it must be supported"],"exampleFix":"// before\nUnsupportedOperationException: Cannot apply unknown unique constraint: SOME_NEW_TYPE\n// after\nif (constraint.getType() == ConstraintType.PRIMARY_KEY\n    || constraint.getType() == ConstraintType.UNIQUE_KEY) {\n  applyUniqueConstraint(update, constraint);\n}","handlingStrategy":"validation","validationCode":"ConstraintType t = constraint.getType();\nif (t != ConstraintType.PRIMARY_KEY && t != ConstraintType.UNIQUE_KEY) {\n  throw new IllegalArgumentException(\"Unknown constraint type: \" + t);\n}","typeGuard":"static boolean isKnownConstraintType(UniqueConstraint c) {\n  switch (c.getType()) {\n    case PRIMARY_KEY:\n    case UNIQUE_KEY: return true;\n    default: return false;\n  }\n}","tryCatchPattern":"try { FlinkAlterTableUtil.applySchemaChanges(update, changes); }\ncatch (UnsupportedOperationException e) {\n  if (e.getMessage().startsWith(\"Cannot apply unknown unique constraint\")) { log.error(\"Constraint type mismatch; check versions\"); }\n  throw e;\n}","preventionTips":["Keep Flink and iceberg-flink enum versions in sync","Log constraint types at debug before applying changes","Reject foreign/unknown constraint objects at catalog boundaries"],"tags":["flink","iceberg","enum","unsupported-operation"],"backgroundTag":"invalid-enum-value","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}