{"record":{"id":"b7ef44c2a266728e","repo":"apache/iceberg","slug":"cannot-remove-property-that-is-not-set-property-b7ef44","errorCode":null,"errorMessage":"Cannot remove property that is not set: '$property'","messagePattern":"Cannot remove property that is not set: '\\$property'","errorType":"exception","errorClass":"IcebergAnalysisException","httpStatus":null,"severity":"error","filePath":"spark/v4.1/spark-extensions/src/main/scala/org/apache/spark/sql/execution/datasources/v2/AlterV2ViewUnsetPropertiesExec.scala","lineNumber":40,"sourceCode":"import org.apache.spark.sql.catalyst.analysis.IcebergAnalysisException\nimport org.apache.spark.sql.catalyst.expressions.Attribute\nimport org.apache.spark.sql.connector.catalog.Identifier\nimport org.apache.spark.sql.connector.catalog.ViewCatalog\nimport org.apache.spark.sql.connector.catalog.ViewChange\n\ncase class AlterV2ViewUnsetPropertiesExec(\n    catalog: ViewCatalog,\n    ident: Identifier,\n    propertyKeys: Seq[String],\n    ifExists: Boolean)\n    extends LeafV2CommandExec {\n\n  override lazy val output: Seq[Attribute] = Nil\n\n  override protected def run(): Seq[InternalRow] = {\n    if (!ifExists) {\n      propertyKeys.filterNot(catalog.loadView(ident).properties.containsKey).foreach { property =>\n        throw new IcebergAnalysisException(s\"Cannot remove property that is not set: '$property'\")\n      }\n    }\n\n    val changes = propertyKeys.map(ViewChange.removeProperty)\n    catalog.alterView(ident, changes: _*)\n\n    Nil\n  }\n\n  override def simpleString(maxFields: Int): String = {\n    s\"AlterV2ViewUnsetProperties: ${ident}\"\n  }\n}\n","sourceCodeStart":22,"sourceCodeEnd":54,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.1/spark-extensions/src/main/scala/org/apache/spark/sql/execution/datasources/v2/AlterV2ViewUnsetPropertiesExec.scala#L22-L54","documentation":"AlterV2ViewUnsetPropertiesExec validates that every property key being unset actually exists in the view's properties, unless IF EXISTS was specified. If a key is missing and ifExists is false, it throws this IcebergAnalysisException before building the ViewChange to protect against silently dropping a typo'd key.","triggerScenarios":"Running `ALTER VIEW ... UNSET TBLPROPERTIES ('key')` where 'key' is not currently set on the view and the statement lacks IF EXISTS.","commonSituations":"Unsetting a property with a typo in the key name, double-unsetting the same property in a session, cleaning up properties that were already removed, or key-casing differences.","solutions":["Add IF EXISTS to tolerate missing keys: `ALTER VIEW v UNSET TBLPROPERTIES IF EXISTS ('key')`.","Verify the exact property key via `DESCRIBE VIEW EXTENDED` or the catalog's view properties.","Skip properties already removed in your script.","Check key casing/spelling against what was originally set."],"exampleFix":"-- before\nALTER VIEW catalog.db.v UNSET TBLPROPERTIES ('comment.note')\n-- after\nALTER VIEW catalog.db.v UNSET TBLPROPERTIES IF EXISTS ('comment.note')","handlingStrategy":"validation","validationCode":"// Scala: check the property exists before unsetting\nval props = catalog.loadView(ident).properties\nval missing = propertyKeys.filterNot(props.containsKey)\nif (missing.nonEmpty) propertyKeys = propertyKeys.filter(props.containsKey) // or use IF EXISTS in SQL","typeGuard":null,"tryCatchPattern":"// Scala\ntry { spark.sql(alterViewStmt) } catch {\n  case e: AnalysisException if e.getMessage.contains(\"Cannot remove property that is not set\") =>\n    // retry with IF EXISTS or ignore\n}","preventionTips":["Use UNSET TBLPROPERTIES IF EXISTS for idempotent cleanup scripts.","List current view properties with DESCRIBE VIEW EXTENDED before unsetting.","Copy keys from the original SET statement, don't retype them."],"tags":["spark-sql","views","properties"],"backgroundTag":"missing-required-argument","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"}