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
- Reference the table through an Iceberg catalog, e.g. iceberg_catalog.db.t
- Ensure the catalog is configured as an IcebergCatalog (spark.sql.catalog.<name>=org.apache.iceberg.spark.SparkCatalog)
- 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
- Qualify Iceberg tables with an Iceberg catalog alias in all DDL
- Verify catalog configuration (spark.sql.catalog.<name>) points to SparkCatalog
- Check table provider with DESCRIBE TABLE EXTENDED before Iceberg-specific DDL
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
- Cannot drop partition field in non-Iceberg table: $table
- Cannot replace partition field in non-Iceberg table: $table
- Cannot add partition field to non-Iceberg table: $table
- Cannot convert predicate to SQL
- Cannot convert term to SQL
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)