{"record":{"id":"93694e336819309d","repo":"apache/iceberg","slug":"cannot-apply-unknown-unique-constraint","errorCode":null,"errorMessage":"Cannot apply unknown unique constraint: ","messagePattern":"Cannot apply unknown unique constraint: ","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"flink/v1.20/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/v1.20/flink/src/main/java/org/apache/iceberg/flink/util/FlinkAlterTableUtil.java#L238-L261","documentation":"applyUniqueConstraint exhaustively switches over ConstraintType; if a new or unrecognized constraint type arrives (not PRIMARY_KEY or UNIQUE_KEY), the default branch throws UnsupportedOperationException naming the unknown type. This guards against enum values added by a newer Flink runtime being applied by an older Iceberg Flink module (or vice versa).","triggerScenarios":"Calling applySchemaChanges with a UniqueConstraint whose getType() returns an enum constant unknown to this code path — typically after a Flink/Iceberg version mismatch introducing a new ConstraintType.","commonSituations":"Mixing Iceberg flink-runtime jar version with a different Flink version; custom Catalog implementations feeding synthetic constraints; library upgrades that add enum constants without updating this switch.","solutions":["Align the iceberg-flink-runtime version with the Flink version in use (e.g. use the flink/vX.Y module matching your Flink major.minor)","Log/inspect constraint.getType().name() to identify the unexpected enum value","Upgrade both Iceberg and Flink together so all ConstraintType values are handled","If you maintain a fork, add a case for the new constraint type or translate it to a supported change"],"exampleFix":"// before (version skew)\nflink 1.20 + iceberg-flink-runtime-1.19.jar\n// after\nflink 1.20 + iceberg-flink-runtime-1.20.jar (versions aligned)","handlingStrategy":"validation","validationCode":"Set<String> known = Set.of(\"PRIMARY_KEY\", \"UNIQUE_KEY\");\nif (!known.contains(constraint.getType().name())) {\n  throw new IllegalStateException(\"ConstraintType \" + constraint.getType().name()\n    + \" unknown to this iceberg-flink version; check version alignment\");\n}","typeGuard":"null","tryCatchPattern":"try {\n  applySchemaChanges(changes);\n} catch (UnsupportedOperationException e) {\n  if (e.getMessage().startsWith(\"Cannot apply unknown unique constraint\")) {\n    throw new IllegalStateException(\"Flink/Iceberg version mismatch on ConstraintType; align module versions\", e);\n  }\n  throw e;\n}","preventionTips":["Keep iceberg-flink-runtime version matched to your Flink major.minor","Upgrade Flink and Iceberg in lockstep","After upgrades, run a smoke ALTER against a test table before production"],"tags":["flink","iceberg","enum","version-mismatch"],"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-14T11:17:12.474Z"}