{"record":{"id":"ed93348c48013325","repo":"apache/iceberg","slug":"alter-table-has-no-changes-missing-both-distribut-ed9334","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.0/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.0/spark-extensions/src/main/scala/org/apache/spark/sql/catalyst/parser/extensions/IcebergSqlExtensionsAstBuilder.scala#L212-L248","documentation":"When executing ALTER TABLE ... WRITE (DISTRIBUTED BY ... / ORDERED BY ...) spec changes, the AST builder requires at least one of a distribution clause or an ordering clause. If the writeSpec contains neither, it throws IcebergAnalysisException because the statement would be a no-op. Iceberg models the write distribution/order as a pair and refuses empty updates.","triggerScenarios":"Running `ALTER TABLE t WRITE` with no DISTRIBUTED BY and no ORDERED BY clause, e.g. `ALTER TABLE t WRITE` or `ALTER TABLE t WRITE UNORDERED` malformed/omitted body.","commonSituations":"Truncated SQL generation from scripts/ORMs, assuming a bare `ALTER TABLE t WRITE` resets defaults, or accidentally deleting the clause body in a migration script.","solutions":["Add the intended clause, e.g. WRITE ORDERED BY col or WRITE DISTRIBUTED BY HASH","To reset ordering, write explicit `WRITE UNORDERED`; to reset distribution use `WRITE DIRECTLY` or `WRITE DISTRIBUTED BY HASH` as appropriate","Remove the statement entirely if no change is intended"],"exampleFix":"// before\nALTER TABLE t WRITE;\n// after\nALTER TABLE t WRITE ORDERED BY id;","handlingStrategy":"validation","validationCode":"def hasWriteSpecBody(stmt: String): Boolean = {\n  val s = stmt.toUpperCase(Locale.ROOT)\n  s.contains(\"DISTRIBUTED\") || s.contains(\"ORDERED BY\") || s.contains(\"UNORDERED\") || s.contains(\"DIRECTLY\")\n}","typeGuard":null,"tryCatchPattern":"try { spark.sql(stmt) } catch { case e: IcebergAnalysisException if e.getMessage.contains(\"has no changes\") => log.warn(\"No-op ALTER TABLE WRITE spec skipped\") }","preventionTips":["Always emit a DISTRIBUTED BY or ORDERED BY clause when generating WRITE spec DDL","To clear settings use explicit UNORDERED/DIRECTLY rather than omitting the body","Review generated SQL for truncated clauses"],"tags":["spark","sql","alter-table","missing-clause"],"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"}