apache/iceberg · error · UnsupportedOperationException

Cannot add partition field to non-Iceberg table: $table

Error message

Cannot add partition field to non-Iceberg table: $table

What it means

AddPartitionFieldExec applies `ALTER TABLE ... ADD PARTITION FIELD` only to tables backed by the Iceberg catalog. When the resolved Spark V2 table is not an IcebergTable (any other provider), the executor throws UnsupportedOperationException because updateSpec() is an Iceberg-only API.

Solutions

  1. Reference the table through an Iceberg catalog, e.g. iceberg_catalog.db.t
  2. Ensure the catalog is configured as an IcebergCatalog (spark.sql.catalog.<name>=org.apache.iceberg.spark.SparkCatalog)
  3. Confirm the table actually exists in the Iceberg catalog rather than being created by another provider

Example fix

// before
ALTER TABLE spark_catalog.db.t ADD PARTITION FIELD bucket(16, id);
// after
ALTER TABLE iceberg_catalog.db.t ADD PARTITION FIELD bucket(16, id);
Defensive patterns

Strategy: try-catch

Validate before calling

val isIceberg = spark.sessionState.catalogManager.currentCatalog.asInstanceOf[SupportsNamespaces]
  .loadTable(ident).isInstanceOf[IcebergTable]

Type guard

def isIcebergTable(t: Table): Boolean = t.isInstanceOf[IcebergTable]

Try / catch

try { spark.sql(ddl) } catch { case _: UnsupportedOperationException => log.error("ADD PARTITION FIELD requires an Iceberg catalog table") }

Prevention

When it happens

Trigger: Running `ALTER TABLE catalog.db.t ADD PARTITION FIELD bucket(16, id)` where t resolves to a non-Iceberg V2 catalog table (JDBC, Delta via V2, Spark's built-in catalogs, etc.).

Common situations: Pointing the statement at the default Spark catalog or a non-Iceberg session catalog; using a catalog alias that maps to the wrong implementation; expecting Iceberg extensions to work generically on any V2 table.

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/98453e9801a92a6a. Report an issue: GitHub.

Appendix: source

Thrown at spark/v4.0/spark-extensions/src/main/scala/org/apache/spark/sql/execution/datasources/v2/AddPartitionFieldExec.scala:48

    catalog: TableCatalog,
    ident: Identifier,
    transform: Transform,
    name: Option[String])
    extends LeafV2CommandExec {
  import org.apache.spark.sql.connector.catalog.CatalogV2Implicits._

  override lazy val output: Seq[Attribute] = Nil

  override protected def run(): Seq[InternalRow] = {
    catalog.loadTable(ident) match {
      case iceberg: SparkTable =>
        iceberg.table
          .updateSpec()
          .addField(name.orNull, Spark3Util.toIcebergTerm(transform))
          .commit()

      case table =>
        throw new UnsupportedOperationException(
          s"Cannot add partition field to non-Iceberg table: $table")
    }

    Nil
  }

  override def simpleString(maxFields: Int): String = {
    s"AddPartitionField ${catalog.name}.${ident.quoted} ${name.map(n => s"$n=").getOrElse("")}${transform.describe}"
  }
}

View on GitHub (pinned to 86d9c8fc54)