{"record":{"id":"774b13453cf4014c","repo":"apache/iceberg","slug":"alter-table-has-no-changes-missing-both-distribut-774b13","errorCode":null,"errorMessage":"ALTER TABLE has no changes: missing both distribution and ordering clauses","messagePattern":"ALTER TABLE has no changes: missing both distribution and ordering clauses","errorType":"exception","errorClass":"IcebergAnalysisException","httpStatus":null,"severity":"error","filePath":"spark/v4.1/spark-extensions/src/main/scala/org/apache/spark/sql/catalyst/parser/extensions/IcebergSqlExtensionsAstBuilder.scala","lineNumber":230,"sourceCode":"  override def visitDropIdentifierFields(ctx: DropIdentifierFieldsContext): DropIdentifierFields =\n    withOrigin(ctx) {\n      DropIdentifierFields(\n        typedVisit[Seq[String]](ctx.multipartIdentifier),\n        toSeq(ctx.fieldList.fields).map(_.getText))\n    }\n\n  /**\n   * Create a [[SetWriteDistributionAndOrdering]] for changing the write distribution and ordering.\n   */\n  override def visitSetWriteDistributionAndOrdering(\n      ctx: SetWriteDistributionAndOrderingContext): SetWriteDistributionAndOrdering = {\n\n    val tableName = typedVisit[Seq[String]](ctx.multipartIdentifier)\n\n    val (distributionSpec, orderingSpec) = toDistributionAndOrderingSpec(ctx.writeSpec)\n\n    if (distributionSpec == null && orderingSpec == null) {\n      throw new IcebergAnalysisException(\n        \"ALTER TABLE has no changes: missing both distribution and ordering clauses\")\n    }\n\n    val distributionMode = if (distributionSpec != null) {\n      Some(DistributionMode.HASH)\n    } else if (orderingSpec.UNORDERED != null) {\n      Some(DistributionMode.NONE)\n    } else if (orderingSpec.LOCALLY() != null) {\n      None\n    } else {\n      Some(DistributionMode.RANGE)\n    }\n\n    val ordering = if (orderingSpec != null && orderingSpec.order != null) {\n      toSeq(orderingSpec.order.fields).map(typedVisit[(Term, SortDirection, NullOrder)])\n    } else {\n      Seq.empty\n    }","sourceCodeStart":212,"sourceCodeEnd":248,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.1/spark-extensions/src/main/scala/org/apache/spark/sql/catalyst/parser/extensions/IcebergSqlExtensionsAstBuilder.scala#L212-L248","documentation":"When handling ALTER TABLE ... WRITE (DISTRIBUTED|ORDERED) statements, the AstBuilder requires at least one of a distribution clause or an ordering clause. If the WRITE spec contains neither, it throws this IcebergAnalysisException because the statement would be a no-op.","triggerScenarios":"Running `ALTER TABLE t WRITE` (or a form where both distribution and ordering clauses are absent/empty), leaving the statement without any spec to apply.","commonSituations":"Incomplete SQL after copy-paste truncation, templated SQL where the clause variables were empty, or misunderstanding that `WRITE` alone changes nothing.","solutions":["Add a distribution clause, e.g. `ALTER TABLE t WRITE DISTRIBUTED BY PARTITION`.","Or add an ordering clause, e.g. `ALTER TABLE t WRITE ORDERED BY col`.","Or combine both: `ALTER TABLE t WRITE ORDERED BY col` with DISTRIBUTED as needed.","If no change is intended, drop the ALTER TABLE statement entirely."],"exampleFix":"-- before\nALTER TABLE catalog.db.t WRITE\n-- after\nALTER TABLE catalog.db.t WRITE ORDERED BY id","handlingStrategy":"validation","validationCode":"-- ensure at least one clause exists before executing\n-- valid: ALTER TABLE t WRITE DISTRIBUTED BY PARTITION\n-- valid: ALTER TABLE t WRITE ORDERED BY id\n-- invalid: ALTER TABLE t WRITE","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never emit a bare `WRITE` clause without DISTRIBUTED or ORDERED.","In SQL generators, assert the rendered clause list is non-empty.","Drop no-op ALTER statements early in scripts."],"tags":["spark-sql","alter-table","write-spec"],"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"}