apache/iceberg · error · UnsupportedOperationException

Cannot add column since setting default values in Spark is…

Error message

Cannot add column %s since setting default values in Spark is currently unsupported

What it means

Thrown when an AddColumn TableChange carries a non-null default value. Iceberg's Spark integration in this version cannot express column DEFAULT values through Spark DDL, so adding a column with a default is rejected rather than silently ignored.

Solutions

  1. Remove the DEFAULT clause from the ADD COLUMN statement
  2. Add the column without a default, then backfill existing data with an UPDATE if a value is needed
  3. Upgrade Iceberg — newer versions may support default values via schema defaults

Example fix

// before
ALTER TABLE t ADD COLUMN c INT DEFAULT 5;
// after
ALTER TABLE t ADD COLUMN c INT;
UPDATE t SET c = 5 WHERE c IS NULL;
Defensive patterns

Strategy: validation

Validate before calling

if (change instanceof TableChange.AddColumn && ((TableChange.AddColumn) change).defaultValue() != null) {
  throw new IllegalArgumentException("Column default values are not supported via Spark");
}

Try / catch

try {
  catalogAlterTable(ident, changes);
} catch (UnsupportedOperationException e) {
  if (e.getMessage().contains("default values in Spark is currently unsupported")) {
    // retry without default, then backfill
  }
}

Prevention

When it happens

Trigger: ALTER TABLE ... ADD COLUMN c INT DEFAULT 5, or building a TableChange.addColumn(...) with a defaultValue via the catalog API on Spark.

Common situations: Porting DDL from engines/database systems that support column defaults (Postgres, Delta with defaults); programmatic catalog code that populates defaultValue.

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/iceberg@86d9c8fc54 (2026-09-12). Data as JSON: /api/errors/8614892142593fd3. Report an issue: GitHub.

Appendix: source

Thrown at spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/Spark3Util.java:252

      TableChange.After after = (TableChange.After) update.position();
      String referenceField = peerName(update.fieldNames(), after.column());
      pendingUpdate.moveAfter(DOT.join(update.fieldNames()), referenceField);

    } else if (update.position() instanceof TableChange.First) {
      pendingUpdate.moveFirst(DOT.join(update.fieldNames()));

    } else {
      throw new IllegalArgumentException("Unknown position for reorder: " + update.position());
    }
  }

  private static void apply(UpdateSchema pendingUpdate, TableChange.AddColumn add) {
    Preconditions.checkArgument(
        add.isNullable(),
        "Incompatible change: cannot add required column: %s",
        leafName(add.fieldNames()));
    if (add.defaultValue() != null) {
      throw new UnsupportedOperationException(
          String.format(
              "Cannot add column %s since setting default values in Spark is currently unsupported",
              leafName(add.fieldNames())));
    }

    Type type = SparkSchemaUtil.convert(add.dataType());
    pendingUpdate.addColumn(
        parentName(add.fieldNames()), leafName(add.fieldNames()), type, add.comment());

    if (add.position() instanceof TableChange.After) {
      TableChange.After after = (TableChange.After) add.position();
      String referenceField = peerName(add.fieldNames(), after.column());
      pendingUpdate.moveAfter(DOT.join(add.fieldNames()), referenceField);

    } else if (add.position() instanceof TableChange.First) {
      pendingUpdate.moveFirst(DOT.join(add.fieldNames()));

    } else {

View on GitHub (pinned to 86d9c8fc54)