{"record":{"id":"1d832d98af3c8e64","repo":"apache/iceberg","slug":"cannot-create-tag-to-non-iceberg-table-table-1d832d","errorCode":null,"errorMessage":"Cannot create tag to non-Iceberg table: $table","messagePattern":"Cannot create tag to non-Iceberg table: \\$table","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"spark/v4.0/spark-extensions/src/main/scala/org/apache/spark/sql/execution/datasources/v2/CreateOrReplaceTagExec.scala","lineNumber":77,"sourceCode":"          manageSnapshot.createTag(tag, snapshotId)\n        } else if (replace) {\n          manageSnapshot.replaceTag(tag, snapshotId)\n        } else {\n          if (refExists && ifNotExists) {\n            return Nil\n          }\n\n          manageSnapshot.createTag(tag, snapshotId)\n        }\n\n        if (tagOptions.snapshotRefRetain.nonEmpty) {\n          manageSnapshot.setMaxRefAgeMs(tag, tagOptions.snapshotRefRetain.get)\n        }\n\n        manageSnapshot.commit()\n\n      case table =>\n        throw new UnsupportedOperationException(s\"Cannot create tag to non-Iceberg table: $table\")\n    }\n\n    Nil\n  }\n\n  override def simpleString(maxFields: Int): String = {\n    s\"Create tag: $tag for table: ${ident.quoted}\"\n  }\n}\n","sourceCodeStart":59,"sourceCodeEnd":87,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.0/spark-extensions/src/main/scala/org/apache/spark/sql/execution/datasources/v2/CreateOrReplaceTagExec.scala#L59-L87","documentation":"This UnsupportedOperationException is thrown by CreateOrReplaceTagExec when the target of ALTER TABLE ... CREATE TAG is a Spark table that is not an Iceberg table. The Spark extensions pattern-match the resolved table against SparkTable (the Iceberg wrapper); any other catalog/table implementation falls into the catch-all case and fails. Tags are an Iceberg-specific snapshot reference feature, so non-Iceberg tables cannot support them.","triggerScenarios":"Running ALTER TABLE ... CREATE TAG (or CREATE OR REPLACE TAG) against a table resolved through a non-Iceberg DataSource V2 catalog (e.g. Delta, Parquet-based, or a plain Spark catalog table).","commonSituations":"Pointing the SQL at the wrong table name; a session catalog that resolves to a non-Iceberg provider; using a metastore where the table was migrated away from Iceberg; copy-pasting Iceberg SQL onto a Delta table.","solutions":["Verify the target table is an Iceberg table (check its provider with DESCRIBE TABLE EXTENDED or SHOW CREATE TABLE).","Use an Iceberg catalog (Hadoop/Hive/Nessie/REST) so the table resolves to a SparkTable.","If using Spark session catalog, ensure the table was created/migrated with Iceberg (e.g. via a migration procedure).","If the operation may not exist, guard the ALTER TABLE with IF EXISTS semantics or check the table type first."],"exampleFix":"// before\nALTER TABLE delta_table CREATE TAG etl_2026_01;\n// after\nALTER TABLE iceberg_catalog.db.events CREATE TAG etl_2026_01;","handlingStrategy":"validation","validationCode":"val table = spark.sessionState.catalogManager.currentCatalog.asTableCatalog.loadTable(ident)\nif (!table.isInstanceOf[org.apache.iceberg.spark.SparkTable])\n  throw new IllegalStateException(s\"$ident is not an Iceberg table; CREATE TAG requires Iceberg\")","typeGuard":"def isIcebergTable(t: org.apache.spark.sql.connector.catalog.Table): Boolean = t.isInstanceOf[org.apache.iceberg.spark.SparkTable]","tryCatchPattern":"try { spark.sql(s\"ALTER TABLE $ident CREATE TAG $tag\") } catch { case e: UnsupportedOperationException if e.getMessage.contains(\"non-Iceberg table\") => log.warn(s\"$ident is not an Iceberg table; skipping tag creation\") }","preventionTips":["Always qualify Iceberg DDL with the Iceberg catalog name","Check table provider with DESCRIBE TABLE EXTENDED before Iceberg-specific DDL","Keep Iceberg operations in scripts scoped to Iceberg catalogs","List table providers in the environment and filter maintenance jobs accordingly"],"tags":["spark","iceberg","unsupported-operation"],"backgroundTag":"unsupported-operation","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}