{"record":{"id":"32717a978ebbd3c0","repo":"apache/iceberg","slug":"cannot-replace-partition-field-in-non-iceberg-tabl-32717a","errorCode":null,"errorMessage":"Cannot replace partition field in non-Iceberg table: $table","messagePattern":"Cannot replace partition field in non-Iceberg table: \\$table","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"spark/v4.1/spark-extensions/src/main/scala/org/apache/spark/sql/execution/datasources/v2/ReplacePartitionFieldExec.scala","lineNumber":65,"sourceCode":"          case IdentityTransform(FieldReference(parts))\n              if parts.size == 1 && schema.findField(parts.head) == null =>\n            // the name is not present in the Iceberg schema, so it must be a partition field name, not a column name\n            iceberg.table\n              .updateSpec()\n              .removeField(parts.head)\n              .addField(name.orNull, Spark3Util.toIcebergTerm(transformTo))\n              .commit()\n\n          case _ =>\n            iceberg.table\n              .updateSpec()\n              .removeField(Spark3Util.toIcebergTerm(transformFrom))\n              .addField(name.orNull, Spark3Util.toIcebergTerm(transformTo))\n              .commit()\n        }\n\n      case table =>\n        throw new UnsupportedOperationException(\n          s\"Cannot replace partition field in non-Iceberg table: $table\")\n    }\n\n    Nil\n  }\n\n  override def simpleString(maxFields: Int): String = {\n    s\"ReplacePartitionField ${catalog.name}.${ident.quoted} ${transformFrom.describe} \" +\n      s\"with ${name.map(n => s\"$n=\").getOrElse(\"\")}${transformTo.describe}\"\n  }\n}\n","sourceCodeStart":47,"sourceCodeEnd":77,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.1/spark-extensions/src/main/scala/org/apache/spark/sql/execution/datasources/v2/ReplacePartitionFieldExec.scala#L47-L77","documentation":"ReplacePartitionFieldExec throws this when ALTER TABLE ... REPLACE PARTITION FIELD targets a non-Iceberg table. Replacing a partition field (removing the old transform and adding a new one via UpdateSpec) is Iceberg partition-evolution functionality; other V2 table implementations do not support it, so the executor throws UnsupportedOperationException.","triggerScenarios":"Running `ALTER TABLE ... REPLACE PARTITION FIELD days(ts) WITH month(ts)` where the table resolves through a non-Iceberg catalog and the `iceberg: SparkTable` match fails.","commonSituations":"Partition-granularity change scripts applied to Delta/Hive tables; wrong catalog binding in multi-catalog sessions; migrating pipelines between table formats.","solutions":["Qualify the statement with the Iceberg catalog so it resolves to an Iceberg table","Confirm both the from and to transforms are valid Iceberg terms (Spark3Util.toIcebergTerm must translate them)","For non-Iceberg tables, use that engine's partition-management features or migrate to Iceberg"],"exampleFix":"// before\nALTER TABLE delta_t REPLACE PARTITION FIELD days(ts) WITH month(ts);\n// after\nALTER TABLE iceberg_catalog.db.t REPLACE PARTITION FIELD days(ts) WITH month(ts);","handlingStrategy":"validation","validationCode":"val loaded = catalog.loadTable(ident)\nrequire(loaded.isInstanceOf[org.apache.iceberg.spark.source.SparkTable], s\"REPLACE PARTITION FIELD requires Iceberg: $ident\")","typeGuard":"def isIcebergTable(t: org.apache.spark.sql.connector.catalog.Table): Boolean = t.isInstanceOf[org.apache.iceberg.spark.source.SparkTable]","tryCatchPattern":"try { spark.sql(s\"ALTER TABLE $ident REPLACE PARTITION FIELD days(ts) WITH month(ts)\") } catch { case e: UnsupportedOperationException if e.getMessage.contains(\"non-Iceberg\") => log.error(s\"Partition evolution unsupported on $ident\") }","preventionTips":["Confirm table format before partition-evolution DDL","Qualify the table with the Iceberg catalog","Keep Iceberg DDL in format-specific migration scripts"],"tags":["spark","spark-extensions","unsupported-operation","partition-evolution"],"backgroundTag":"unsupported-operation","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}