{"record":{"id":"7cbfcd3416c6817b","repo":"apache/seatunnel","slug":"unsupported-constraint-type-7cbfcd","errorCode":null,"errorMessage":"Unsupported constraint type: ","messagePattern":"Unsupported constraint type: ","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/catalog/sqlserver/SqlServerCreateTableSqlBuilder.java","lineNumber":266,"sourceCode":"                                            \"`%s` %s\",\n                                            constraintKeyColumn.getColumnName(),\n                                            constraintKeyColumn.getSortType().name());\n                                })\n                        .collect(Collectors.joining(\", \"));\n        String keyName = null;\n        switch (constraintType) {\n            case INDEX_KEY:\n                keyName = \"KEY\";\n                break;\n            case UNIQUE_KEY:\n                keyName = \"UNIQUE KEY\";\n                break;\n            case FOREIGN_KEY:\n                keyName = \"FOREIGN KEY\";\n                // todo:\n                break;\n            default:\n                throw new UnsupportedOperationException(\n                        \"Unsupported constraint type: \" + constraintType);\n        }\n        return String.format(\n                \"%s `%s` (%s)\", keyName, constraintKey.getConstraintName(), indexColumns);\n    }\n}\n","sourceCodeStart":248,"sourceCodeEnd":273,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/catalog/sqlserver/SqlServerCreateTableSqlBuilder.java#L248-L273","documentation":"SqlServerCreateTableSqlBuilder.buildConstraintKeySql() switches over the constraint key type (PRIMARY_KEY, UNIQUE, INDEX, FOREIGN_KEY); any other ConstraintKeyType reaches the default branch and throws UnsupportedOperationException 'Unsupported constraint type: <type>'. Since FOREIGN_KEY is currently a stub ('todo:'), and all known types are covered, this only fires when a new/unknown constraint type flows in — an internal invariant violation.","triggerScenarios":"Generating CREATE TABLE SQL for SQL Server when a ConstraintKey carries a ConstraintKeyType not handled by the switch — typically after the SeaTunnel API adds a new constraint type, or a custom/extended constraint key is passed through to the SQL builder.","commonSituations":"Upgrading SeaTunnel where a new ConstraintKeyType was introduced upstream but the SQL Server SQL builder was not updated; programmatic construction of ConstraintKey with a null or exotic type; auto-generated DDL for a table whose metadata yields an unmapped constraint kind.","solutions":["Check which ConstraintKeyType value hit the default branch (printed in the message).","Upgrade connector-jdbc to a version where the SQL Server builder supports that constraint type, or drop that constraint from the table definition.","Patch buildConstraintKeySql to handle the new type (note FOREIGN_KEY is itself still a todo stub).","As a workaround, generate the table without constraint keys and add them via manual DDL."],"exampleFix":"// before\ncase FOREIGN_KEY:\n    keyName = \"FOREIGN KEY\"; // todo:\n    break;\ndefault:\n    throw new UnsupportedOperationException(\"Unsupported constraint type: \" + constraintType);\n// after\ncase FOREIGN_KEY:\n    keyName = \"FOREIGN KEY\";\n    String refCols = String.join(\", \", constraintKey.getReferenceColumns());\n    return String.format(\"CONSTRAINT `%s` FOREIGN KEY (`%s`) REFERENCES %s(%s)\",\n            constraintKey.getConstraintName(), indexColumns, constraintKey.getReferenceTableName(), refCols);","handlingStrategy":"try-catch","validationCode":"// java\nSet<ConstraintKeyType> supported = EnumSet.of(PRIMARY_KEY, UNIQUE, INDEX);\nif (constraintKeys.stream().anyMatch(k -> !supported.contains(k.getConstraintType()))) {\n    throw new IllegalArgumentException(\"unsupported constraint type for SQLServer DDL generation\");\n}","typeGuard":null,"tryCatchPattern":"// java\ntry {\n    String sql = SqlServerCreateTableSqlBuilder.buildCreateTableSql(table, false);\n} catch (UnsupportedOperationException e) {\n    LOG.warn(\"constraint dropped from DDL: {}\", e.getMessage());\n    // regenerate DDL without constraint keys, apply constraints manually\n}","preventionTips":["Only pass PRIMARY_KEY, UNIQUE or INDEX constraint keys into SQL Server DDL generation (FOREIGN_KEY is a stub).","After upgrading SeaTunnel, diff new ConstraintKeyType values against builder support.","Add foreign keys via manual DDL instead of the builder."],"tags":["sqlserver","ddl","unsupported-operation","constraint"],"backgroundTag":"unsupported-operation","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}