apache/seatunnel · error · UnsupportedOperationException

Unsupported constraint type:

Error message

Unsupported constraint type: 

What it means

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.

Source

Thrown at seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/catalog/sqlserver/SqlServerCreateTableSqlBuilder.java:266

                                            "`%s` %s",
                                            constraintKeyColumn.getColumnName(),
                                            constraintKeyColumn.getSortType().name());
                                })
                        .collect(Collectors.joining(", "));
        String keyName = null;
        switch (constraintType) {
            case INDEX_KEY:
                keyName = "KEY";
                break;
            case UNIQUE_KEY:
                keyName = "UNIQUE KEY";
                break;
            case FOREIGN_KEY:
                keyName = "FOREIGN KEY";
                // todo:
                break;
            default:
                throw new UnsupportedOperationException(
                        "Unsupported constraint type: " + constraintType);
        }
        return String.format(
                "%s `%s` (%s)", keyName, constraintKey.getConstraintName(), indexColumns);
    }
}

View on GitHub (pinned to cf67b549a7)

Solutions

  1. Check which ConstraintKeyType value hit the default branch (printed in the message).
  2. Upgrade connector-jdbc to a version where the SQL Server builder supports that constraint type, or drop that constraint from the table definition.
  3. Patch buildConstraintKeySql to handle the new type (note FOREIGN_KEY is itself still a todo stub).
  4. As a workaround, generate the table without constraint keys and add them via manual DDL.

Example fix

// before
case FOREIGN_KEY:
    keyName = "FOREIGN KEY"; // todo:
    break;
default:
    throw new UnsupportedOperationException("Unsupported constraint type: " + constraintType);
// after
case FOREIGN_KEY:
    keyName = "FOREIGN KEY";
    String refCols = String.join(", ", constraintKey.getReferenceColumns());
    return String.format("CONSTRAINT `%s` FOREIGN KEY (`%s`) REFERENCES %s(%s)",
            constraintKey.getConstraintName(), indexColumns, constraintKey.getReferenceTableName(), refCols);
Defensive patterns

Strategy: try-catch

Validate before calling

// java
Set<ConstraintKeyType> supported = EnumSet.of(PRIMARY_KEY, UNIQUE, INDEX);
if (constraintKeys.stream().anyMatch(k -> !supported.contains(k.getConstraintType()))) {
    throw new IllegalArgumentException("unsupported constraint type for SQLServer DDL generation");
}

Try / catch

// java
try {
    String sql = SqlServerCreateTableSqlBuilder.buildCreateTableSql(table, false);
} catch (UnsupportedOperationException e) {
    LOG.warn("constraint dropped from DDL: {}", e.getMessage());
    // regenerate DDL without constraint keys, apply constraints manually
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10). Data as JSON: /api/errors/7cbfcd3416c6817b. Report an issue: GitHub.